0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Added email resource permission

This commit is contained in:
Nazar Gargol 2019-11-06 14:55:53 +07:00 committed by Naz Gargol
parent 0e822b4d54
commit 6bc8a1bb18
4 changed files with 75 additions and 14 deletions

View file

@ -0,0 +1,51 @@
const _ = require('lodash');
const utils = require('../../../schema/fixtures/utils');
const permissions = require('../../../../services/permissions');
const logging = require('../../../../lib/common/logging');
const resources = ['emails'];
const _private = {};
_private.getPermissions = function getPermissions(resource) {
return utils.findModelFixtures('Permission', {object_type: resource});
};
_private.printResult = function printResult(result, message) {
if (result.done === result.expected) {
logging.info(message);
} else {
logging.warn(`(${result.done}/${result.expected}) ${message}`);
}
};
module.exports.config = {
transaction: true
};
module.exports.up = (options) => {
const localOptions = _.merge({
context: {internal: true}
}, options);
return Promise.map(resources, (resource) => {
const modelToAdd = _private.getPermissions(resource);
return utils.addFixturesForModel(modelToAdd, localOptions)
.then(result => _private.printResult(result, `Adding permissions fixtures for ${resource}s`))
.then(() => permissions.init(localOptions));
});
};
module.exports.down = (options) => {
const localOptions = _.merge({
context: {internal: true}
}, options);
return Promise.map(resources, (resource) => {
const modelToRemove = _private.getPermissions(resource);
// permission model automatically cleans up permissions_roles on .destroy()
return utils.removeFixturesForModel(modelToRemove, localOptions)
.then(result => _private.printResult(result, `Removing permissions fixtures for ${resource}s`));
});
};

View file

@ -372,6 +372,11 @@
"name": "Send test email",
"action_type": "sendTestEmail",
"object_type": "email_preview"
},
{
"name": "Email",
"action_type": "read",
"object_type": "email"
}
]
},
@ -567,7 +572,8 @@
"api_key": "all",
"action": "all",
"member": "all",
"email_preview": "all"
"email_preview": "all",
"email": "all"
},
"DB Backup Integration": {
"db": "all"
@ -590,7 +596,8 @@
"webhook": "all",
"action": "all",
"member": "all",
"email_preview": "all"
"email_preview": "all",
"email": "all"
},
"Editor": {
"notification": "all",
@ -602,7 +609,8 @@
"role": "all",
"invite": "all",
"theme": ["browse"],
"email_preview": "all"
"email_preview": "all",
"email": "all"
},
"Author": {
"post": ["browse", "read", "add"],
@ -612,7 +620,8 @@
"user": ["browse", "read"],
"role": ["browse"],
"theme": ["browse"],
"email_preview": "read"
"email_preview": "read",
"email": "read"
},
"Contributor": {
"post": ["browse", "read", "add"],
@ -622,7 +631,8 @@
"user": ["browse", "read"],
"role": ["browse"],
"theme": ["browse"],
"email_preview": "read"
"email_preview": "read",
"email": "read"
}
}
},

View file

@ -150,19 +150,19 @@ describe('Migration Fixture Utils', function () {
fixtureUtils.addFixturesForRelation(fixtures.relations[0]).then(function (result) {
should.exist(result);
result.should.be.an.Object();
result.should.have.property('expected', 61);
result.should.have.property('done', 61);
result.should.have.property('expected', 66);
result.should.have.property('done', 66);
// Permissions & Roles
permsAllStub.calledOnce.should.be.true();
rolesAllStub.calledOnce.should.be.true();
dataMethodStub.filter.callCount.should.eql(61);
dataMethodStub.filter.callCount.should.eql(66);
dataMethodStub.find.callCount.should.eql(7);
baseUtilAttachStub.callCount.should.eql(61);
baseUtilAttachStub.callCount.should.eql(66);
fromItem.related.callCount.should.eql(61);
fromItem.findWhere.callCount.should.eql(61);
toItem[0].get.callCount.should.eql(122);
fromItem.related.callCount.should.eql(66);
fromItem.findWhere.callCount.should.eql(66);
toItem[0].get.callCount.should.eql(132);
done();
}).catch(done);

View file

@ -19,8 +19,8 @@ var should = require('should'),
*/
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = 'ee3406c46cb779fa73c5c86a4e676973';
const currentFixturesHash = '84005b6e8f62231b6fd0fc261ce893db';
const currentSchemaHash = '986b3a9c8a5c00e5230f8bfb1133006a';
const currentFixturesHash = '7462de0f3d5879c328161e0c98039aec';
// If this test is failing, then it is likely a change has been made that requires a DB version bump,
// and the values above will need updating as confirmation