File indexing completed on 2024-12-08 04:34:04

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "administratorwidget.h"
0008 #include "administratordialog/logs/viewlogwidget.h"
0009 #include "administratordialog/moderationconsole/administratormoderationconsolewidget.h"
0010 #include "administratordialog/oauth/administratoroauthwidget.h"
0011 #include "administratordialog/permissions/permissionswidget.h"
0012 #include "administratordialog/roles/administratorroleswidget.h"
0013 #include "customemoji/administratorcustomemojiwidget.h"
0014 #include "customsounds/administratorcustomsoundswidget.h"
0015 #include "customuserstatus/administratorcustomuserstatuswidget.h"
0016 #include "invites/administratorinviteswidget.h"
0017 #include "rocketchataccount.h"
0018 #include "rooms/administratorroomswidget.h"
0019 #include "serverinfo/administratorserverinfowidget.h"
0020 #include "users/administratoruserswidget.h"
0021 #include <KLocalizedString>
0022 #include <QTabWidget>
0023 #include <QVBoxLayout>
0024 
0025 AdministratorWidget::AdministratorWidget(RocketChatAccount *account, QWidget *parent)
0026     : QWidget(parent)
0027     , mTabWidget(new QTabWidget(this))
0028     , mAdministratorRoomsWidget(new AdministratorRoomsWidget(account, this))
0029     , mAdministratorCustomUserStatusWidget(new AdministratorCustomUserStatusWidget(account, this))
0030     , mAdministratorCustomSoundsWidget(new AdministratorCustomSoundsWidget(account, this))
0031     , mAdministratorServerInfoWidget(new AdministratorServerInfoWidget(account, this))
0032     , mAdministratorUsersWidget(new AdministratorUsersWidget(account, this))
0033     , mAdministratorInvitesWidget(new AdministratorInvitesWidget(account, this))
0034     , mAdministratorCustomEmojiWidget(new AdministratorCustomEmojiWidget(account, this))
0035     , mViewLogWidget(new ViewLogWidget(account, this))
0036     , mPermissionsWidget(new PermissionsWidget(account, this))
0037     , mRolesWidget(new AdministratorRolesWidget(account, this))
0038     , mOauthWidget(new AdministratorOauthWidget(account, this))
0039     , mAdministratorModerationConsoleWidget(new AdministratorModerationConsoleWidget(account, this))
0040     , mRocketChatAccount(account)
0041 {
0042     auto mainLayout = new QVBoxLayout(this);
0043     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0044     mainLayout->setContentsMargins({});
0045 
0046     mTabWidget->setObjectName(QStringLiteral("mTabWidget"));
0047     mainLayout->addWidget(mTabWidget);
0048 
0049     mAdministratorServerInfoWidget->setObjectName(QStringLiteral("mAdministratorServerInfoWidget"));
0050     mTabWidget->addTab(mAdministratorServerInfoWidget, i18n("Server Info"));
0051 
0052     mAdministratorRoomsWidget->setObjectName(QStringLiteral("mAdministratorRoomsWidget"));
0053     mTabWidget->addTab(mAdministratorRoomsWidget, i18n("Rooms"));
0054 
0055     mAdministratorCustomUserStatusWidget->setObjectName(QStringLiteral("mAdministratorCustomUserStatusWidget"));
0056     mTabWidget->addTab(mAdministratorCustomUserStatusWidget, i18n("Custom User Status"));
0057 
0058     mAdministratorCustomSoundsWidget->setObjectName(QStringLiteral("mAdministratorCustomSoundsWidget"));
0059     mTabWidget->addTab(mAdministratorCustomSoundsWidget, i18n("Custom Sounds"));
0060 
0061     mAdministratorCustomEmojiWidget->setObjectName(QStringLiteral("mAdministratorCustomEmojiWidget"));
0062     mTabWidget->addTab(mAdministratorCustomEmojiWidget, i18n("Custom Emojis"));
0063 
0064     mAdministratorUsersWidget->setObjectName(QStringLiteral("mAdministratorUsersWidget"));
0065     mTabWidget->addTab(mAdministratorUsersWidget, i18n("Users"));
0066 
0067     mAdministratorInvitesWidget->setObjectName(QStringLiteral("mAdministratorInvitesWidget"));
0068     mTabWidget->addTab(mAdministratorInvitesWidget, i18n("Invites"));
0069 
0070     mViewLogWidget->setObjectName(QStringLiteral("mViewLogWidget"));
0071     mTabWidget->addTab(mViewLogWidget, i18n("View Log"));
0072 
0073     mPermissionsWidget->setObjectName(QStringLiteral("mPermissionsWidget"));
0074     mTabWidget->addTab(mPermissionsWidget, i18n("Permissions"));
0075 
0076     mRolesWidget->setObjectName(QStringLiteral("mRolesWidget"));
0077     mTabWidget->addTab(mRolesWidget, i18n("Roles"));
0078 
0079     mOauthWidget->setObjectName(QStringLiteral("mOauthWidget"));
0080     mTabWidget->addTab(mOauthWidget, i18n("Oauth"));
0081 
0082     mAdministratorModerationConsoleWidget->setObjectName(QStringLiteral("mAdministratorModerationConsoleWidget"));
0083     mTabWidget->addTab(mAdministratorModerationConsoleWidget, i18n("Moderation Console"));
0084 }
0085 
0086 AdministratorWidget::~AdministratorWidget() = default;
0087 
0088 void AdministratorWidget::initialize()
0089 {
0090     mAdministratorUsersWidget->initialize();
0091     mAdministratorRoomsWidget->initialize();
0092     if (mRocketChatAccount->hasPermission(QStringLiteral("manage-sounds"))) {
0093         mAdministratorCustomSoundsWidget->initialize();
0094     }
0095     mAdministratorCustomEmojiWidget->initialize();
0096     mPermissionsWidget->initialize();
0097     mAdministratorCustomUserStatusWidget->initialize();
0098     mRolesWidget->initialize();
0099     if (mRocketChatAccount->hasPermission(QStringLiteral("view-statistics"))) {
0100         mAdministratorServerInfoWidget->initialize();
0101     }
0102     mAdministratorInvitesWidget->initialize();
0103     if (mRocketChatAccount->hasPermission(QStringLiteral("manage-oauth-apps"))) {
0104         mOauthWidget->initialize();
0105     }
0106     if (mRocketChatAccount->hasPermission(QStringLiteral("view-moderation-console"))) {
0107         mAdministratorModerationConsoleWidget->initialize();
0108     }
0109 }
0110 
0111 void AdministratorWidget::updateUiFromPermission()
0112 {
0113     if (!mRocketChatAccount->hasPermission(QStringLiteral("manage-sounds"))) {
0114         mTabWidget->setTabVisible(mTabWidget->indexOf(mAdministratorCustomSoundsWidget), false);
0115     }
0116     if (!mRocketChatAccount->hasPermission(QStringLiteral("view-statistics"))) {
0117         mTabWidget->setTabVisible(mTabWidget->indexOf(mAdministratorServerInfoWidget), false);
0118     }
0119     if (!mRocketChatAccount->hasPermission(QStringLiteral("view-logs"))) {
0120         mTabWidget->setTabVisible(mTabWidget->indexOf(mViewLogWidget), false);
0121     }
0122     if (!mRocketChatAccount->hasPermission(QStringLiteral("manage-oauth-apps"))) {
0123         mTabWidget->setTabVisible(mTabWidget->indexOf(mOauthWidget), false);
0124     }
0125     if (!mRocketChatAccount->hasPermission(QStringLiteral("view-moderation-console"))) {
0126         mTabWidget->setTabVisible(mTabWidget->indexOf(mAdministratorModerationConsoleWidget), false);
0127     }
0128 }
0129 
0130 #include "moc_administratorwidget.cpp"