Skip to content

Commit

Permalink
Add Craft Teams support for permissions.
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed May 29, 2024
1 parent e4261cc commit ee5a2ff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/controllers/LayoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
10 changes: 5 additions & 5 deletions src/helpers/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -66,7 +66,7 @@ public static function getBaseNavItems(): array
];
}

if ($craftPro) {
if (!$craftSolo) {
$navItems[] = [
'label' => Craft::t('app', 'Users'),
'url' => 'users',
Expand Down Expand Up @@ -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();

Expand All @@ -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,
];
Expand Down
4 changes: 2 additions & 2 deletions src/services/Layouts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);

Expand Down

0 comments on commit ee5a2ff

Please sign in to comment.