chore(core): better doc action error message (#10288)

This commit is contained in:
forehalo
2025-02-19 10:38:38 +00:00
parent 54b7515167
commit 02f567f2c0
13 changed files with 74 additions and 72 deletions

View File

@@ -856,7 +856,7 @@ test('default page role should be able to override the workspace role', async t
await t.throwsAsync(
updateDocDefaultRole(app, workspace.id, docId, DocRole.Manager),
{
message: `You do not have permission to access doc ${docId} under Space ${workspace.id}.`,
message: `You do not have permission to perform Doc.Users.Manage action on doc ${docId}.`,
}
);
}
@@ -908,7 +908,7 @@ test('should be able to grant and revoke doc user role', async t => {
// external user can't manage the page
app.switchUser(external);
await t.throwsAsync(revokeDocUserRoles(app, ws.id, docId, read.id), {
message: `You do not have permission to access doc ${docId} under Space ${ws.id}.`,
message: `You do not have permission to perform Doc.Users.Manage action on doc ${docId}.`,
});
}
});
@@ -922,7 +922,7 @@ test('update page default role should throw error if the space does not exist',
await t.throwsAsync(
updateDocDefaultRole(app, nonExistWorkspaceId, docId, DocRole.Manager),
{
message: `You do not have permission to access doc ${docId} under Space ${nonExistWorkspaceId}.`,
message: `You do not have permission to perform Doc.Users.Manage action on doc ${docId}.`,
}
);
});

View File

@@ -108,12 +108,12 @@ test('should not be able to public not permitted doc', async t => {
await t.throwsAsync(publishDoc(app, 'not_exists_ws', 'doc2'), {
message:
'You do not have permission to access doc doc2 under Space not_exists_ws.',
'You do not have permission to perform Doc.Publish action on doc doc2.',
});
await t.throwsAsync(revokePublicDoc(app, 'not_exists_ws', 'doc2'), {
message:
'You do not have permission to access doc doc2 under Space not_exists_ws.',
'You do not have permission to perform Doc.Publish action on doc doc2.',
});
});

View File

@@ -419,11 +419,11 @@ export const USER_FRIENDLY_ERRORS = {
message: ({ spaceId, docId }) =>
`Doc ${docId} under Space ${spaceId} not found.`,
},
doc_access_denied: {
doc_action_denied: {
type: 'no_permission',
args: { spaceId: 'string', docId: 'string' },
message: ({ spaceId, docId }) =>
`You do not have permission to access doc ${docId} under Space ${spaceId}.`,
args: { spaceId: 'string', docId: 'string', action: 'string' },
message: ({ docId, action }) =>
`You do not have permission to perform ${action} action on doc ${docId}.`,
},
version_rejected: {
type: 'action_forbidden',

View File

@@ -299,14 +299,15 @@ export class DocNotFound extends UserFriendlyError {
}
}
@ObjectType()
class DocAccessDeniedDataType {
class DocActionDeniedDataType {
@Field() spaceId!: string
@Field() docId!: string
@Field() action!: string
}
export class DocAccessDenied extends UserFriendlyError {
constructor(args: DocAccessDeniedDataType, message?: string | ((args: DocAccessDeniedDataType) => string)) {
super('no_permission', 'doc_access_denied', message, args);
export class DocActionDenied extends UserFriendlyError {
constructor(args: DocActionDeniedDataType, message?: string | ((args: DocActionDeniedDataType) => string)) {
super('no_permission', 'doc_action_denied', message, args);
}
}
@ObjectType()
@@ -832,7 +833,7 @@ export enum ErrorNames {
SPACE_OWNER_NOT_FOUND,
SPACE_SHOULD_HAVE_ONLY_ONE_OWNER,
DOC_NOT_FOUND,
DOC_ACCESS_DENIED,
DOC_ACTION_DENIED,
VERSION_REJECTED,
INVALID_HISTORY_TIMESTAMP,
DOC_HISTORY_NOT_FOUND,
@@ -903,5 +904,5 @@ registerEnumType(ErrorNames, {
export const ErrorDataUnionType = createUnionType({
name: 'ErrorDataUnion',
types: () =>
[GraphqlBadRequestDataType, QueryTooLongDataType, WrongSignInCredentialsDataType, UnknownOauthProviderDataType, MissingOauthQueryParameterDataType, InvalidEmailDataType, InvalidPasswordLengthDataType, WorkspacePermissionNotFoundDataType, SpaceNotFoundDataType, MemberNotFoundInSpaceDataType, NotInSpaceDataType, AlreadyInSpaceDataType, SpaceAccessDeniedDataType, SpaceOwnerNotFoundDataType, SpaceShouldHaveOnlyOneOwnerDataType, DocNotFoundDataType, DocAccessDeniedDataType, VersionRejectedDataType, InvalidHistoryTimestampDataType, DocHistoryNotFoundDataType, BlobNotFoundDataType, ExpectToGrantDocUserRolesDataType, ExpectToRevokeDocUserRolesDataType, ExpectToUpdateDocUserRoleDataType, UnsupportedSubscriptionPlanDataType, SubscriptionAlreadyExistsDataType, SubscriptionNotExistsDataType, SameSubscriptionRecurringDataType, SubscriptionPlanNotFoundDataType, CopilotDocNotFoundDataType, CopilotMessageNotFoundDataType, CopilotPromptNotFoundDataType, CopilotProviderSideErrorDataType, CopilotInvalidContextDataType, CopilotContextFileNotSupportedDataType, CopilotFailedToModifyContextDataType, CopilotFailedToMatchContextDataType, RuntimeConfigNotFoundDataType, InvalidRuntimeConfigTypeDataType, InvalidLicenseUpdateParamsDataType, WorkspaceMembersExceedLimitToDowngradeDataType] as const,
[GraphqlBadRequestDataType, QueryTooLongDataType, WrongSignInCredentialsDataType, UnknownOauthProviderDataType, MissingOauthQueryParameterDataType, InvalidEmailDataType, InvalidPasswordLengthDataType, WorkspacePermissionNotFoundDataType, SpaceNotFoundDataType, MemberNotFoundInSpaceDataType, NotInSpaceDataType, AlreadyInSpaceDataType, SpaceAccessDeniedDataType, SpaceOwnerNotFoundDataType, SpaceShouldHaveOnlyOneOwnerDataType, DocNotFoundDataType, DocActionDeniedDataType, VersionRejectedDataType, InvalidHistoryTimestampDataType, DocHistoryNotFoundDataType, BlobNotFoundDataType, ExpectToGrantDocUserRolesDataType, ExpectToRevokeDocUserRolesDataType, ExpectToUpdateDocUserRoleDataType, UnsupportedSubscriptionPlanDataType, SubscriptionAlreadyExistsDataType, SubscriptionNotExistsDataType, SameSubscriptionRecurringDataType, SubscriptionPlanNotFoundDataType, CopilotDocNotFoundDataType, CopilotMessageNotFoundDataType, CopilotPromptNotFoundDataType, CopilotProviderSideErrorDataType, CopilotInvalidContextDataType, CopilotContextFileNotSupportedDataType, CopilotFailedToModifyContextDataType, CopilotFailedToMatchContextDataType, RuntimeConfigNotFoundDataType, InvalidRuntimeConfigTypeDataType, InvalidLicenseUpdateParamsDataType, WorkspaceMembersExceedLimitToDowngradeDataType] as const,
});

View File

@@ -5,7 +5,7 @@ import { groupBy } from 'lodash-es';
import {
CanNotBatchGrantDocOwnerPermissions,
DocAccessDenied,
DocActionDenied,
EventBus,
OnEvent,
SpaceAccessDenied,
@@ -552,7 +552,7 @@ export class PermissionService {
user?: string
) {
if (!(await this.tryCheckPage(ws, page, action, user))) {
throw new DocAccessDenied({ spaceId: ws, docId: page });
throw new DocActionDenied({ spaceId: ws, docId: page, action });
}
}

View File

@@ -14,7 +14,7 @@ import type { WorkspaceDoc as PrismaWorkspaceDoc } from '@prisma/client';
import { PrismaClient } from '@prisma/client';
import {
DocAccessDenied,
DocActionDenied,
DocDefaultRoleCanNotBeOwner,
DocIsNotPublic,
ExpectToGrantDocUserRoles,
@@ -662,7 +662,7 @@ export class DocResolver {
user.id
);
} catch (error) {
if (error instanceof DocAccessDenied) {
if (error instanceof DocActionDenied) {
this.logger.log(
`User does not have permission to update page default role (${JSON.stringify(
{

View File

@@ -250,7 +250,8 @@ input DeleteSessionInput {
workspaceId: String!
}
type DocAccessDeniedDataType {
type DocActionDeniedDataType {
action: String!
docId: String!
spaceId: String!
}
@@ -315,7 +316,7 @@ type EditorType {
name: String!
}
union ErrorDataUnion = AlreadyInSpaceDataType | BlobNotFoundDataType | CopilotContextFileNotSupportedDataType | CopilotDocNotFoundDataType | CopilotFailedToMatchContextDataType | CopilotFailedToModifyContextDataType | CopilotInvalidContextDataType | CopilotMessageNotFoundDataType | CopilotPromptNotFoundDataType | CopilotProviderSideErrorDataType | DocAccessDeniedDataType | DocHistoryNotFoundDataType | DocNotFoundDataType | ExpectToGrantDocUserRolesDataType | ExpectToRevokeDocUserRolesDataType | ExpectToUpdateDocUserRoleDataType | GraphqlBadRequestDataType | InvalidEmailDataType | InvalidHistoryTimestampDataType | InvalidLicenseUpdateParamsDataType | InvalidPasswordLengthDataType | InvalidRuntimeConfigTypeDataType | MemberNotFoundInSpaceDataType | MissingOauthQueryParameterDataType | NotInSpaceDataType | QueryTooLongDataType | RuntimeConfigNotFoundDataType | SameSubscriptionRecurringDataType | SpaceAccessDeniedDataType | SpaceNotFoundDataType | SpaceOwnerNotFoundDataType | SpaceShouldHaveOnlyOneOwnerDataType | SubscriptionAlreadyExistsDataType | SubscriptionNotExistsDataType | SubscriptionPlanNotFoundDataType | UnknownOauthProviderDataType | UnsupportedSubscriptionPlanDataType | VersionRejectedDataType | WorkspaceMembersExceedLimitToDowngradeDataType | WorkspacePermissionNotFoundDataType | WrongSignInCredentialsDataType
union ErrorDataUnion = AlreadyInSpaceDataType | BlobNotFoundDataType | CopilotContextFileNotSupportedDataType | CopilotDocNotFoundDataType | CopilotFailedToMatchContextDataType | CopilotFailedToModifyContextDataType | CopilotInvalidContextDataType | CopilotMessageNotFoundDataType | CopilotPromptNotFoundDataType | CopilotProviderSideErrorDataType | DocActionDeniedDataType | DocHistoryNotFoundDataType | DocNotFoundDataType | ExpectToGrantDocUserRolesDataType | ExpectToRevokeDocUserRolesDataType | ExpectToUpdateDocUserRoleDataType | GraphqlBadRequestDataType | InvalidEmailDataType | InvalidHistoryTimestampDataType | InvalidLicenseUpdateParamsDataType | InvalidPasswordLengthDataType | InvalidRuntimeConfigTypeDataType | MemberNotFoundInSpaceDataType | MissingOauthQueryParameterDataType | NotInSpaceDataType | QueryTooLongDataType | RuntimeConfigNotFoundDataType | SameSubscriptionRecurringDataType | SpaceAccessDeniedDataType | SpaceNotFoundDataType | SpaceOwnerNotFoundDataType | SpaceShouldHaveOnlyOneOwnerDataType | SubscriptionAlreadyExistsDataType | SubscriptionNotExistsDataType | SubscriptionPlanNotFoundDataType | UnknownOauthProviderDataType | UnsupportedSubscriptionPlanDataType | VersionRejectedDataType | WorkspaceMembersExceedLimitToDowngradeDataType | WorkspacePermissionNotFoundDataType | WrongSignInCredentialsDataType
enum ErrorNames {
ACCESS_DENIED
@@ -347,7 +348,7 @@ enum ErrorNames {
COPILOT_SESSION_DELETED
COPILOT_SESSION_NOT_FOUND
CUSTOMER_PORTAL_CREATE_FAILED
DOC_ACCESS_DENIED
DOC_ACTION_DENIED
DOC_DEFAULT_ROLE_CAN_NOT_BE_OWNER
DOC_HISTORY_NOT_FOUND
DOC_IS_NOT_PUBLIC

View File

@@ -360,7 +360,7 @@ enum ErrorNames {
CUSTOMER_PORTAL_CREATE_FAILED
DOC_ACCESS_DENIED
DOC_ACTION_DENIED
DOC_HISTORY_NOT_FOUND

View File

@@ -1,7 +1,7 @@
import { Menu, MenuItem, MenuTrigger, notify } from '@affine/component';
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
import { ShareInfoService } from '@affine/core/modules/share-doc';
import { PublicDocMode } from '@affine/graphql';
import { PublicDocMode, UserFriendlyError } from '@affine/graphql';
import { useI18n } from '@affine/i18n';
import track from '@affine/track';
import {
@@ -73,18 +73,12 @@ export const PublicDoc = ({ disabled }: { disabled?: boolean }) => {
style: 'normal',
icon: <SingleSelectCheckSolidIcon color={cssVar('primaryColor')} />,
});
} catch (err) {
} catch (error) {
const err = UserFriendlyError.fromAnyError(error);
notify.error({
title:
t[
'com.affine.share-menu.confirm-modify-mode.notification.fail.title'
](),
message:
t[
'com.affine.share-menu.confirm-modify-mode.notification.fail.message'
](),
title: err.name,
message: err.message,
});
console.error(err);
}
}, [isSharedPage, shareInfoService.shareInfo, t]);

View File

@@ -144,6 +144,11 @@ export interface CopilotContextListItem {
status: Maybe<ContextFileStatus>;
}
export interface CopilotDocNotFoundDataType {
__typename?: 'CopilotDocNotFoundDataType';
docId: Scalars['String']['output'];
}
export interface CopilotFailedToMatchContextDataType {
__typename?: 'CopilotFailedToMatchContextDataType';
content: Scalars['String']['output'];
@@ -308,8 +313,9 @@ export interface DeleteSessionInput {
workspaceId: Scalars['String']['input'];
}
export interface DocAccessDeniedDataType {
__typename?: 'DocAccessDeniedDataType';
export interface DocActionDeniedDataType {
__typename?: 'DocActionDeniedDataType';
action: Scalars['String']['output'];
docId: Scalars['String']['output'];
spaceId: Scalars['String']['output'];
}
@@ -387,18 +393,20 @@ export type ErrorDataUnion =
| AlreadyInSpaceDataType
| BlobNotFoundDataType
| CopilotContextFileNotSupportedDataType
| CopilotDocNotFoundDataType
| CopilotFailedToMatchContextDataType
| CopilotFailedToModifyContextDataType
| CopilotInvalidContextDataType
| CopilotMessageNotFoundDataType
| CopilotPromptNotFoundDataType
| CopilotProviderSideErrorDataType
| DocAccessDeniedDataType
| DocActionDeniedDataType
| DocHistoryNotFoundDataType
| DocNotFoundDataType
| ExpectToGrantDocUserRolesDataType
| ExpectToRevokeDocUserRolesDataType
| ExpectToUpdateDocUserRoleDataType
| GraphqlBadRequestDataType
| InvalidEmailDataType
| InvalidHistoryTimestampDataType
| InvalidLicenseUpdateParamsDataType
@@ -440,6 +448,7 @@ export enum ErrorNames {
CAPTCHA_VERIFICATION_FAILED = 'CAPTCHA_VERIFICATION_FAILED',
COPILOT_ACTION_TAKEN = 'COPILOT_ACTION_TAKEN',
COPILOT_CONTEXT_FILE_NOT_SUPPORTED = 'COPILOT_CONTEXT_FILE_NOT_SUPPORTED',
COPILOT_DOC_NOT_FOUND = 'COPILOT_DOC_NOT_FOUND',
COPILOT_FAILED_TO_CREATE_MESSAGE = 'COPILOT_FAILED_TO_CREATE_MESSAGE',
COPILOT_FAILED_TO_GENERATE_TEXT = 'COPILOT_FAILED_TO_GENERATE_TEXT',
COPILOT_FAILED_TO_MATCH_CONTEXT = 'COPILOT_FAILED_TO_MATCH_CONTEXT',
@@ -453,7 +462,7 @@ export enum ErrorNames {
COPILOT_SESSION_DELETED = 'COPILOT_SESSION_DELETED',
COPILOT_SESSION_NOT_FOUND = 'COPILOT_SESSION_NOT_FOUND',
CUSTOMER_PORTAL_CREATE_FAILED = 'CUSTOMER_PORTAL_CREATE_FAILED',
DOC_ACCESS_DENIED = 'DOC_ACCESS_DENIED',
DOC_ACTION_DENIED = 'DOC_ACTION_DENIED',
DOC_DEFAULT_ROLE_CAN_NOT_BE_OWNER = 'DOC_DEFAULT_ROLE_CAN_NOT_BE_OWNER',
DOC_HISTORY_NOT_FOUND = 'DOC_HISTORY_NOT_FOUND',
DOC_IS_NOT_PUBLIC = 'DOC_IS_NOT_PUBLIC',
@@ -470,6 +479,7 @@ export enum ErrorNames {
FAILED_TO_CHECKOUT = 'FAILED_TO_CHECKOUT',
FAILED_TO_SAVE_UPDATES = 'FAILED_TO_SAVE_UPDATES',
FAILED_TO_UPSERT_SNAPSHOT = 'FAILED_TO_UPSERT_SNAPSHOT',
GRAPHQL_BAD_REQUEST = 'GRAPHQL_BAD_REQUEST',
INTERNAL_SERVER_ERROR = 'INTERNAL_SERVER_ERROR',
INVALID_CHECKOUT_PARAMETERS = 'INVALID_CHECKOUT_PARAMETERS',
INVALID_EMAIL = 'INVALID_EMAIL',
@@ -583,6 +593,12 @@ export interface GrantedDocUserTypeEdge {
node: GrantedDocUserType;
}
export interface GraphqlBadRequestDataType {
__typename?: 'GraphqlBadRequestDataType';
code: Scalars['String']['output'];
message: Scalars['String']['output'];
}
export interface InvalidEmailDataType {
__typename?: 'InvalidEmailDataType';
email: Scalars['String']['output'];

View File

@@ -1,26 +1,26 @@
{
"ar": 87,
"ar": 88,
"ca": 4,
"da": 5,
"de": 87,
"el-GR": 87,
"de": 88,
"el-GR": 88,
"en": 100,
"es-AR": 87,
"es-AR": 88,
"es-CL": 89,
"es": 87,
"fa": 87,
"fr": 87,
"es": 88,
"fa": 88,
"fr": 88,
"hi": 2,
"it-IT": 87,
"it-IT": 88,
"it": 1,
"ja": 87,
"ja": 88,
"ko": 63,
"pl": 87,
"pt-BR": 87,
"ru": 87,
"sv-SE": 87,
"uk": 87,
"pl": 88,
"pt-BR": 88,
"ru": 88,
"sv-SE": 88,
"uk": 88,
"ur": 2,
"zh-Hans": 87,
"zh-Hant": 87
"zh-Hans": 88,
"zh-Hant": 88
}

View File

@@ -5708,19 +5708,19 @@ export function useAFFiNEI18N(): {
*/
["com.affine.settings.workspace.affine-ai.description"](): string;
/**
* `Achieved workspaces`
* `Archived workspaces`
*/
["com.affine.settings.workspace.backup"](): string;
/**
* `Management in local workspace backup files`
* `Manage archived local workspace files`
*/
["com.affine.settings.workspace.backup.subtitle"](): string;
/**
* `No backup files found`
* `No archived workspace files found`
*/
["com.affine.settings.workspace.backup.empty"](): string;
/**
* `Delete backup workspace`
* `Delete archived workspace`
*/
["com.affine.settings.workspace.backup.delete"](): string;
/**
@@ -5790,14 +5790,6 @@ export function useAFFiNEI18N(): {
* `Shared doc`
*/
["com.affine.share-menu.SharedPage"](): string;
/**
* `Please try again later.`
*/
["com.affine.share-menu.confirm-modify-mode.notification.fail.message"](): string;
/**
* `Failed to modify`
*/
["com.affine.share-menu.confirm-modify-mode.notification.fail.title"](): string;
/**
* `Copy Link`
*/
@@ -7199,11 +7191,11 @@ export function useAFFiNEI18N(): {
spaceId: string;
}>): string;
/**
* `You do not have permission to access doc {{docId}} under Space {{spaceId}}.`
* `You do not have permission to perform {{action}} action on doc {{docId}}.`
*/
["error.DOC_ACCESS_DENIED"](options: Readonly<{
["error.DOC_ACTION_DENIED"](options: Readonly<{
action: string;
docId: string;
spaceId: string;
}>): string;
/**
* `Your client with version {{version}} is rejected by remote sync server. Please upgrade to {{serverVersion}}.`

View File

@@ -1446,8 +1446,6 @@
"com.affine.share-menu.ShareWithLink": "Share with link",
"com.affine.share-menu.ShareWithLinkDescription": "Create a link you can easily share with anyone. The visitors will open your doc in the form od a document",
"com.affine.share-menu.SharedPage": "Shared doc",
"com.affine.share-menu.confirm-modify-mode.notification.fail.message": "Please try again later.",
"com.affine.share-menu.confirm-modify-mode.notification.fail.title": "Failed to modify",
"com.affine.share-menu.copy": "Copy Link",
"com.affine.share-menu.copy-private-link": "Copy private link",
"com.affine.share-menu.copy.block": "Copy Link to Selected Block",
@@ -1783,7 +1781,7 @@
"error.SPACE_OWNER_NOT_FOUND": "Owner of Space {{spaceId}} not found.",
"error.SPACE_SHOULD_HAVE_ONLY_ONE_OWNER": "Space should have only one owner.",
"error.DOC_NOT_FOUND": "Doc {{docId}} under Space {{spaceId}} not found.",
"error.DOC_ACCESS_DENIED": "You do not have permission to access doc {{docId}} under Space {{spaceId}}.",
"error.DOC_ACTION_DENIED": "You do not have permission to perform {{action}} action on doc {{docId}}.",
"error.VERSION_REJECTED": "Your client with version {{version}} is rejected by remote sync server. Please upgrade to {{serverVersion}}.",
"error.INVALID_HISTORY_TIMESTAMP": "Invalid doc history timestamp provided.",
"error.DOC_HISTORY_NOT_FOUND": "History of {{docId}} at {{timestamp}} under Space {{spaceId}}.",