mirror of
https://github.com/nocodb/nocodb.git
synced 2026-02-01 22:08:33 +00:00
fix: handle missing super user scenario
Signed-off-by: mertmit <mertmit99@gmail.com>
This commit is contained in:
@@ -30,7 +30,7 @@ const up = async (knex: Knex) => {
|
||||
}
|
||||
|
||||
// find super user
|
||||
const superUser = await knex(MetaTable.USERS)
|
||||
let superUser = await knex(MetaTable.USERS)
|
||||
.where('roles', 'like', '%super%')
|
||||
.first();
|
||||
|
||||
@@ -43,9 +43,24 @@ const up = async (knex: Knex) => {
|
||||
if (!userCount || +userCount.count === 0) {
|
||||
return;
|
||||
}
|
||||
throw new Error(
|
||||
'No super user found in the system, cannot create default workspace',
|
||||
);
|
||||
|
||||
// Mark first created user on instance as super user
|
||||
const firstUser = await knex(MetaTable.USERS)
|
||||
.orderBy('created_at', 'asc')
|
||||
.first();
|
||||
|
||||
if (!firstUser)
|
||||
throw new Error(
|
||||
'No appropriate user found in the system, cannot create default workspace',
|
||||
);
|
||||
|
||||
await knex(MetaTable.USERS)
|
||||
.update({
|
||||
roles: 'org-level-creator,super',
|
||||
})
|
||||
.where('id', firstUser.id);
|
||||
|
||||
superUser = firstUser;
|
||||
}
|
||||
|
||||
const defaultWorkspaceId = `w${nanoidWorkspace()}`;
|
||||
|
||||
Reference in New Issue
Block a user