From f620847dab558091bd3e75d25ffee862541c568b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Galv=C3=A1n?= <33644205+jose-galvan@users.noreply.github.com> Date: Fri, 14 Jun 2024 09:46:06 -0600 Subject: [PATCH] feat: allow editor to change project settings (#10383) Co-authored-by: Hanzla Mateen --- .../src/user/useUserProjectPermission.tsx | 20 +++++++++++++++++++ .../project-setting/project-setting.hooks.ts | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/client-core/src/user/useUserProjectPermission.tsx b/packages/client-core/src/user/useUserProjectPermission.tsx index 1aa9198d9e..07c66e60c9 100644 --- a/packages/client-core/src/user/useUserProjectPermission.tsx +++ b/packages/client-core/src/user/useUserProjectPermission.tsx @@ -45,3 +45,23 @@ export const useProjectPermissions = (project: string): ProjectPermissionType => const [permission] = data return permission } + +/** + * + * @param {ProjectPermissionType} userPermission current user permission + * @param {string | string[]} required required permission + * @returns {boolean} whether the user has or not the required permission + */ +export const userHasProjectPermission = ( + userPermission: ProjectPermissionType, + required: string[] | string +): boolean => { + if (!userPermission?.type) { + return false + } + + if (!Array.isArray(required)) { + return userPermission.type === required + } + return required.includes(userPermission.type) +} diff --git a/packages/server-core/src/setting/project-setting/project-setting.hooks.ts b/packages/server-core/src/setting/project-setting/project-setting.hooks.ts index 5ff7eaf685..bcd0599b99 100644 --- a/packages/server-core/src/setting/project-setting/project-setting.hooks.ts +++ b/packages/server-core/src/setting/project-setting/project-setting.hooks.ts @@ -97,7 +97,7 @@ export default { iffElse( checkScope('projects', 'write'), [], - [verifyScope('editor', 'write'), verifyProjectPermission(['owner'])] + [verifyScope('editor', 'write'), verifyProjectPermission(['owner', 'editor'])] ) ) ],