File indexing completed on 2024-05-12 16:25:56

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "roleinfo.h"
0008 #include <QJsonObject>
0009 
0010 //{"_id":"admin","description":"Admin","mandatory2fa":false,"name":"admin","protected":true,"scope":"Users"},
0011 RoleInfo::RoleInfo() = default;
0012 
0013 const QString &RoleInfo::identifier() const
0014 {
0015     return mIdentifier;
0016 }
0017 
0018 void RoleInfo::setIdentifier(const QString &newIdentifier)
0019 {
0020     mIdentifier = newIdentifier;
0021 }
0022 
0023 const QString &RoleInfo::scope() const
0024 {
0025     return mScope;
0026 }
0027 
0028 void RoleInfo::setScope(const QString &newScope)
0029 {
0030     mScope = newScope;
0031 }
0032 
0033 bool RoleInfo::operator==(const RoleInfo &other) const
0034 {
0035     return mScope == other.scope() && mIdentifier == other.identifier() && mName == other.name() && mDescription == other.description() && mRoleProtected
0036         && other.roleProtected() && mMandatory2fa == other.mandatory2fa();
0037 }
0038 
0039 void RoleInfo::parseRoleInfo(const QJsonObject &obj)
0040 {
0041     // TODO updateAt!
0042     mScope = obj[QLatin1String("scope")].toString();
0043     mIdentifier = obj[QLatin1String("_id")].toString();
0044     mName = obj[QLatin1String("name")].toString();
0045     mDescription = obj[QLatin1String("description")].toString();
0046     mRoleProtected = obj[QLatin1String("protected")].toBool();
0047     mMandatory2fa = obj[QLatin1String("mandatory2fa")].toBool();
0048 }
0049 
0050 const QString &RoleInfo::name() const
0051 {
0052     return mName;
0053 }
0054 
0055 void RoleInfo::setName(const QString &newName)
0056 {
0057     mName = newName;
0058 }
0059 
0060 const QString &RoleInfo::description() const
0061 {
0062     return mDescription;
0063 }
0064 
0065 void RoleInfo::setDescription(const QString &newDescription)
0066 {
0067     mDescription = newDescription;
0068 }
0069 
0070 bool RoleInfo::roleProtected() const
0071 {
0072     return mRoleProtected;
0073 }
0074 
0075 void RoleInfo::setRoleProtected(bool newRoleProtected)
0076 {
0077     mRoleProtected = newRoleProtected;
0078 }
0079 
0080 bool RoleInfo::mandatory2fa() const
0081 {
0082     return mMandatory2fa;
0083 }
0084 
0085 void RoleInfo::setMandatory2fa(bool newMandatory2fa)
0086 {
0087     mMandatory2fa = newMandatory2fa;
0088 }
0089 
0090 // TODO translate name.
0091 
0092 QDebug operator<<(QDebug d, const RoleInfo &t)
0093 {
0094     // TODO add more
0095     d << "Identifier: " << t.identifier();
0096     d << "Scope: " << t.scope();
0097     d << "name: " << t.name();
0098     d << "description: " << t.description();
0099     d << "protected: " << t.roleProtected();
0100     d << "mandatory2fa: " << t.mandatory2fa();
0101     return d;
0102 }