Skip to content

Commit

Permalink
Check all permission for attribute config (#4694)
Browse files Browse the repository at this point in the history
* Check all permission for attribute config

* Add changeset
  • Loading branch information
poulch authored and andrzejewsky committed Mar 1, 2024
1 parent c7f9be3 commit e096735
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-icons-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Fix showing attribute config for use with only one permission
1 change: 1 addition & 0 deletions src/configuration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function createConfigurationMenu(intl: IntlShape): MenuSection[] {
defaultMessage: "Determine attributes used to create product types",
}),
icon: <Attributes />,
requireAllPermissions: true,
permissions: [
PermissionEnum.MANAGE_PRODUCT_TYPES_AND_ATTRIBUTES,
PermissionEnum.MANAGE_PAGE_TYPES_AND_ATTRIBUTES,
Expand Down
1 change: 1 addition & 0 deletions src/configuration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface MenuItem {
description: string;
icon: React.ReactElement<IconProps>;
permissions?: PermissionEnum[];
requireAllPermissions?: boolean;
title: string;
url?: string;
testId?: string;
Expand Down
15 changes: 12 additions & 3 deletions src/configuration/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-strict-ignore
import { hasAnyPermissions } from "@dashboard/auth/misc";
import { hasAllPermissions, hasAnyPermissions } from "@dashboard/auth/misc";
import { PermissionEnum, UserFragment } from "@dashboard/graphql";
import { IntlShape } from "react-intl";

Expand All @@ -22,5 +22,14 @@ export const getConfigMenuItemsPermissions = (
export const hasUserMenuItemPermissions = (
menuItem: MenuItem,
user: UserFragment,
): boolean =>
menuItem.permissions ? hasAnyPermissions(menuItem.permissions, user) : true;
): boolean => {
if (menuItem.permissions) {
if (menuItem.requireAllPermissions) {
return hasAllPermissions(menuItem.permissions, user);
}

return hasAnyPermissions(menuItem.permissions, user);
}

return true;
};

0 comments on commit e096735

Please sign in to comment.