Skip to content

Commit

Permalink
make reserved workspace name readonly
Browse files Browse the repository at this point in the history
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
  • Loading branch information
yuye-aws committed Sep 25, 2023
1 parent 1281ceb commit af6e0ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/plugins/workspace/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { IWorkspaceDBImpl, WorkspaceRoutePermissionItem } from '../types';
export const WORKSPACES_API_BASE_URL = '/api/workspaces';

const workspacePermissionMode = schema.oneOf([
schema.literal(WorkspacePermissionMode.Read),
schema.literal(WorkspacePermissionMode.Write),
schema.literal(WorkspacePermissionMode.LibraryRead),
schema.literal(WorkspacePermissionMode.LibraryWrite),
schema.literal(WorkspacePermissionMode.Management),
Expand All @@ -41,6 +43,7 @@ const workspaceAttributesSchema = schema.object({
features: schema.maybe(schema.arrayOf(schema.string())),
color: schema.maybe(schema.string()),
icon: schema.maybe(schema.string()),
reserved: schema.maybe(schema.boolean()),
defaultVISTheme: schema.maybe(schema.string()),
permissions: schema.oneOf([workspacePermission, schema.arrayOf(workspacePermission)]),
});
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/workspace/server/workspace_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ const DUPLICATE_WORKSPACE_NAME_ERROR = i18n.translate('workspace.duplicate.name.
defaultMessage: 'workspace name has already been used, try with a different name',
});

const RESERVED_WORKSPACE_NAME_ERROR = i18n.translate('workspace.reserved.name.error', {
defaultMessage: 'reserved workspace name cannot be changed',
});

export class WorkspaceClientWithSavedObject implements IWorkspaceDBImpl {
private setupDep: CoreSetup;
private logger: Logger;
Expand Down Expand Up @@ -338,6 +342,9 @@ export class WorkspaceClientWithSavedObject implements IWorkspaceDBImpl {
const client = this.getSavedObjectClientsFromRequestDetail(requestDetail);
const workspaceInDB: SavedObject<WorkspaceAttribute> = await client.get(WORKSPACE_TYPE, id);
if (workspaceInDB.attributes.name !== attributes.name) {
if (workspaceInDB.attributes.reserved) {
throw new Error(RESERVED_WORKSPACE_NAME_ERROR);
}
const existingWorkspaceRes = await this.getScopedClientWithoutPermission(
requestDetail
)?.find({
Expand Down

0 comments on commit af6e0ee

Please sign in to comment.