refactor(core): use workspace role query instead of isOwner query (#12118)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Updated workspace permission handling to use a unified role field within workspace data instead of separate admin and owner flags. - Permission checks now rely on the workspace role for determining admin and owner status. - **Chores** - Removed deprecated queries and types related to admin and owner status. - Cleaned up internal logic and variable naming for improved consistency. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
query getIsAdmin($workspaceId: String!) {
|
|
||||||
isAdmin(workspaceId: $workspaceId)
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
query getIsOwner($workspaceId: String!) {
|
|
||||||
isOwner(workspaceId: $workspaceId)
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
query getWorkspaceInfo($workspaceId: String!) {
|
query getWorkspaceInfo($workspaceId: String!) {
|
||||||
isAdmin(workspaceId: $workspaceId)
|
|
||||||
isOwner(workspaceId: $workspaceId)
|
|
||||||
workspace(id: $workspaceId) {
|
workspace(id: $workspaceId) {
|
||||||
|
role
|
||||||
team
|
team
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1036,24 +1036,6 @@ export const getInviteInfoQuery = {
|
|||||||
}`,
|
}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getIsAdminQuery = {
|
|
||||||
id: 'getIsAdminQuery' as const,
|
|
||||||
op: 'getIsAdmin',
|
|
||||||
query: `query getIsAdmin($workspaceId: String!) {
|
|
||||||
isAdmin(workspaceId: $workspaceId)
|
|
||||||
}`,
|
|
||||||
deprecations: ["'isAdmin' is deprecated: use WorkspaceType[role] instead"],
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getIsOwnerQuery = {
|
|
||||||
id: 'getIsOwnerQuery' as const,
|
|
||||||
op: 'getIsOwner',
|
|
||||||
query: `query getIsOwner($workspaceId: String!) {
|
|
||||||
isOwner(workspaceId: $workspaceId)
|
|
||||||
}`,
|
|
||||||
deprecations: ["'isOwner' is deprecated: use WorkspaceType[role] instead"],
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getMemberCountByWorkspaceIdQuery = {
|
export const getMemberCountByWorkspaceIdQuery = {
|
||||||
id: 'getMemberCountByWorkspaceIdQuery' as const,
|
id: 'getMemberCountByWorkspaceIdQuery' as const,
|
||||||
op: 'getMemberCountByWorkspaceId',
|
op: 'getMemberCountByWorkspaceId',
|
||||||
@@ -1185,13 +1167,11 @@ export const getWorkspaceInfoQuery = {
|
|||||||
id: 'getWorkspaceInfoQuery' as const,
|
id: 'getWorkspaceInfoQuery' as const,
|
||||||
op: 'getWorkspaceInfo',
|
op: 'getWorkspaceInfo',
|
||||||
query: `query getWorkspaceInfo($workspaceId: String!) {
|
query: `query getWorkspaceInfo($workspaceId: String!) {
|
||||||
isAdmin(workspaceId: $workspaceId)
|
|
||||||
isOwner(workspaceId: $workspaceId)
|
|
||||||
workspace(id: $workspaceId) {
|
workspace(id: $workspaceId) {
|
||||||
|
role
|
||||||
team
|
team
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
deprecations: ["'isAdmin' is deprecated: use WorkspaceType[role] instead","'isOwner' is deprecated: use WorkspaceType[role] instead"],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getWorkspacePageByIdQuery = {
|
export const getWorkspacePageByIdQuery = {
|
||||||
|
|||||||
@@ -3665,18 +3665,6 @@ export type GetInviteInfoQuery = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GetIsAdminQueryVariables = Exact<{
|
|
||||||
workspaceId: Scalars['String']['input'];
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export type GetIsAdminQuery = { __typename?: 'Query'; isAdmin: boolean };
|
|
||||||
|
|
||||||
export type GetIsOwnerQueryVariables = Exact<{
|
|
||||||
workspaceId: Scalars['String']['input'];
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export type GetIsOwnerQuery = { __typename?: 'Query'; isOwner: boolean };
|
|
||||||
|
|
||||||
export type GetMemberCountByWorkspaceIdQueryVariables = Exact<{
|
export type GetMemberCountByWorkspaceIdQueryVariables = Exact<{
|
||||||
workspaceId: Scalars['String']['input'];
|
workspaceId: Scalars['String']['input'];
|
||||||
}>;
|
}>;
|
||||||
@@ -3829,9 +3817,7 @@ export type GetWorkspaceInfoQueryVariables = Exact<{
|
|||||||
|
|
||||||
export type GetWorkspaceInfoQuery = {
|
export type GetWorkspaceInfoQuery = {
|
||||||
__typename?: 'Query';
|
__typename?: 'Query';
|
||||||
isAdmin: boolean;
|
workspace: { __typename?: 'WorkspaceType'; role: Permission; team: boolean };
|
||||||
isOwner: boolean;
|
|
||||||
workspace: { __typename?: 'WorkspaceType'; team: boolean };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GetWorkspacePageByIdQueryVariables = Exact<{
|
export type GetWorkspacePageByIdQueryVariables = Exact<{
|
||||||
@@ -4825,16 +4811,6 @@ export type Queries =
|
|||||||
variables: GetInviteInfoQueryVariables;
|
variables: GetInviteInfoQueryVariables;
|
||||||
response: GetInviteInfoQuery;
|
response: GetInviteInfoQuery;
|
||||||
}
|
}
|
||||||
| {
|
|
||||||
name: 'getIsAdminQuery';
|
|
||||||
variables: GetIsAdminQueryVariables;
|
|
||||||
response: GetIsAdminQuery;
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
name: 'getIsOwnerQuery';
|
|
||||||
variables: GetIsOwnerQueryVariables;
|
|
||||||
response: GetIsOwnerQuery;
|
|
||||||
}
|
|
||||||
| {
|
| {
|
||||||
name: 'getMemberCountByWorkspaceIdQuery';
|
name: 'getMemberCountByWorkspaceIdQuery';
|
||||||
variables: GetMemberCountByWorkspaceIdQueryVariables;
|
variables: GetMemberCountByWorkspaceIdQueryVariables;
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ const AccountMenu = () => {
|
|||||||
const openSignOutModal = useSignOut();
|
const openSignOutModal = useSignOut();
|
||||||
const serverService = useService(ServerService);
|
const serverService = useService(ServerService);
|
||||||
const userFeatureService = useService(UserFeatureService);
|
const userFeatureService = useService(UserFeatureService);
|
||||||
const isAdmin = useLiveData(userFeatureService.userFeature.isAdmin$);
|
const isAFFiNEAdmin = useLiveData(userFeatureService.userFeature.isAdmin$);
|
||||||
|
|
||||||
const onOpenAccountSetting = useCallback(() => {
|
const onOpenAccountSetting = useCallback(() => {
|
||||||
track.$.navigationPanel.profileAndBadge.openSettings({ to: 'account' });
|
track.$.navigationPanel.profileAndBadge.openSettings({ to: 'account' });
|
||||||
@@ -111,7 +111,7 @@ const AccountMenu = () => {
|
|||||||
>
|
>
|
||||||
{t['com.affine.workspace.cloud.account.settings']()}
|
{t['com.affine.workspace.cloud.account.settings']()}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
{isAdmin ? (
|
{isAFFiNEAdmin ? (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
prefixIcon={<AdminIcon />}
|
prefixIcon={<AdminIcon />}
|
||||||
data-testid="workspace-modal-account-admin-option"
|
data-testid="workspace-modal-account-admin-option"
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { Permission } from '@affine/graphql';
|
||||||
import {
|
import {
|
||||||
backoffRetry,
|
backoffRetry,
|
||||||
effect,
|
effect,
|
||||||
@@ -43,8 +44,8 @@ export class WorkspacePermission extends Entity {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isOwner: info.isOwner,
|
isOwner: info.workspace.role === Permission.Owner,
|
||||||
isAdmin: info.isAdmin,
|
isAdmin: info.workspace.role === Permission.Admin,
|
||||||
isTeam: info.workspace.team,
|
isTeam: info.workspace.team,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
deleteWorkspaceMutation,
|
deleteWorkspaceMutation,
|
||||||
getWorkspaceInfoQuery,
|
getWorkspaceInfoQuery,
|
||||||
getWorkspacesQuery,
|
getWorkspacesQuery,
|
||||||
|
Permission,
|
||||||
ServerDeploymentType,
|
ServerDeploymentType,
|
||||||
} from '@affine/graphql';
|
} from '@affine/graphql';
|
||||||
import type {
|
import type {
|
||||||
@@ -339,8 +340,8 @@ class CloudWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
|
|||||||
|
|
||||||
if (!cloudData && !localData) {
|
if (!cloudData && !localData) {
|
||||||
return {
|
return {
|
||||||
isOwner: info.isOwner,
|
isOwner: info.workspace.role === Permission.Owner,
|
||||||
isAdmin: info.isAdmin,
|
isAdmin: info.workspace.role === Permission.Admin,
|
||||||
isTeam: info.workspace.team,
|
isTeam: info.workspace.team,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -355,8 +356,8 @@ class CloudWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
|
|||||||
return {
|
return {
|
||||||
name: result.name,
|
name: result.name,
|
||||||
avatar: result.avatar,
|
avatar: result.avatar,
|
||||||
isOwner: info.isOwner,
|
isOwner: info.workspace.role === Permission.Owner,
|
||||||
isAdmin: info.isAdmin,
|
isAdmin: info.workspace.role === Permission.Admin,
|
||||||
isTeam: info.workspace.team,
|
isTeam: info.workspace.team,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user