mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-11 00:08:30 +01:00
fix: migrate only users without any role
This commit is contained in:
parent
6c57aeb232
commit
65fad95c6f
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
|
|
||||||
function resolveRoleName(permissions = []) {
|
function resolveRoleName(permissions) {
|
||||||
if (permissions.length === 0) {
|
if (!permissions || permissions.length === 0) {
|
||||||
return 'Viewer';
|
return 'Viewer';
|
||||||
}
|
}
|
||||||
if (permissions.includes('ADMIN')) {
|
if (permissions.includes('ADMIN')) {
|
||||||
@ -13,24 +13,27 @@ function resolveRoleName(permissions = []) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.up = function(db, cb) {
|
exports.up = function(db, cb) {
|
||||||
db.runSql(`SELECT id, permissions from users;`, (err, results) => {
|
db.runSql(
|
||||||
if (results.rowCount > 0) {
|
`SELECT id, permissions from users WHERE id NOT IN (select user_id from role_user);`,
|
||||||
const users = results.rows;
|
(err, results) => {
|
||||||
const insertRootRole = users.map(u => {
|
if (results.rowCount > 0) {
|
||||||
const roleName = resolveRoleName(u.permissions);
|
const users = results.rows;
|
||||||
return db.runSql.bind(
|
const insertRootRole = users.map(u => {
|
||||||
db,
|
const roleName = resolveRoleName(u.permissions);
|
||||||
`INSERT INTO role_user (role_id, user_id)
|
return db.runSql.bind(
|
||||||
|
db,
|
||||||
|
`INSERT INTO role_user (role_id, user_id)
|
||||||
SELECT id, '${u.id}'
|
SELECT id, '${u.id}'
|
||||||
FROM roles
|
FROM roles
|
||||||
WHERE name = '${roleName}' AND type = 'root';`,
|
WHERE name = '${roleName}' AND type = 'root';`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
async.series(insertRootRole, cb);
|
async.series(insertRootRole, cb);
|
||||||
} else {
|
} else {
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.down = function(db, cb) {
|
exports.down = function(db, cb) {
|
||||||
|
Loading…
Reference in New Issue
Block a user