From 489bc503fbb9deaf7501c69efccc9d3b0ed98f07 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 17 Oct 2022 23:09:24 +0530 Subject: [PATCH] feat(gui): rename roles in api and ui Signed-off-by: Pranav C --- packages/nc-gui/lib/constants.ts | 2 +- packages/nc-gui/lib/enums.ts | 3 ++- packages/nocodb/src/enums/OrgUserRoles.ts | 5 +++++ packages/nocodb/src/lib/meta/api/userApi/userApis.ts | 7 ++++--- packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts | 4 ++-- .../src/lib/version-upgrader/ncProjectRolesUpgrader.ts | 5 +++-- 6 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 packages/nocodb/src/enums/OrgUserRoles.ts diff --git a/packages/nc-gui/lib/constants.ts b/packages/nc-gui/lib/constants.ts index e8903720ad..5bf9d6b101 100644 --- a/packages/nc-gui/lib/constants.ts +++ b/packages/nc-gui/lib/constants.ts @@ -18,7 +18,7 @@ export const rolePermissions = { [Role.Super]: '*', [Role.Admin]: {} as Record, [Role.Guest]: {} as Record, - [Role.User]: { + [Role.OrgLevelCreator]: { include: { projectCreate: true, projectActions: true, diff --git a/packages/nc-gui/lib/enums.ts b/packages/nc-gui/lib/enums.ts index 43c6aa0888..a96f4f5fb6 100644 --- a/packages/nc-gui/lib/enums.ts +++ b/packages/nc-gui/lib/enums.ts @@ -1,7 +1,8 @@ export enum Role { Super = 'super', Admin = 'admin', - User = 'user', + OrgLevelCreator = 'org-level-creator', + OrgLevelViewer = 'org-level-viewer', Guest = 'guest', } diff --git a/packages/nocodb/src/enums/OrgUserRoles.ts b/packages/nocodb/src/enums/OrgUserRoles.ts new file mode 100644 index 0000000000..dbf53b2c3e --- /dev/null +++ b/packages/nocodb/src/enums/OrgUserRoles.ts @@ -0,0 +1,5 @@ +export enum OrgUserRoles { + SUPER = 'super', + CREATOR = 'org-level-creator', + VIEWER = 'org-level-viewer', +} diff --git a/packages/nocodb/src/lib/meta/api/userApi/userApis.ts b/packages/nocodb/src/lib/meta/api/userApi/userApis.ts index b4ab59de0c..40b1408e45 100644 --- a/packages/nocodb/src/lib/meta/api/userApi/userApis.ts +++ b/packages/nocodb/src/lib/meta/api/userApi/userApis.ts @@ -1,5 +1,6 @@ import { Request, Response } from 'express'; import { TableType, validatePassword } from 'nocodb-sdk'; +import { OrgUserRoles } from '../../../../enums/OrgUserRoles' import catchError, { NcError } from '../../helpers/catchError'; const { isEmail } = require('validator'); import * as ejs from 'ejs'; @@ -84,10 +85,10 @@ export async function signup(req: Request, res: Response) { NcError.badRequest('User already exist'); } } else { - let roles = 'user'; + let roles: string = OrgUserRoles.CREATOR; if (await User.isFirst()) { - roles = 'user,super'; + roles = `${OrgUserRoles.CREATOR},${OrgUserRoles.SUPER}`; // todo: update in nc_store // roles = 'owner,creator,editor' Tele.emit('evt', { @@ -98,7 +99,7 @@ export async function signup(req: Request, res: Response) { if (process.env.NC_INVITE_ONLY_SIGNUP) { NcError.badRequest('Not allowed to signup, contact super admin.'); } else { - roles = 'user_new'; + roles = OrgUserRoles.VIEWER; } } diff --git a/packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts b/packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts index 2946253259..2bac1fbc49 100644 --- a/packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts +++ b/packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts @@ -5,8 +5,8 @@ import NcMetaIO from '../meta/NcMetaIO'; import ncProjectEnvUpgrader from './ncProjectEnvUpgrader'; import ncProjectEnvUpgrader0011045 from './ncProjectEnvUpgrader0011045'; import ncProjectUpgraderV2_0090000 from './ncProjectUpgraderV2_0090000'; -import ncProjectRolesUpdate from './ncProjectRolesUpdate'; import ncDataTypesUpgrader from './ncDataTypesUpgrader'; +import ncProjectRolesUpgrader from './ncProjectRolesUpgrader'; const log = debug('nc:version-upgrader'); import { Tele } from 'nc-help'; @@ -34,7 +34,7 @@ export default class NcUpgrader { { name: '0011045', handler: ncProjectEnvUpgrader0011045 }, { name: '0090000', handler: ncProjectUpgraderV2_0090000 }, { name: '0098004', handler: ncDataTypesUpgrader }, - { name: '0098005', handler: ncProjectRolesUpdate }, + { name: '0098005', handler: ncProjectRolesUpgrader }, ]; if (!(await ctx.ncMeta.knexConnection?.schema?.hasTable?.('nc_store'))) { return; diff --git a/packages/nocodb/src/lib/version-upgrader/ncProjectRolesUpgrader.ts b/packages/nocodb/src/lib/version-upgrader/ncProjectRolesUpgrader.ts index 17367ee2d5..5d272ccac5 100644 --- a/packages/nocodb/src/lib/version-upgrader/ncProjectRolesUpgrader.ts +++ b/packages/nocodb/src/lib/version-upgrader/ncProjectRolesUpgrader.ts @@ -1,3 +1,4 @@ +import { OrgUserRoles } from '../../enums/OrgUserRoles' import { MetaTable } from '../utils/globals'; import { NcUpgraderCtx } from './NcUpgrader'; @@ -10,9 +11,9 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { .split(',') .map((r) => { if (r === 'user') { - return 'org-level-creator'; + return OrgUserRoles.CREATOR; } else if (r === 'user-new') { - return 'org-level-viewer'; + return OrgUserRoles.VIEWER; } return r; })