forked from TryGhost/Ghost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added migrations for backupContent permission
no-issue
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
core/server/data/migrations/versions/2.28/1-add-db-backup-content-permission.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} | ||
}; |
46 changes: 46 additions & 0 deletions
46
core/server/data/migrations/versions/2.28/2-add-db-backup-content-permission-to-roles.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} | ||
}; |