File indexing completed on 2024-12-01 13:10:51
0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-FileCopyrightText: 2023 Rishi Kumar <rsi.dev17@gmail.com> 0003 // SPDX-License-Identifier: GPL-3.0-or-later 0004 0005 #pragma once 0006 0007 #include <QFlags> 0008 #include <QJsonArray> 0009 #include <QObject> 0010 #include <QSettings> 0011 #include <QUrl> 0012 #include <QJsonArray> 0013 0014 class AbstractAccount; 0015 class Identity; 0016 0017 class AdminAccountInfo : public QObject 0018 { 0019 Q_OBJECT 0020 Q_PROPERTY(bool emailStatus READ emailStatus NOTIFY adminAccountInfoUpdated) 0021 Q_PROPERTY(bool suspended READ suspended WRITE setSuspended NOTIFY adminAccountInfoUpdated) 0022 Q_PROPERTY(bool silenced READ silenced WRITE setSilence NOTIFY adminAccountInfoUpdated) 0023 Q_PROPERTY(bool sensitized READ sensitized WRITE setSensitized NOTIFY adminAccountInfoUpdated) 0024 Q_PROPERTY(bool disabled READ disabled WRITE setDisabled NOTIFY adminAccountInfoUpdated) 0025 Q_PROPERTY(bool approved READ approved WRITE setApproved NOTIFY adminAccountInfoUpdated) 0026 Q_PROPERTY(bool isLocal READ isLocal NOTIFY adminAccountInfoUpdated) 0027 Q_PROPERTY(QString loginStatus READ loginStatus NOTIFY adminAccountInfoUpdated) 0028 Q_PROPERTY(QString inviteRequest READ inviteRequest NOTIFY adminAccountInfoUpdated) 0029 Q_PROPERTY(QString ip READ ip NOTIFY adminAccountInfoUpdated) 0030 Q_PROPERTY(QString email READ email NOTIFY adminAccountInfoUpdated) 0031 Q_PROPERTY(QString emailProvider READ emailProvider NOTIFY adminAccountInfoUpdated) 0032 Q_PROPERTY(QString locale READ locale NOTIFY adminAccountInfoUpdated) 0033 Q_PROPERTY(QDateTime joined READ joined NOTIFY adminAccountInfoUpdated) 0034 Q_PROPERTY(QDateTime lastActive READ lastActive NOTIFY adminAccountInfoUpdated) 0035 Q_PROPERTY(QString role READ role NOTIFY adminAccountInfoUpdated) 0036 Q_PROPERTY(QJsonArray ips READ ips NOTIFY adminAccountInfoUpdated) 0037 Q_PROPERTY(Identity *invitedByIdentity READ invitedByIdentity NOTIFY adminAccountInfoUpdated) 0038 Q_PROPERTY(Identity *userLevelIdentity READ userLevelIdentity NOTIFY adminAccountInfoUpdated) 0039 Q_PROPERTY(int position READ position NOTIFY adminAccountInfoUpdated) 0040 0041 public: 0042 enum Permission { 0043 Administrator = 0x1, 0044 Devops = 0x2, 0045 ViewAuditLog = 0x4, 0046 ViewDashboard = 0x8, 0047 ManageReports = 0x10, 0048 ManageFederation = 0x20, 0049 ManageSettings = 0x40, 0050 ManageBlocks = 0x80, 0051 ManageTaxonomies = 0x100, 0052 ManageAppeals = 0x200, 0053 ManageUsers = 0x400, 0054 ManageInvites = 0x800, 0055 ManageRules = 0x1000, 0056 ManageAnnouncements = 0x2000, 0057 ManageCustomEmojis = 0x4000, 0058 ManageWebhooks = 0x8000, 0059 InviteUsers = 0x10000, 0060 ManageRoles = 0x20000, 0061 ManageUserAccess = 0x40000, 0062 DeleteUserData = 0x80000, 0063 ModerationToolAccess = Administrator | Devops | ViewAuditLog | ViewDashboard | ManageReports | ManageFederation | ManageSettings | ManageBlocks 0064 | ManageTaxonomies | ManageAppeals | ManageUsers | ManageInvites | ManageRules | ManageAnnouncements | ManageCustomEmojis | ManageWebhooks 0065 | InviteUsers | ManageRoles | ManageUserAccess | DeleteUserData 0066 }; 0067 0068 Q_DECLARE_FLAGS(Permissions, Permission) 0069 Q_ENUM(Permission) 0070 QString ip() const; 0071 QString email() const; 0072 QString emailProvider() const; 0073 QString locale() const; 0074 QDateTime joined() const; 0075 QDateTime lastActive() const; 0076 QString role() const; 0077 QString loginStatus() const; 0078 QString inviteRequest() const; 0079 bool emailStatus() const; 0080 bool suspended() const; 0081 void setSuspended(bool suspended); 0082 bool silenced() const; 0083 void setSilence(bool silenced); 0084 bool sensitized() const; 0085 void setSensitized(bool sensitized); 0086 bool disabled() const; 0087 void setDisabled(bool disabled); 0088 bool approved() const; 0089 void setApproved(bool approved); 0090 bool isLocal() const; 0091 int position() const; 0092 0093 QJsonArray fields() const; 0094 QJsonArray ips() const; 0095 0096 void fromSourceData(const QJsonObject &jdoc); 0097 void reparentAdminAccountInfo(AbstractAccount *parent); 0098 0099 Identity *invitedByIdentity() const; 0100 Identity *userLevelIdentity() const; 0101 0102 Q_SIGNALS: 0103 void adminAccountInfoUpdated(); 0104 0105 private: 0106 QString m_ip; 0107 QString m_email; 0108 QString m_emailProvider; 0109 QString m_locale; 0110 QDateTime m_joined; 0111 QDateTime m_lastActive; 0112 QString m_role; 0113 QString m_inviteRequest; 0114 bool m_emailStatus; 0115 bool m_suspended; 0116 bool m_silenced; 0117 bool m_sensitized; 0118 bool m_disabled; 0119 bool m_approved; 0120 int m_position; 0121 QJsonArray m_ips; 0122 std::shared_ptr<Identity> m_invitedByIdentity; 0123 std::shared_ptr<Identity> m_userLevelIdentity; 0124 AbstractAccount *m_parent = nullptr; 0125 0126 void calculateRecentActivity(const QJsonArray &ipsArray); 0127 };