mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
feat(core): make permission and invoice offline available (#8123)
This commit is contained in:
@@ -75,6 +75,14 @@ export class PermissionService {
|
||||
return owner.user;
|
||||
}
|
||||
|
||||
async getWorkspaceMemberCount(workspaceId: string) {
|
||||
return this.prisma.workspaceUserPermission.count({
|
||||
where: {
|
||||
workspaceId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async tryGetWorkspaceOwner(workspaceId: string) {
|
||||
return this.prisma.workspaceUserPermission.findFirst({
|
||||
where: {
|
||||
|
||||
@@ -113,6 +113,8 @@ export class QuotaManagementService {
|
||||
// quota was apply to owner's account
|
||||
async getWorkspaceUsage(workspaceId: string): Promise<QuotaBusinessType> {
|
||||
const owner = await this.permissions.getWorkspaceOwner(workspaceId);
|
||||
const memberCount =
|
||||
await this.permissions.getWorkspaceMemberCount(workspaceId);
|
||||
const {
|
||||
feature: {
|
||||
name,
|
||||
@@ -145,6 +147,7 @@ export class QuotaManagementService {
|
||||
humanReadable,
|
||||
usedSize,
|
||||
unlimited,
|
||||
memberCount,
|
||||
};
|
||||
|
||||
if (quota.unlimited) {
|
||||
|
||||
@@ -87,6 +87,9 @@ export class QuotaQueryType {
|
||||
@Field(() => SafeIntResolver)
|
||||
memberLimit!: number;
|
||||
|
||||
@Field(() => SafeIntResolver)
|
||||
memberCount!: number;
|
||||
|
||||
@Field(() => SafeIntResolver)
|
||||
storageQuota!: number;
|
||||
|
||||
|
||||
@@ -115,11 +115,7 @@ export class WorkspaceResolver {
|
||||
complexity: 2,
|
||||
})
|
||||
memberCount(@Parent() workspace: WorkspaceType) {
|
||||
return this.prisma.workspaceUserPermission.count({
|
||||
where: {
|
||||
workspaceId: workspace.id,
|
||||
},
|
||||
});
|
||||
return this.permissions.getWorkspaceMemberCount(workspace.id);
|
||||
}
|
||||
|
||||
@ResolveField(() => Boolean, {
|
||||
@@ -388,13 +384,8 @@ export class WorkspaceResolver {
|
||||
}
|
||||
|
||||
// member limit check
|
||||
const [memberCount, quota] = await Promise.all([
|
||||
this.prisma.workspaceUserPermission.count({
|
||||
where: { workspaceId },
|
||||
}),
|
||||
this.quota.getWorkspaceUsage(workspaceId),
|
||||
]);
|
||||
if (memberCount >= quota.memberLimit) {
|
||||
const quota = await this.quota.getWorkspaceUsage(workspaceId);
|
||||
if (quota.memberCount >= quota.memberLimit) {
|
||||
return new MemberQuotaExceeded();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user