Skip to content

Commit

Permalink
feat: add ability for org billing leader and org admin to delete meet…
Browse files Browse the repository at this point in the history
…ing templates
  • Loading branch information
tianrunhe committed Feb 20, 2025
1 parent 8da96fd commit 2d64bb6
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 13 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"mini-css-extract-plugin": "^2.7.2",
"minimist": "^1.2.5",
"node-loader": "^2.0.0",
"nx": "^20.4.5",
"pm2": "^5.4.2",
"postcss": "^8.5.1",
"postcss-loader": "^7.0.2",
Expand Down
17 changes: 14 additions & 3 deletions packages/server/graphql/mutations/removeReflectTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import {GraphQLID, GraphQLNonNull} from 'graphql'
import {sql} from 'kysely'
import {SubscriptionChannel} from 'parabol-client/types/constEnums'
import getKysely from '../../postgres/getKysely'
import {getUserId, isTeamMember} from '../../utils/authorization'
import {
getUserId,
isTeamMember,
isUserBillingLeader,
isUserOrgAdmin
} from '../../utils/authorization'
import publish from '../../utils/publish'
import standardError from '../../utils/standardError'
import {GQLContext} from '../graphql'
Expand Down Expand Up @@ -31,8 +36,14 @@ const removeReflectTemplate = {
if (!template || !template.isActive) {
return standardError(new Error('Template not found'), {userId: viewerId})
}
if (!isTeamMember(authToken, template.teamId)) {
return standardError(new Error('Team not found'), {userId: viewerId})
const [isBillingLeader, isOrgAdmin] = await Promise.all([
isUserBillingLeader(viewerId, template.orgId, dataLoader),
isUserOrgAdmin(viewerId, template.orgId, dataLoader)
])
if (!isTeamMember(authToken, template.teamId) && !isBillingLeader && !isOrgAdmin) {
return standardError(new Error('You are not authorized to remove this template'), {
userId: viewerId
})
}

// VALIDATION
Expand Down
17 changes: 14 additions & 3 deletions packages/server/graphql/public/mutations/removePokerTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {SprintPokerDefaults, SubscriptionChannel} from 'parabol-client/types/constEnums'
import getKysely from '../../../postgres/getKysely'
import {getUserId, isTeamMember} from '../../../utils/authorization'
import {
getUserId,
isTeamMember,
isUserBillingLeader,
isUserOrgAdmin
} from '../../../utils/authorization'
import publish from '../../../utils/publish'
import standardError from '../../../utils/standardError'
import {MutationResolvers} from '../resolverTypes'
Expand All @@ -21,8 +26,14 @@ const removePokerTemplate: MutationResolvers['removePokerTemplate'] = async (
if (!template || !template.isActive) {
return standardError(new Error('Template not found'), {userId: viewerId})
}
if (!isTeamMember(authToken, template.teamId)) {
return standardError(new Error('Team not found'), {userId: viewerId})
const [isBillingLeader, isOrgAdmin] = await Promise.all([
isUserBillingLeader(viewerId, template.orgId, dataLoader),
isUserOrgAdmin(viewerId, template.orgId, dataLoader)
])
if (!isTeamMember(authToken, template.teamId) && !isBillingLeader && !isOrgAdmin) {
return standardError(new Error('You are not authorized to remove this template'), {
userId: viewerId
})
}

// VALIDATION
Expand Down
Loading

0 comments on commit 2d64bb6

Please sign in to comment.