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:
forehalo
2025-05-23 04:25:53 +00:00
parent f38b8fef4d
commit 7978a2545f
3 changed files with 82 additions and 68 deletions

View File

@@ -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,

View File

@@ -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