Files
pilotclient/src/misc/network/rolelist.cpp
2025-11-01 16:15:13 +01:00

44 lines
1.4 KiB
C++

// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
#include "misc/network/rolelist.h"
#include <QJsonValue>
#include "misc/network/role.h"
SWIFT_DEFINE_SEQUENCE_MIXINS(swift::misc::network, CRole, CRoleList)
namespace swift::misc::network
{
bool CRoleList::hasRole(const QString &roleName) const
{
return this->contains(&CRole::getName, roleName.trimmed().toUpper());
}
bool CRoleList::hasRole(const CRole &role) const { return hasRole(role.getName()); }
bool CRoleList::hasAnyRole(const QStringList &roles) const
{
return std::any_of(roles.cbegin(), roles.cend(), [&](const QString &r) { return this->hasRole(r); });
}
CRoleList::CRoleList(const CSequence<CRole> &other) : CSequence<CRole>(other) {}
QString CRoleList::namesAsString(const QString &separator) const
{
QStringList rolesString;
rolesString.reserve(size());
for (const CRole &role : (*this)) { rolesString.append(role.getName()); }
return rolesString.join(separator);
}
CRoleList CRoleList::fromDatabaseJson(const QJsonArray &array)
{
CRoleList roles;
for (const QJsonValue &value : array) { roles.push_back(CRole::fromDatabaseJson(value.toObject())); }
return roles;
}
} // namespace swift::misc::network