mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix(server): should direct allocate seat if workspace is not team (#12469)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added the ability for workspace owners to approve members under review, with different approval processes for team and non-team workspaces. - **Bug Fixes** - Improved accuracy of workspace seat quota calculations for member management. - **Tests** - Enhanced test coverage and consistency for workspace member actions, including approval and revocation scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -173,7 +173,8 @@ export class QuotaService {
|
||||
|
||||
async getWorkspaceSeatQuota(workspaceId: string) {
|
||||
const quota = await this.getWorkspaceQuota(workspaceId);
|
||||
const memberCount = await this.models.workspaceUser.count(workspaceId);
|
||||
const memberCount =
|
||||
await this.models.workspaceUser.chargedCount(workspaceId);
|
||||
|
||||
return {
|
||||
memberCount,
|
||||
|
||||
@@ -343,22 +343,37 @@ export class WorkspaceMemberResolver {
|
||||
.workspace(workspaceId)
|
||||
.assert('Workspace.Users.Manage');
|
||||
|
||||
const isTeam = await this.models.workspace.isTeamWorkspace(workspaceId);
|
||||
const role = await this.models.workspaceUser.get(workspaceId, userId);
|
||||
|
||||
if (role) {
|
||||
if (role.status === WorkspaceMemberStatus.UnderReview) {
|
||||
await this.models.workspaceUser.setStatus(
|
||||
workspaceId,
|
||||
userId,
|
||||
WorkspaceMemberStatus.AllocatingSeat,
|
||||
{
|
||||
inviterId: me.id,
|
||||
if (isTeam) {
|
||||
await this.models.workspaceUser.setStatus(
|
||||
workspaceId,
|
||||
userId,
|
||||
WorkspaceMemberStatus.AllocatingSeat,
|
||||
{
|
||||
inviterId: me.id,
|
||||
}
|
||||
);
|
||||
} else {
|
||||
const quota = await this.quota.getWorkspaceSeatQuota(workspaceId);
|
||||
if (quota.memberCount >= quota.memberLimit) {
|
||||
throw new NoMoreSeat({ spaceId: workspaceId });
|
||||
} else {
|
||||
await this.models.workspaceUser.setStatus(
|
||||
workspaceId,
|
||||
userId,
|
||||
WorkspaceMemberStatus.Accepted
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
this.event.emit('workspace.members.updated', {
|
||||
workspaceId,
|
||||
});
|
||||
|
||||
await this.workspaceService.sendReviewApprovedNotification(
|
||||
role.id,
|
||||
me.id
|
||||
|
||||
Reference in New Issue
Block a user