Skip to content

Commit

Permalink
Merge pull request uselagoon#3714 from uselagoon/disable-global-admin…
Browse files Browse the repository at this point in the history
…-check

fix: allow platform admin to add when disable-non-organization enabled
  • Loading branch information
shreddedbacon authored May 7, 2024
2 parents 26f57ef + a60a93b commit 18d528a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion services/api/src/resources/group/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export const addGroup: ResolverFn = async (
}
} else {
// otherwise fall back
if (DISABLE_NON_ORGANIZATION_GROUP_CREATION == "false") {
if (DISABLE_NON_ORGANIZATION_GROUP_CREATION == "false" || adminScopes.projectViewAll) {
await hasPermission('group', 'add');
} else {
throw new Error(
Expand Down
24 changes: 12 additions & 12 deletions services/api/src/resources/notification/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const addNotificationGeneric = async (sqlClientPool, notificationTable, input) =
return await query(sqlClientPool, knex(notificationTable).where('id', insertId).toString());
}

const checkOrgNotificationPermission = async (hasPermission, input) => {
const checkOrgNotificationPermission = async (hasPermission, input, adminScopes) => {
if (input.organization != null) {
const organizationData = await organizationHelpers(sqlClientPool).getOrganizationById(input.organization);
if (organizationData === undefined) {
Expand All @@ -43,7 +43,7 @@ const checkOrgNotificationPermission = async (hasPermission, input) => {
);
}
} else {
if (DISABLE_NON_ORGANIZATION_NOTIFICATION_ASSIGNMENT == "false") {
if (DISABLE_NON_ORGANIZATION_NOTIFICATION_ASSIGNMENT == "false" || adminScopes.projectViewAll) {
await hasPermission('notification', 'add');
} else {
throw new Error(
Expand All @@ -56,41 +56,41 @@ const checkOrgNotificationPermission = async (hasPermission, input) => {
export const addNotificationMicrosoftTeams: ResolverFn = async (
root,
{ input },
{ sqlClientPool, hasPermission }
{ sqlClientPool, hasPermission, adminScopes}
) => {
await checkOrgNotificationPermission(hasPermission, input)
await checkOrgNotificationPermission(hasPermission, input, adminScopes)
return R.path([0], await addNotificationGeneric(sqlClientPool, 'notification_microsoftteams', input));
};

export const addNotificationEmail: ResolverFn = async (
root,
{ input },
{ sqlClientPool, hasPermission }
{ sqlClientPool, hasPermission, adminScopes}
) => {
await checkOrgNotificationPermission(hasPermission, input)
await checkOrgNotificationPermission(hasPermission, input, adminScopes)
return R.path([0], await addNotificationGeneric(sqlClientPool, 'notification_email', input));
};

export const addNotificationRocketChat: ResolverFn = async (
root,
{ input },
{ sqlClientPool, hasPermission }
{ sqlClientPool, hasPermission, adminScopes }
) => {
await checkOrgNotificationPermission(hasPermission, input)
await checkOrgNotificationPermission(hasPermission, input, adminScopes)
return R.path([0], await addNotificationGeneric(sqlClientPool, 'notification_rocketchat', input));
};

export const addNotificationSlack: ResolverFn = async (
root,
{ input },
{ sqlClientPool, hasPermission }
{ sqlClientPool, hasPermission, adminScopes}
) => {
await checkOrgNotificationPermission(hasPermission, input)
await checkOrgNotificationPermission(hasPermission, input, adminScopes)
return R.path([0], await addNotificationGeneric(sqlClientPool, 'notification_slack', input));
};

export const addNotificationWebhook: ResolverFn = async (root, { input }, { sqlClientPool, hasPermission }) => {
await checkOrgNotificationPermission(hasPermission, input)
export const addNotificationWebhook: ResolverFn = async (root, { input }, { sqlClientPool, hasPermission, adminScopes}) => {
await checkOrgNotificationPermission(hasPermission, input, adminScopes)
return R.path([0], await addNotificationGeneric(sqlClientPool, 'notification_webhook', input));
};

Expand Down
2 changes: 1 addition & 1 deletion services/api/src/resources/project/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export const addProject = async (
}
}
} else {
if (DISABLE_NON_ORGANIZATION_PROJECT_CREATION == "false") {
if (DISABLE_NON_ORGANIZATION_PROJECT_CREATION == "false" || adminScopes.projectViewAll) {
await hasPermission('project', 'add');
} else {
throw new Error(
Expand Down

0 comments on commit 18d528a

Please sign in to comment.