1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00
unleash.unleash/src/migrations/20220425090847-add-token-permission.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

'use strict';
exports.up = function (db, cb) {
db.runSql(
`
INSERT INTO permissions (permission, display_name, type) VALUES
('READ_API_TOKEN', 'Read API token', 'root');
INSERT INTO role_permission (role_id, permission_id)
SELECT
r.id AS role_id,
p.id AS permission_id
FROM roles r
JOIN permissions p ON p.permission = 'READ_API_TOKEN'
WHERE r.name IN ('Admin', 'Editor');
UPDATE roles SET description = 'Users with this role can only read root resources in Unleash. The viewer can be added to specific projects as project member. Viewers may not view API tokens.'
WHERE name = 'Viewer'
`,
cb,
);
};
exports.down = function (db, cb) {
db.runSql(
`
DELETE FROM role_permission WHERE permission_id = (
SELECT id FROM permissions WHERE permission = 'READ_API_TOKEN'
);
DELETE FROM permissions WHERE permission = 'READ_API_TOKEN';
UPDATE roles SET description = 'Users with this role can only read root resources in Unleash. The viewer can be added to specific projects as project member.'
WHERE name = 'Viewer'
`,
cb,
);
};