Skip to content

Commit

Permalink
fix(server): some serverinvites regressions (#2538)
Browse files Browse the repository at this point in the history
* project invite retrieval

* fix for invalid invite target when inviting registered user by email

* improved error msg w/ broken streamId
  • Loading branch information
fabis94 authored Jul 29, 2024
1 parent abd89a3 commit 281f77a
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,6 @@ export = {
},

async streamInviteCreate(_parent, args, context) {
await authorizeResolver(
context.userId,
args.input.streamId,
Roles.Stream.Owner,
context.resourceAccessRules
)
const createProjectInvite = createProjectInviteFactory({
createAndSendInvite: buildCreateAndSendServerOrProjectInvite()
})
Expand Down Expand Up @@ -320,17 +314,18 @@ export = {
},
ProjectInviteMutations: {
async create(_parent, args, ctx) {
await authorizeResolver(
ctx.userId,
args.projectId,
Roles.Stream.Owner,
ctx.resourceAccessRules
)
const createProjectInvite = createProjectInviteFactory({
createAndSendInvite: buildCreateAndSendServerOrProjectInvite()
})

await createProjectInvite(args, ctx.userId!, ctx.resourceAccessRules)
await createProjectInvite(
{
projectId: args.projectId,
...args.input
},
ctx.userId!,
ctx.resourceAccessRules
)
return ctx.loaders.streams.getStream.load(args.projectId)
},
async batchCreate(_parent, args, ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function down(knex: Knex): Promise<void> {
table.string('serverRole')

table.index(OLD_IDX_2)
table.index(OLD_UNIQUE_IDX_COLS)
table.unique(OLD_UNIQUE_IDX_COLS)
})

// Move back from resource to old fields
Expand Down
7 changes: 6 additions & 1 deletion packages/server/modules/serverinvites/services/creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export const createAndSendInviteFactory =
}): CreateAndSendInvite =>
async (params, inviterResourceAccessLimits?) => {
const sendInviteEmail = sendInviteEmailFactory({ buildInviteEmailContents })
const { inviterId, target } = params
const { inviterId } = params
let { target } = params
let { message } = params

const [inviter, targetUser, serverInfo] = await Promise.all([
Expand All @@ -111,6 +112,10 @@ export const createAndSendInviteFactory =
throw new InviteCreateValidationError('Attempting to invite an invalid user')
}

if (targetData.userId) {
target = buildUserTarget(targetData.userId)!
}

if (message && message.length >= 1024) {
throw new InviteCreateValidationError('Personal message too long')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export const createProjectInviteFactory =
throw new InviteCreateValidationError('Either email or userId must be specified')
}

const resourceId = isStreamInviteCreateInput(input)
? input.streamId
: input.projectId
if (!resourceId?.length) {
throw new InviteCreateValidationError('Invalid project ID specified')
}

const target = (userId ? buildUserTarget(userId) : email)!
await deps.createAndSendInvite(
{
Expand All @@ -67,9 +74,7 @@ export const createProjectInviteFactory =
: undefined,
primaryResourceTarget: {
resourceType: ProjectInviteResourceType,
resourceId: isStreamInviteCreateInput(input)
? input.streamId
: input.projectId,
resourceId,
role: role || Roles.Stream.Contributor,
primary: true
}
Expand Down
Loading

0 comments on commit 281f77a

Please sign in to comment.