0
Fork 0
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:
Fabien O'Carroll 2020-03-12 14:21:46 +02:00
parent d246a4761e
commit 6f6e5e2a3a

View file

@ -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();
};