Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): make permission and invoice offline available #8123

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/backend/server/src/core/permission/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/server/src/core/quota/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -145,6 +147,7 @@ export class QuotaManagementService {
humanReadable,
usedSize,
unlimited,
memberCount,
};

if (quota.unlimited) {
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/server/src/core/quota/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ export class QuotaQueryType {
@Field(() => SafeIntResolver)
memberLimit!: number;

@Field(() => SafeIntResolver)
memberCount!: number;

@Field(() => SafeIntResolver)
storageQuota!: number;

Expand Down
15 changes: 3 additions & 12 deletions packages/backend/server/src/core/workspaces/resolvers/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions packages/backend/server/src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ type QuotaQueryType {
copilotActionLimit: SafeInt
historyPeriod: SafeInt!
humanReadable: HumanReadableQuotaType!
memberCount: SafeInt!
memberLimit: SafeInt!
name: String!
storageQuota: SafeInt!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ import ReactPaginate from 'react-paginate';
import * as styles from './styles.css';
export interface PaginationProps {
totalCount: number;
pageNum?: number;
countPerPage: number;
onPageChange: (skip: number) => void;
onPageChange: (skip: number, pageNum: number) => void;
}

export const Pagination = ({
totalCount,
countPerPage,
pageNum,
onPageChange,
}: PaginationProps) => {
const handlePageClick = useCallback(
(e: { selected: number }) => {
const newOffset = (e.selected * countPerPage) % totalCount;
onPageChange(newOffset);
onPageChange(newOffset, e.selected);
},
[countPerPage, onPageChange, totalCount]
);
Expand All @@ -34,6 +36,7 @@ export const Pagination = ({
pageRangeDisplayed={3}
marginPagesDisplayed={2}
pageCount={pageCount}
forcePage={pageNum}
previousLabel={<ArrowLeftSmallIcon />}
nextLabel={<ArrowRightSmallIcon />}
pageClassName={styles.pageItem}
Expand Down
Loading
Loading