Skip to content

Commit

Permalink
Fixes #35994 - check if user has administrator permissions by its use…
Browse files Browse the repository at this point in the history
…rgroup
  • Loading branch information
nofaralfasi authored and ronlavi2412 committed Feb 5, 2023
1 parent 78b7799 commit e9ac79c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions webpack/graphql/queries/currentUserAttributes.gql
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ fragment CurrentUserAttributes on User {
name
}
}
usergroups {
nodes {
admin
}
}
}
5 changes: 4 additions & 1 deletion webpack/permissionsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export const permissionCheck = (user, permissionsRequired) => {
);
}

if (user.admin) {
if (
user.admin ||
user.usergroups.nodes.find(usergroup => usergroup.admin === true)
) {
return { allowed: true };
}

Expand Down
6 changes: 6 additions & 0 deletions webpack/testHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ export const userFactory = (login, permissions = []) => ({
permissions: {
nodes: permissions,
},
usergroups: {
nodes: [],
},
});

export const admin = {
Expand All @@ -81,6 +84,9 @@ export const admin = {
permissions: {
nodes: [],
},
usergroups: {
nodes: [],
},
};

export const intruder = userFactory('intruder', [
Expand Down

0 comments on commit e9ac79c

Please sign in to comment.