Skip to content

Commit

Permalink
chore: remove owner transfer limitation for normal workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Dec 20, 2024
1 parent f5f8ecb commit 5ee43d1
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 43 deletions.
4 changes: 0 additions & 4 deletions packages/backend/server/src/base/error/def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,6 @@ export const USER_FRIENDLY_ERRORS = {
args: { spaceId: 'string' },
message: ({ spaceId }) => `Owner of Space ${spaceId} not found.`,
},
cant_change_space_owner: {
type: 'action_forbidden',
message: 'You are not allowed to change the owner of a Space.',
},
doc_not_found: {
type: 'resource_not_found',
args: { spaceId: 'string', docId: 'string' },
Expand Down
9 changes: 1 addition & 8 deletions packages/backend/server/src/base/error/errors.gen.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable */
// AUTO GENERATED FILE
import { createUnionType, Field, ObjectType, registerEnumType } from '@nestjs/graphql';

Expand Down Expand Up @@ -240,12 +240,6 @@ export class SpaceOwnerNotFound extends UserFriendlyError {
super('internal_server_error', 'space_owner_not_found', message, args);
}
}

export class CantChangeSpaceOwner extends UserFriendlyError {
constructor(message?: string) {
super('action_forbidden', 'cant_change_space_owner', message);
}
}
@ObjectType()
class DocNotFoundDataType {
@Field() spaceId!: string
Expand Down Expand Up @@ -630,7 +624,6 @@ export enum ErrorNames {
ALREADY_IN_SPACE,
SPACE_ACCESS_DENIED,
SPACE_OWNER_NOT_FOUND,
CANT_CHANGE_SPACE_OWNER,
DOC_NOT_FOUND,
DOC_ACCESS_DENIED,
VERSION_REJECTED,
Expand Down
4 changes: 0 additions & 4 deletions packages/backend/server/src/core/permission/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,6 @@ export class PermissionService {
this.prisma.workspaceUserPermission.update({
where: {
workspaceId_userId: { workspaceId: ws, userId: user },
// only update permission:
// 1. if the new permission is owner and original permission is admin
// 2. if the original permission is not owner
type: toBeOwner ? Permission.Admin : { not: Permission.Owner },
},
data: { type: permission },
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ export class TeamWorkspaceResolver {
}
} catch (e) {
this.logger.error('failed to invite user', e);
if (e instanceof UserFriendlyError) return e;
// pass through user friendly error
if (e instanceof UserFriendlyError) {
return e;
}
return new TooManyRequest();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type { FileUpload } from '../../../base';
import {
AlreadyInSpace,
Cache,
CantChangeSpaceOwner,
DocNotFound,
EventEmitter,
InternalServerError,
Expand Down Expand Up @@ -383,19 +382,20 @@ export class WorkspaceResolver {
@CurrentUser() user: CurrentUser,
@Args('workspaceId') workspaceId: string,
@Args('email') email: string,
@Args('permission', { type: () => Permission }) permission: Permission,
@Args('sendInviteMail', { nullable: true }) sendInviteMail: boolean
@Args('sendInviteMail', { nullable: true }) sendInviteMail: boolean,
@Args('permission', {
type: () => Permission,
nullable: true,
deprecationReason: 'never used',
})
_permission?: Permission
) {
await this.permissions.checkWorkspace(
workspaceId,
user.id,
Permission.Admin
);

if (permission === Permission.Owner) {
throw new CantChangeSpaceOwner();
}

try {
// lock to prevent concurrent invite and grant
const lockFlag = `invite:${workspaceId}`;
Expand Down Expand Up @@ -428,7 +428,7 @@ export class WorkspaceResolver {
const inviteId = await this.permissions.grant(
workspaceId,
target.id,
permission
Permission.Write
);
if (sendInviteMail) {
try {
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/server/src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ enum ErrorNames {
BLOB_QUOTA_EXCEEDED
CANNOT_DELETE_ALL_ADMIN_ACCOUNT
CANNOT_DELETE_OWN_ACCOUNT
CANT_CHANGE_SPACE_OWNER
CANT_UPDATE_ONETIME_PAYMENT_SUBSCRIPTION
CAPTCHA_VERIFICATION_FAILED
COPILOT_ACTION_TAKEN
Expand Down Expand Up @@ -526,7 +525,7 @@ type Mutation {
"""Create a chat session"""
forkCopilotSession(options: ForkChatSessionInput!): String!
grantMember(permission: Permission!, userId: String!, workspaceId: String!): String!
invite(email: String!, permission: Permission!, sendInviteMail: Boolean, workspaceId: String!): String!
invite(email: String!, permission: Permission @deprecated(reason: "never used"), sendInviteMail: Boolean, workspaceId: String!): String!
inviteBatch(emails: [String!]!, sendInviteMail: Boolean, workspaceId: String!): [InviteResult!]!
leaveWorkspace(sendLeaveMail: Boolean, workspaceId: String!, workspaceName: String @deprecated(reason: "no longer used")): Boolean!
publishPage(mode: PublicPageMode = Page, pageId: String!, workspaceId: String!): WorkspacePage!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,10 @@ export class WorkspacePermission extends Entity {
})
);

async inviteMember(
email: string,
permission: Permission,
sendInviteMail?: boolean
) {
async inviteMember(email: string, sendInviteMail?: boolean) {
return await this.store.inviteMember(
this.workspaceService.workspace.id,
email,
permission,
sendInviteMail
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class WorkspacePermissionStore extends Store {
async inviteMember(
workspaceId: string,
email: string,
permission: Permission,
sendInviteMail = false
) {
if (!this.workspaceServerService.server) {
Expand All @@ -49,7 +48,6 @@ export class WorkspacePermissionStore extends Store {
variables: {
workspaceId,
email,
permission,
sendInviteMail,
},
});
Expand Down
3 changes: 1 addition & 2 deletions packages/frontend/graphql/src/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1367,11 +1367,10 @@ export const inviteByEmailMutation = {
definitionName: 'invite',
containsFile: false,
query: `
mutation inviteByEmail($workspaceId: String!, $email: String!, $permission: Permission!, $sendInviteMail: Boolean) {
mutation inviteByEmail($workspaceId: String!, $email: String!, $sendInviteMail: Boolean) {
invite(
workspaceId: $workspaceId
email: $email
permission: $permission
sendInviteMail: $sendInviteMail
)
}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
mutation inviteByEmail(
$workspaceId: String!
$email: String!
$permission: Permission!
$sendInviteMail: Boolean
) {
invite(
workspaceId: $workspaceId
email: $email
permission: $permission
sendInviteMail: $sendInviteMail
)
}
6 changes: 2 additions & 4 deletions packages/frontend/graphql/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable */
export type Maybe<T> = T | null;
export type InputMaybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
Expand Down Expand Up @@ -298,7 +298,6 @@ export enum ErrorNames {
BLOB_QUOTA_EXCEEDED = 'BLOB_QUOTA_EXCEEDED',
CANNOT_DELETE_ALL_ADMIN_ACCOUNT = 'CANNOT_DELETE_ALL_ADMIN_ACCOUNT',
CANNOT_DELETE_OWN_ACCOUNT = 'CANNOT_DELETE_OWN_ACCOUNT',
CANT_CHANGE_SPACE_OWNER = 'CANT_CHANGE_SPACE_OWNER',
CANT_UPDATE_ONETIME_PAYMENT_SUBSCRIPTION = 'CANT_UPDATE_ONETIME_PAYMENT_SUBSCRIPTION',
CAPTCHA_VERIFICATION_FAILED = 'CAPTCHA_VERIFICATION_FAILED',
COPILOT_ACTION_TAKEN = 'COPILOT_ACTION_TAKEN',
Expand Down Expand Up @@ -729,7 +728,7 @@ export interface MutationGrantMemberArgs {

export interface MutationInviteArgs {
email: Scalars['String']['input'];
permission: Permission;
permission?: InputMaybe<Permission>;
sendInviteMail?: InputMaybe<Scalars['Boolean']['input']>;
workspaceId: Scalars['String']['input'];
}
Expand Down Expand Up @@ -2647,7 +2646,6 @@ export type RemoveWorkspaceFeatureMutation = {
export type InviteByEmailMutationVariables = Exact<{
workspaceId: Scalars['String']['input'];
email: Scalars['String']['input'];
permission: Permission;
sendInviteMail?: InputMaybe<Scalars['Boolean']['input']>;
}>;

Expand Down

0 comments on commit 5ee43d1

Please sign in to comment.