Skip to content

Commit

Permalink
Added members permission migrations
Browse files Browse the repository at this point in the history
no issue

- Added new fixtures for member permissions for Admin
  • Loading branch information
rishabhgrg committed Feb 26, 2019
1 parent 20a898a commit d62feca
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const _ = require('lodash');
const utils = require('../../../schema/fixtures/utils');
const permissions = require('../../../../services/permissions');
const common = require('../../../../lib/common');
const resource = 'members';
const _private = {};

_private.getPermissions = function getPermissions() {
return utils.findModelFixtures('Permission', {object_type: resource});
};

_private.getRelations = function getRelations() {
return utils.findPermissionRelationsForObject(resource);
};

_private.printResult = function printResult(result, message) {
if (result.done === result.expected) {
common.logging.info(message);
} else {
common.logging.warn('(' + result.done + '/' + result.expected + ') ' + message);
}
};

module.exports.up = function addMembersPermissions(options) {
const modelToAdd = _private.getPermissions();
const relationToAdd = _private.getRelations();
const localOptions = _.merge({
context: {
internal: true,
migrating: true
}
}, options);

return utils.addFixturesForModel(modelToAdd, localOptions)
.then(function (result) {
_private.printResult(result, 'Adding permissions fixtures for ' + resource + 's');
return utils.addFixturesForRelation(relationToAdd, localOptions);
})
.then(function (result) {
_private.printResult(result, 'Adding permissions_roles fixtures for ' + resource + 's');
return permissions.init(localOptions);
});
};
31 changes: 29 additions & 2 deletions core/server/data/schema/fixtures/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,31 @@
"name": "Browse Actions",
"action_type": "browse",
"object_type": "action"
},
{
"name": "Browse Members",
"action_type": "browse",
"object_type": "member"
},
{
"name": "Read Members",
"action_type": "read",
"object_type": "member"
},
{
"name": "Edit Members",
"action_type": "edit",
"object_type": "member"
},
{
"name": "Add Members",
"action_type": "add",
"object_type": "member"
},
{
"name": "Delete Members",
"action_type": "destroy",
"object_type": "member"
}
]
},
Expand Down Expand Up @@ -577,7 +602,8 @@
"webhook": "all",
"integration": "all",
"api_key": "all",
"action": "all"
"action": "all",
"members": "all"
},
"Admin Integration": {
"mail": "all",
Expand All @@ -594,7 +620,8 @@
"invite": "all",
"redirect": "all",
"webhook": "all",
"action": "all"
"action": "all",
"members": "all"
},
"Editor": {
"post": "all",
Expand Down
9 changes: 8 additions & 1 deletion core/test/regression/migrations/migration_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ describe('Database Migration (special functions)', function () {
// Actions
permissions[64].name.should.eql('Browse Actions');
permissions[64].should.be.AssignedToRoles(['Administrator', 'Admin Integration']);

// Members
permissions[65].name.should.eql('Browse Members');
permissions[66].name.should.eql('Read Members');
permissions[67].name.should.eql('Edit Members');
permissions[68].name.should.eql('Add Members');
permissions[69].name.should.eql('Delete Members');
});

describe('Populate', function () {
Expand Down Expand Up @@ -262,7 +269,7 @@ describe('Database Migration (special functions)', function () {
result.roles.at(5).get('name').should.eql('Admin Integration');

// Permissions
result.permissions.length.should.eql(65);
result.permissions.length.should.eql(70);
result.permissions.toJSON().should.be.CompletePermissions();
});
});
Expand Down
14 changes: 7 additions & 7 deletions core/test/unit/data/schema/fixtures/utils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', 63);
result.should.have.property('done', 63);

// Permissions & Roles
permsAllStub.calledOnce.should.be.true();
rolesAllStub.calledOnce.should.be.true();
dataMethodStub.filter.callCount.should.eql(61);
dataMethodStub.filter.callCount.should.eql(63);
dataMethodStub.find.callCount.should.eql(5);
baseUtilAttachStub.callCount.should.eql(61);
baseUtilAttachStub.callCount.should.eql(63);

fromItem.related.callCount.should.eql(61);
fromItem.findWhere.callCount.should.eql(61);
toItem[0].get.callCount.should.eql(122);
fromItem.related.callCount.should.eql(63);
fromItem.findWhere.callCount.should.eql(63);
toItem[0].get.callCount.should.eql(126);

done();
}).catch(done);
Expand Down
2 changes: 1 addition & 1 deletion core/test/unit/data/schema/integrity_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var should = require('should'),
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = '7c5d34376392d01c274700350de228c1';
const currentFixturesHash = 'db8cd644bc496d0ba34c7f54d7183ee4';
const currentFixturesHash = '42e15796b3c9bdcf0d0ec7eb66a1abf5';

// 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
Expand Down

0 comments on commit d62feca

Please sign in to comment.