Skip to content

Commit

Permalink
chore: adjust isTeam
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmFly committed Dec 9, 2024
1 parent fef8394 commit 57a611d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ export class WorkspaceProfileCacheStore extends Store {
}

const info = data as WorkspaceProfileInfo;

return {
avatar: info.avatar,
name: info.name,
isOwner: info.isOwner,
isAdmin: info.isAdmin,
isTeam: info.isTeam,
};
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const ActionButton = ({ detail, recurring }: PlanCardProps) => {
) : (
<Upgrade
recurring={recurring as SubscriptionRecurring}
plan={SubscriptionPlan.Team}
plan={SubscriptionPlan.Pro}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const logger = new DebugLogger('affine:workspace-permission');
export class WorkspacePermission extends Entity {
isOwner$ = new LiveData<boolean | null>(null);
isAdmin$ = new LiveData<boolean | null>(null);
isTeam$ = new LiveData<boolean | null>(null);
isLoading$ = new LiveData(false);
error$ = new LiveData<any>(null);

Expand All @@ -43,9 +44,13 @@ export class WorkspacePermission extends Entity {
signal
);

return { isOwner: info.isOwner, isAdmin: info.isAdmin };
return {
isOwner: info.isOwner,
isAdmin: info.isAdmin,
isTeam: info.workspace.team,
};
} else {
return { isOwner: true, isAdmin: false };
return { isOwner: true, isAdmin: false, isTeam: false };
}
}).pipe(
backoffRetry({
Expand All @@ -55,9 +60,10 @@ export class WorkspacePermission extends Entity {
backoffRetry({
when: isBackendError,
}),
mergeMap(({ isOwner, isAdmin }) => {
mergeMap(({ isOwner, isAdmin, isTeam }) => {
this.isAdmin$.next(isAdmin);
this.isOwner$.next(isOwner);
this.isTeam$.next(isTeam);
return EMPTY;
}),
catchErrorInto(this.error$, error => {
Expand Down
19 changes: 3 additions & 16 deletions packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { DebugLogger } from '@affine/debug';
import {
createWorkspaceMutation,
deleteWorkspaceMutation,
FeatureType,
getWorkspaceFeaturesQuery,
getWorkspaceInfoQuery,
getWorkspacesQuery,
} from '@affine/graphql';
Expand Down Expand Up @@ -233,12 +231,12 @@ class CloudWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
const cloudData = await cloudStorage.pull(id);

const info = await this.getWorkspaceInfo(id, signal);
const isTeam = await this.getIsTeam(id, signal);

if (!cloudData && !localData) {
return {
isOwner: info.isOwner,
isTeam,
isAdmin: info.isAdmin,
isTeam: info.workspace.team,
};
}

Expand All @@ -255,7 +253,7 @@ class CloudWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
avatar: bs.meta.avatar,
isOwner: info.isOwner,
isAdmin: info.isAdmin,
isTeam,
isTeam: info.workspace.team,
};
}
async getWorkspaceBlob(id: string, blob: string): Promise<Blob | null> {
Expand Down Expand Up @@ -318,17 +316,6 @@ class CloudWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
});
}

private async getIsTeam(workspaceId: string, signal?: AbortSignal) {
return (
await this.graphqlService.gql({
query: getWorkspaceFeaturesQuery,
variables: {
workspaceId,
},
context: { signal },
})
).workspace.features.includes(FeatureType.TeamWorkspace);
}
private waitForLoaded() {
return this.isRevalidating$.waitFor(loading => !loading);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/graphql/src/graphql/get-workspace-info.gql
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
query getWorkspaceInfo($workspaceId: String!) {
isAdmin(workspaceId: $workspaceId)
isOwner(workspaceId: $workspaceId)
workspace(id: $workspaceId) {
team
}
}
5 changes: 4 additions & 1 deletion packages/frontend/graphql/src/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,15 @@ query getWorkspaceFeatures($workspaceId: String!) {
export const getWorkspaceInfoQuery = {
id: 'getWorkspaceInfoQuery' as const,
operationName: 'getWorkspaceInfo',
definitionName: 'isAdmin,isOwner',
definitionName: 'isAdmin,isOwner,workspace',
containsFile: false,
query: `
query getWorkspaceInfo($workspaceId: String!) {
isAdmin(workspaceId: $workspaceId)
isOwner(workspaceId: $workspaceId)
workspace(id: $workspaceId) {
team
}
}`,
};

Expand Down
1 change: 1 addition & 0 deletions packages/frontend/graphql/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,7 @@ export type GetWorkspaceInfoQuery = {
__typename?: 'Query';
isAdmin: boolean;
isOwner: boolean;
workspace: { __typename?: 'WorkspaceType'; team: boolean };
};

export type GetWorkspacePageMetaByIdQueryVariables = Exact<{
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/i18n/src/i18n-completenesses.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
"ur": 2,
"zh-Hans": 93,
"zh-Hant": 93
}
}

0 comments on commit 57a611d

Please sign in to comment.