Browse Source

feat(gui): add upgrader for updating role names

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4134/head
Pranav C 2 years ago
parent
commit
a51e6c8c29
  1. 2
      packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts
  2. 24
      packages/nocodb/src/lib/version-upgrader/ncProjectRolesUpgrader.ts

2
packages/nocodb/src/lib/version-upgrader/NcUpgrader.ts

@ -5,6 +5,7 @@ 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';
const log = debug('nc:version-upgrader');
@ -33,6 +34,7 @@ export default class NcUpgrader {
{ name: '0011045', handler: ncProjectEnvUpgrader0011045 },
{ name: '0090000', handler: ncProjectUpgraderV2_0090000 },
{ name: '0098004', handler: ncDataTypesUpgrader },
{ name: '0098005', handler: ncProjectRolesUpdate },
];
if (!(await ctx.ncMeta.knexConnection?.schema?.hasTable?.('nc_store'))) {
return;

24
packages/nocodb/src/lib/version-upgrader/ncProjectRolesUpgrader.ts

@ -0,0 +1,24 @@
import { MetaTable } from '../utils/globals';
import { NcUpgraderCtx } from './NcUpgrader';
/** Upgrader for upgrading roles */
export default async function ({ ncMeta }: NcUpgraderCtx) {
const users = await ncMeta.metaList2(null, null, MetaTable.USERS);
for (const user of users) {
user.roles = user.roles
.split(',')
.map((r) => {
if (r === 'user') {
return 'org-level-creator';
} else if (r === 'user-new') {
return 'org-level-viewer';
}
return r;
})
.join(',');
await ncMeta.metaUpdate(null, null, MetaTable.USERS, user, {
roles: user.roles,
});
}
}
Loading…
Cancel
Save