Skip to content

Commit

Permalink
Fix handling for accessing the Group Model directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Kirkpatrick committed Feb 4, 2016
1 parent 29e5916 commit adcddc9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
6 changes: 6 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ module.exports = class AccessUtils {
debug('getCurrentGroupId context.remotingContext.args: %o', context.remotingContext.args);
let groupId = null;

// If we are accessing the group model directly, the group id is the model id.
if (this.isGroupModel(context.model)) {
process.nextTick(() => cb(null, context.modelId));
return cb.promise;
}

// If we are accessing an existing model, get the store id from the existing model instance.
// TODO: Cache this result so that it can be reused across each ACL lookup attempt.
if (context.modelId) {
Expand Down
33 changes: 22 additions & 11 deletions test/fixtures/simple-app/common/models/store.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,41 @@
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "find"
"principalId": "$group:member",
"permission": "ALLOW"
},
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$group:member",
"principalId": "$group:manager",
"permission": "ALLOW"
},
{
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "$group:manager",
"permission": "ALLOW",
"property": "findById"
"property": "create"
},
{
"accessType": "EXECUTE",
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "$authenticated",
"principalId": "$group:manager",
"permission": "ALLOW",
"property": "addUser"
"property": "updateAttributes"
},
{
"accessType": "EXECUTE",
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "$authenticated",
"principalId": "$group:manager",
"permission": "ALLOW",
"property": "removeUser"
"property": "upsert"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$group:admin",
"permission": "ALLOW"
}
],
"methods": {}
Expand Down
20 changes: 20 additions & 0 deletions test/rest-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ describe('REST API', function() {

users.forEach(user => {
describe(`${user.username} (User with ${user.abilities.join(', ')} permissions):`, function() {
// related group content
describe('group model', function() {
if (_includes(user.abilities, 'read')) {
it('should get a teams store', function() {
return logInAs(user.username)
.then(res => json('get', `/api/stores/A?access_token=${res.body.id}`)
.expect(200))
.then(res => {
expect(res.body).to.be.an('object');
expect(res.body).to.have.property('name', 'Store A');
});
});
}
it('should not get another teams store', function() {
return logInAs(user.username)
.then(res => json('get', `/api/stores/B?access_token=${res.body.id}`)
.expect(401));
});
});

// related group content
describe('related group content', function() {
if (_includes(user.abilities, 'read')) {
Expand Down

0 comments on commit adcddc9

Please sign in to comment.