mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Added migration for read:identity permission
no-issue This ensures that the permission always exists in version 3.12
This commit is contained in:
parent
d246a4761e
commit
6f6e5e2a3a
1 changed files with 56 additions and 0 deletions
|
@ -0,0 +1,56 @@
|
|||
const ObjectId = require('bson-objectid');
|
||||
const common = require('../../../../lib/common');
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
||||
|
||||
module.exports.up = async (options) => {
|
||||
const connection = options.transacting;
|
||||
|
||||
const existingIdentityPermission = await connection('permissions').where({
|
||||
action_type: 'read',
|
||||
object_type: 'identity'
|
||||
}).first();
|
||||
|
||||
if (existingIdentityPermission) {
|
||||
common.logging.warn('Permission for read:identity already added');
|
||||
return;
|
||||
}
|
||||
|
||||
common.logging.info('Adding permission for read:identity');
|
||||
|
||||
const date = connection.raw('CURRENT_TIMESTAMP');
|
||||
|
||||
await connection('permissions').insert({
|
||||
id: ObjectId.generate(),
|
||||
name: 'Read identities',
|
||||
action_type: 'read',
|
||||
object_type: 'identity',
|
||||
created_at: date,
|
||||
created_by: 1,
|
||||
updated_at: date,
|
||||
updated_by: 1
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.down = async (options) => {
|
||||
const connection = options.transacting;
|
||||
|
||||
const existingIdentityPermission = await connection('permissions').where({
|
||||
action_type: 'read',
|
||||
object_type: 'identity'
|
||||
}).first();
|
||||
|
||||
if (!existingIdentityPermission) {
|
||||
common.logging.warn('Permission for read:identity already removed');
|
||||
return;
|
||||
}
|
||||
|
||||
common.logging.info('Removing permission for read:identity');
|
||||
|
||||
await connection('permissions').where({
|
||||
action_type: 'read',
|
||||
object_type: 'identity'
|
||||
}).del();
|
||||
};
|
Loading…
Add table
Reference in a new issue