mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-01 23:37:43 +03:00
Added migrations for backupContent permission
no-issue
This commit is contained in:
parent
f31e535041
commit
42c9904a8f
@ -0,0 +1,61 @@
|
||||
const logging = require('../../../../lib/common/logging');
|
||||
const models = require('../../../../models');
|
||||
const utils = require('../../../schema/fixtures/utils');
|
||||
|
||||
const fixtureBackupContentPerm = utils.findModelFixtureEntry('Permission', {
|
||||
object_type: 'db',
|
||||
action_type: 'backupContent'
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
config: {
|
||||
transaction: true
|
||||
},
|
||||
|
||||
async up(options) {
|
||||
try {
|
||||
const existingBackupContentPerm = await models.Permission.findOne(
|
||||
fixtureBackupContentPerm,
|
||||
options
|
||||
);
|
||||
|
||||
if (existingBackupContentPerm) {
|
||||
return logging.warn('Issue adding db.backupContent (already exists)');
|
||||
}
|
||||
|
||||
const result = await utils.addFixturesForModel({
|
||||
name: 'Permission',
|
||||
entries: [fixtureBackupContentPerm]
|
||||
}, options);
|
||||
|
||||
const success = result.done === result.expected;
|
||||
|
||||
if (!success) {
|
||||
return logging.warn('Issue adding db.backupContent permission (did not insert)');
|
||||
}
|
||||
|
||||
return logging.info('Completed adding db.backupContent permission');
|
||||
} catch (err) {
|
||||
return logging.error('Errored when adding db.backupContent permission');
|
||||
}
|
||||
},
|
||||
|
||||
async down(options) {
|
||||
try {
|
||||
const existingBackupContentPerm = await models.Permission.findOne(
|
||||
fixtureBackupContentPerm,
|
||||
options
|
||||
);
|
||||
|
||||
if (!existingBackupContentPerm) {
|
||||
return logging.warn('Issue removing db.backupContent (already removed)');
|
||||
}
|
||||
|
||||
await existingBackupContentPerm.destroy(options);
|
||||
|
||||
return logging.info('Completed removing db.backupContent permission');
|
||||
} catch (err) {
|
||||
return logging.error('Errored when removing db.backupContent permission');
|
||||
}
|
||||
}
|
||||
};
|
@ -0,0 +1,46 @@
|
||||
const logging = require('../../../../lib/common/logging');
|
||||
const utils = require('../../../schema/fixtures/utils');
|
||||
|
||||
const relationFixtures = {
|
||||
from: {
|
||||
model: 'Role',
|
||||
match: 'name',
|
||||
relation: 'permissions'
|
||||
},
|
||||
to: {
|
||||
model: 'Permission',
|
||||
match: ['object_type', 'action_type']
|
||||
},
|
||||
entries: {
|
||||
Administrator: {
|
||||
db: 'backupContent'
|
||||
},
|
||||
'DB Backup Integration': {
|
||||
db: 'backupContent'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
config: {
|
||||
transaction: true
|
||||
},
|
||||
|
||||
async up(options) {
|
||||
try {
|
||||
await utils.addFixturesForRelation(relationFixtures, options);
|
||||
return logging.info('Completed adding db.backupContent permission to roles');
|
||||
} catch (err) {
|
||||
return logging.warn('Issue adding db.backupContent permission to roles');
|
||||
}
|
||||
},
|
||||
|
||||
async down(options) {
|
||||
try {
|
||||
await utils.removeFixturesForRelation(relationFixtures, options);
|
||||
return logging.info('Completed removing db.backupContent permission from roles');
|
||||
} catch (err) {
|
||||
return logging.warn('Issue removing db.backupContent permission from roles');
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user