From ee5a2ff22bc0e4de73e61912597452796acc4202 Mon Sep 17 00:00:00 2001 From: Josh Crawford Date: Wed, 29 May 2024 20:15:39 +1000 Subject: [PATCH] Add Craft Teams support for permissions. --- src/controllers/LayoutController.php | 4 ++-- src/helpers/Permissions.php | 10 +++++----- src/services/Layouts.php | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/controllers/LayoutController.php b/src/controllers/LayoutController.php index 5153c33..34ecb5e 100644 --- a/src/controllers/LayoutController.php +++ b/src/controllers/LayoutController.php @@ -50,9 +50,9 @@ public function actionGetHudHtml(): Response 'layout' => $layout, ]; - if (Craft::$app->getEdition() == Craft::Solo) { + if (Craft::$app->getEdition() === Craft::Solo) { $variables['soloAccount'] = User::find()->status(null)->one(); - } else if (Craft::$app->getEdition() == Craft::Pro) { + } else { $variables['allGroups'] = Craft::$app->userGroups->getAllGroups(); } diff --git a/src/helpers/Permissions.php b/src/helpers/Permissions.php index 746c1ac..a236722 100644 --- a/src/helpers/Permissions.php +++ b/src/helpers/Permissions.php @@ -18,7 +18,7 @@ class Permissions public static function getBaseNavItems(): array { - $craftPro = Craft::$app->getEdition() === Craft::Pro; + $craftSolo = Craft::$app->getEdition() === Craft::Solo; $generalConfig = Craft::$app->getConfig()->getGeneral(); $navItems = [ @@ -66,7 +66,7 @@ public static function getBaseNavItems(): array ]; } - if ($craftPro) { + if (!$craftSolo) { $navItems[] = [ 'label' => Craft::t('app', 'Users'), 'url' => 'users', @@ -174,7 +174,7 @@ public static function getBaseNavItems(): array public static function getPermissionMap(): array { - $craftPro = Craft::$app->getEdition() === Craft::Pro; + $craftSolo = Craft::$app->getEdition() === Craft::Solo; $isAdmin = Craft::$app->getUser()->getIsAdmin(); $generalConfig = Craft::$app->getConfig()->getGeneral(); @@ -184,11 +184,11 @@ public static function getPermissionMap(): array 'globals' => (bool)Craft::$app->getGlobals()->getEditableSets(), 'categories' => (bool)Craft::$app->getCategories()->getEditableGroupIds(), 'assets' => (bool)Craft::$app->getVolumes()->getTotalViewableVolumes(), - 'users' => $craftPro && Craft::$app->getUser()->checkPermission('editUsers'), + 'users' => !$craftSolo && Craft::$app->getUser()->checkPermission('editUsers'), 'utilities' => (bool)Craft::$app->getUtilities()->getAuthorizedUtilityTypes(), - 'graphql' => $isAdmin && $craftPro && $generalConfig->enableGql, + 'graphql' => $isAdmin && !$craftSolo && $generalConfig->enableGql, 'settings' => $isAdmin && $generalConfig->allowAdminChanges, 'plugin-store' => $isAdmin, ]; diff --git a/src/services/Layouts.php b/src/services/Layouts.php index 4d2fb20..93b137e 100644 --- a/src/services/Layouts.php +++ b/src/services/Layouts.php @@ -80,7 +80,7 @@ public function getLayoutForCurrentUser(): ?Layout $layouts = $this->getAllLayouts(); - if (Craft::$app->getEdition() == Craft::Solo) { + if (Craft::$app->getEdition() === Craft::Solo) { // Is there even a solo account? if ($solo = User::find()->status(null)->one()) { foreach ($layouts as $layout) { @@ -89,7 +89,7 @@ public function getLayoutForCurrentUser(): ?Layout } } } - } else if (Craft::$app->getEdition() == Craft::Pro) { + } else { if ($userId = Craft::$app->getUser()->id) { $groups = Craft::$app->userGroups->getGroupsByUserId($userId);