mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
test(server): add more test for team workspace (#9182)
This commit is contained in:
@@ -347,6 +347,11 @@ export const USER_FRIENDLY_ERRORS = {
|
||||
args: { spaceId: 'string' },
|
||||
message: ({ spaceId }) => `Space ${spaceId} not found.`,
|
||||
},
|
||||
member_not_found_in_space: {
|
||||
type: 'action_forbidden',
|
||||
args: { spaceId: 'string' },
|
||||
message: ({ spaceId }) => `Member not found in Space ${spaceId}.`,
|
||||
},
|
||||
not_in_space: {
|
||||
type: 'action_forbidden',
|
||||
args: { spaceId: 'string' },
|
||||
|
||||
@@ -191,6 +191,16 @@ export class SpaceNotFound extends UserFriendlyError {
|
||||
}
|
||||
}
|
||||
@ObjectType()
|
||||
class MemberNotFoundInSpaceDataType {
|
||||
@Field() spaceId!: string
|
||||
}
|
||||
|
||||
export class MemberNotFoundInSpace extends UserFriendlyError {
|
||||
constructor(args: MemberNotFoundInSpaceDataType, message?: string | ((args: MemberNotFoundInSpaceDataType) => string)) {
|
||||
super('action_forbidden', 'member_not_found_in_space', message, args);
|
||||
}
|
||||
}
|
||||
@ObjectType()
|
||||
class NotInSpaceDataType {
|
||||
@Field() spaceId!: string
|
||||
}
|
||||
@@ -615,6 +625,7 @@ export enum ErrorNames {
|
||||
ACCESS_DENIED,
|
||||
EMAIL_VERIFICATION_REQUIRED,
|
||||
SPACE_NOT_FOUND,
|
||||
MEMBER_NOT_FOUND_IN_SPACE,
|
||||
NOT_IN_SPACE,
|
||||
ALREADY_IN_SPACE,
|
||||
SPACE_ACCESS_DENIED,
|
||||
@@ -674,5 +685,5 @@ registerEnumType(ErrorNames, {
|
||||
export const ErrorDataUnionType = createUnionType({
|
||||
name: 'ErrorDataUnion',
|
||||
types: () =>
|
||||
[WrongSignInCredentialsDataType, UnknownOauthProviderDataType, MissingOauthQueryParameterDataType, InvalidEmailDataType, InvalidPasswordLengthDataType, SpaceNotFoundDataType, NotInSpaceDataType, AlreadyInSpaceDataType, SpaceAccessDeniedDataType, SpaceOwnerNotFoundDataType, DocNotFoundDataType, DocAccessDeniedDataType, VersionRejectedDataType, InvalidHistoryTimestampDataType, DocHistoryNotFoundDataType, BlobNotFoundDataType, UnsupportedSubscriptionPlanDataType, SubscriptionAlreadyExistsDataType, SubscriptionNotExistsDataType, SameSubscriptionRecurringDataType, SubscriptionPlanNotFoundDataType, CopilotMessageNotFoundDataType, CopilotPromptNotFoundDataType, CopilotProviderSideErrorDataType, RuntimeConfigNotFoundDataType, InvalidRuntimeConfigTypeDataType] as const,
|
||||
[WrongSignInCredentialsDataType, UnknownOauthProviderDataType, MissingOauthQueryParameterDataType, InvalidEmailDataType, InvalidPasswordLengthDataType, SpaceNotFoundDataType, MemberNotFoundInSpaceDataType, NotInSpaceDataType, AlreadyInSpaceDataType, SpaceAccessDeniedDataType, SpaceOwnerNotFoundDataType, DocNotFoundDataType, DocAccessDeniedDataType, VersionRejectedDataType, InvalidHistoryTimestampDataType, DocHistoryNotFoundDataType, BlobNotFoundDataType, UnsupportedSubscriptionPlanDataType, SubscriptionAlreadyExistsDataType, SubscriptionNotExistsDataType, SameSubscriptionRecurringDataType, SubscriptionPlanNotFoundDataType, CopilotMessageNotFoundDataType, CopilotPromptNotFoundDataType, CopilotProviderSideErrorDataType, RuntimeConfigNotFoundDataType, InvalidRuntimeConfigTypeDataType] as const,
|
||||
});
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
Cache,
|
||||
EventEmitter,
|
||||
type EventPayload,
|
||||
NotInSpace,
|
||||
MemberNotFoundInSpace,
|
||||
OnEvent,
|
||||
RequestMutex,
|
||||
TooManyRequest,
|
||||
@@ -152,7 +152,16 @@ export class TeamWorkspaceResolver {
|
||||
description: 'invite link for workspace',
|
||||
nullable: true,
|
||||
})
|
||||
async inviteLink(@Parent() workspace: WorkspaceType) {
|
||||
async inviteLink(
|
||||
@Parent() workspace: WorkspaceType,
|
||||
@CurrentUser() user: CurrentUser
|
||||
) {
|
||||
await this.permissions.checkWorkspace(
|
||||
workspace.id,
|
||||
user.id,
|
||||
Permission.Admin
|
||||
);
|
||||
|
||||
const cacheId = `workspace:inviteLink:${workspace.id}`;
|
||||
const id = await this.cache.get<{ inviteId: string }>(cacheId);
|
||||
if (id) {
|
||||
@@ -261,7 +270,7 @@ export class TeamWorkspaceResolver {
|
||||
}
|
||||
return new TooManyRequest();
|
||||
} else {
|
||||
return new NotInSpace({ spaceId: workspaceId });
|
||||
return new MemberNotFoundInSpace({ spaceId: workspaceId });
|
||||
}
|
||||
} catch (e) {
|
||||
this.logger.error('failed to invite user', e);
|
||||
@@ -307,7 +316,7 @@ export class TeamWorkspaceResolver {
|
||||
|
||||
return result;
|
||||
} else {
|
||||
return new NotInSpace({ spaceId: workspaceId });
|
||||
return new MemberNotFoundInSpace({ spaceId: workspaceId });
|
||||
}
|
||||
} catch (e) {
|
||||
this.logger.error('failed to invite user', e);
|
||||
|
||||
@@ -209,7 +209,7 @@ type EditorType {
|
||||
name: String!
|
||||
}
|
||||
|
||||
union ErrorDataUnion = AlreadyInSpaceDataType | BlobNotFoundDataType | CopilotMessageNotFoundDataType | CopilotPromptNotFoundDataType | CopilotProviderSideErrorDataType | DocAccessDeniedDataType | DocHistoryNotFoundDataType | DocNotFoundDataType | InvalidEmailDataType | InvalidHistoryTimestampDataType | InvalidPasswordLengthDataType | InvalidRuntimeConfigTypeDataType | MissingOauthQueryParameterDataType | NotInSpaceDataType | RuntimeConfigNotFoundDataType | SameSubscriptionRecurringDataType | SpaceAccessDeniedDataType | SpaceNotFoundDataType | SpaceOwnerNotFoundDataType | SubscriptionAlreadyExistsDataType | SubscriptionNotExistsDataType | SubscriptionPlanNotFoundDataType | UnknownOauthProviderDataType | UnsupportedSubscriptionPlanDataType | VersionRejectedDataType | WrongSignInCredentialsDataType
|
||||
union ErrorDataUnion = AlreadyInSpaceDataType | BlobNotFoundDataType | CopilotMessageNotFoundDataType | CopilotPromptNotFoundDataType | CopilotProviderSideErrorDataType | DocAccessDeniedDataType | DocHistoryNotFoundDataType | DocNotFoundDataType | InvalidEmailDataType | InvalidHistoryTimestampDataType | InvalidPasswordLengthDataType | InvalidRuntimeConfigTypeDataType | MemberNotFoundInSpaceDataType | MissingOauthQueryParameterDataType | NotInSpaceDataType | RuntimeConfigNotFoundDataType | SameSubscriptionRecurringDataType | SpaceAccessDeniedDataType | SpaceNotFoundDataType | SpaceOwnerNotFoundDataType | SubscriptionAlreadyExistsDataType | SubscriptionNotExistsDataType | SubscriptionPlanNotFoundDataType | UnknownOauthProviderDataType | UnsupportedSubscriptionPlanDataType | VersionRejectedDataType | WrongSignInCredentialsDataType
|
||||
|
||||
enum ErrorNames {
|
||||
ACCESS_DENIED
|
||||
@@ -257,6 +257,7 @@ enum ErrorNames {
|
||||
INVALID_SUBSCRIPTION_PARAMETERS
|
||||
LINK_EXPIRED
|
||||
MAILER_SERVICE_IS_NOT_CONFIGURED
|
||||
MEMBER_NOT_FOUND_IN_SPACE
|
||||
MEMBER_QUOTA_EXCEEDED
|
||||
MISSING_OAUTH_QUERY_PARAMETER
|
||||
NOT_FOUND
|
||||
@@ -472,6 +473,10 @@ input ManageUserInput {
|
||||
name: String
|
||||
}
|
||||
|
||||
type MemberNotFoundInSpaceDataType {
|
||||
spaceId: String!
|
||||
}
|
||||
|
||||
type MissingOauthQueryParameterDataType {
|
||||
name: String!
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user