Browse Source

feat(gui): rename roles in api and ui

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4134/head
Pranav C 2 years ago
parent
commit
489bc503fb
  1. 2
      packages/nc-gui/lib/constants.ts
  2. 3
      packages/nc-gui/lib/enums.ts
  3. 5
      packages/nocodb/src/enums/OrgUserRoles.ts
  4. 7
      packages/nocodb/src/lib/meta/api/userApi/userApis.ts
  5. 4
      packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts
  6. 5
      packages/nocodb/src/lib/version-upgrader/ncProjectRolesUpgrader.ts

2
packages/nc-gui/lib/constants.ts

@ -18,7 +18,7 @@ export const rolePermissions = {
[Role.Super]: '*',
[Role.Admin]: {} as Record<string, boolean>,
[Role.Guest]: {} as Record<string, boolean>,
[Role.User]: {
[Role.OrgLevelCreator]: {
include: {
projectCreate: true,
projectActions: true,

3
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',
}

5
packages/nocodb/src/enums/OrgUserRoles.ts

@ -0,0 +1,5 @@
export enum OrgUserRoles {
SUPER = 'super',
CREATOR = 'org-level-creator',
VIEWER = 'org-level-viewer',
}

7
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<TableType>) {
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<TableType>) {
if (process.env.NC_INVITE_ONLY_SIGNUP) {
NcError.badRequest('Not allowed to signup, contact super admin.');
} else {
roles = 'user_new';
roles = OrgUserRoles.VIEWER;
}
}

4
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;

5
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;
})

Loading…
Cancel
Save