Skip to content

Commit

Permalink
fix(server): allow standard users to batch invite to server (#2150)
Browse files Browse the repository at this point in the history
* fix(server): allow standard users to batch invite to server

* added max 10 invite batch limit

* minor change
  • Loading branch information
fabis94 authored Mar 20, 2024
1 parent e406c5d commit f9f490b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extend type Mutation {
@hasScope(scope: "users:invite")

serverInviteBatchCreate(input: [ServerInviteCreateInput!]!): Boolean!
@hasServerRole(role: SERVER_ADMIN)
@hasServerRole(role: SERVER_USER)
@hasScope(scope: "users:invite")

streamInviteBatchCreate(input: [StreamInviteCreateInput!]!): Boolean!
Expand Down
9 changes: 9 additions & 0 deletions packages/server/modules/core/graph/resolvers/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from '@/modules/core/services/streams/management'
import { createOnboardingStream } from '@/modules/core/services/streams/onboarding'
import { removeStreamCollaborator } from '@/modules/core/services/streams/streamAccessService'
import { InviteCreateValidationError } from '@/modules/serverinvites/errors'
import { cancelStreamInvite } from '@/modules/serverinvites/services/inviteProcessingService'
import {
getPendingStreamCollaborators,
Expand Down Expand Up @@ -145,6 +146,14 @@ export = {
Roles.Stream.Owner,
ctx.resourceAccessRules
)

const inviteCount = args.input.length
if (inviteCount > 10 && ctx.role !== Roles.Server.Admin) {
throw new InviteCreateValidationError(
'Maximum 10 invites can be sent at once by non admins'
)
}

const inputBatches = chunk(args.input, 10)
for (const batch of inputBatches) {
await Promise.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ export = {
async serverInviteBatchCreate(_parent, args, context) {
const { input: paramsArray } = args

const inviteCount = paramsArray.length
if (inviteCount > 10 && context.role !== Roles.Server.Admin) {
throw new InviteCreateValidationError(
'Maximum 10 invites can be sent at once by non admins'
)
}

// Batch calls so that we don't kill the server
const batches = chunk(paramsArray, 50)
for (const paramsBatchArray of batches) {
Expand Down

0 comments on commit f9f490b

Please sign in to comment.