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 (#10902)
  • Loading branch information
tianrunhe authored Feb 20, 2025
1 parent e73fcf9 commit f32c0aa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
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

0 comments on commit f32c0aa

Please sign in to comment.