1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00
unleash.unleash/src/migrations/20220425090847-add-token-permission.js
olav d0724afdf5
feat: add READ_API_TOKEN permission (#1528)
* refactor: extract accessibleTokens fn

* feat: add READ_API_TOKEN permission
2022-04-26 10:24:34 +02:00

39 lines
1.2 KiB
JavaScript

'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,
);
};