fix(server): auto-accept pending invitations by link in team workspace (#11433)
close CLOUD-192
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
import {
|
import {
|
||||||
acceptInviteByInviteIdMutation,
|
acceptInviteByInviteIdMutation,
|
||||||
createInviteLinkMutation,
|
createInviteLinkMutation,
|
||||||
|
getInviteInfoQuery,
|
||||||
|
inviteByEmailMutation,
|
||||||
WorkspaceInviteLinkExpireTime,
|
WorkspaceInviteLinkExpireTime,
|
||||||
|
WorkspaceMemberStatus,
|
||||||
} from '@affine/graphql';
|
} from '@affine/graphql';
|
||||||
|
|
||||||
import { Mockers } from '../../mocks';
|
import { Mockers } from '../../mocks';
|
||||||
@@ -93,3 +96,51 @@ e2e(
|
|||||||
t.truthy(notification.payload.inviteId);
|
t.truthy(notification.payload.inviteId);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
e2e(
|
||||||
|
'should accept invitation by link directly if status is pending on team workspace',
|
||||||
|
async t => {
|
||||||
|
const { owner, workspace } = await createTeamWorkspace(2);
|
||||||
|
const member = await app.create(Mockers.User);
|
||||||
|
|
||||||
|
await app.login(owner);
|
||||||
|
// create a pending invitation
|
||||||
|
const invite = await app.gql({
|
||||||
|
query: inviteByEmailMutation,
|
||||||
|
variables: {
|
||||||
|
email: member.email,
|
||||||
|
workspaceId: workspace.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
t.truthy(invite, 'failed to create invitation');
|
||||||
|
|
||||||
|
const { createInviteLink } = await app.gql({
|
||||||
|
query: createInviteLinkMutation,
|
||||||
|
variables: {
|
||||||
|
workspaceId: workspace.id,
|
||||||
|
expireTime: WorkspaceInviteLinkExpireTime.OneDay,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
t.truthy(createInviteLink, 'failed to create invite link');
|
||||||
|
const link = createInviteLink.link;
|
||||||
|
const inviteLinkId = link.split('/').pop()!;
|
||||||
|
|
||||||
|
// member accept invitation by link
|
||||||
|
await app.login(member);
|
||||||
|
await app.gql({
|
||||||
|
query: acceptInviteByInviteIdMutation,
|
||||||
|
variables: {
|
||||||
|
inviteId: inviteLinkId,
|
||||||
|
workspaceId: workspace.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { getInviteInfo } = await app.gql({
|
||||||
|
query: getInviteInfoQuery,
|
||||||
|
variables: {
|
||||||
|
inviteId: invite.invite,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
t.is(getInviteInfo.status, WorkspaceMemberStatus.Accepted);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|||||||
@@ -664,6 +664,11 @@ export class WorkspaceResolver {
|
|||||||
WorkspaceRole.Collaborator,
|
WorkspaceRole.Collaborator,
|
||||||
WorkspaceMemberStatus.NeedMoreSeatAndReview
|
WorkspaceMemberStatus.NeedMoreSeatAndReview
|
||||||
);
|
);
|
||||||
|
// if status is pending, should accept the invite directly
|
||||||
|
if (role.status === WorkspaceMemberStatus.Pending) {
|
||||||
|
await this.acceptInviteByInviteId(role.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
await this.workspaceService.sendReviewRequestNotification(role.id);
|
await this.workspaceService.sendReviewRequestNotification(role.id);
|
||||||
const memberCount = await this.models.workspaceUser.count(workspaceId);
|
const memberCount = await this.models.workspaceUser.count(workspaceId);
|
||||||
this.event.emit('workspace.members.updated', {
|
this.event.emit('workspace.members.updated', {
|
||||||
|
|||||||
Reference in New Issue
Block a user