Skip to content

Commit adcddc9

Browse files
author
Tom Kirkpatrick
committed
Fix handling for accessing the Group Model directly
1 parent 29e5916 commit adcddc9

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

lib/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ module.exports = class AccessUtils {
332332
debug('getCurrentGroupId context.remotingContext.args: %o', context.remotingContext.args);
333333
let groupId = null;
334334

335+
// If we are accessing the group model directly, the group id is the model id.
336+
if (this.isGroupModel(context.model)) {
337+
process.nextTick(() => cb(null, context.modelId));
338+
return cb.promise;
339+
}
340+
335341
// If we are accessing an existing model, get the store id from the existing model instance.
336342
// TODO: Cache this result so that it can be reused across each ACL lookup attempt.
337343
if (context.modelId) {

test/fixtures/simple-app/common/models/store.json

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,41 @@
4545
{
4646
"accessType": "READ",
4747
"principalType": "ROLE",
48-
"principalId": "admin",
49-
"permission": "ALLOW",
50-
"property": "find"
48+
"principalId": "$group:member",
49+
"permission": "ALLOW"
5150
},
5251
{
5352
"accessType": "READ",
5453
"principalType": "ROLE",
55-
"principalId": "$group:member",
54+
"principalId": "$group:manager",
55+
"permission": "ALLOW"
56+
},
57+
{
58+
"accessType": "WRITE",
59+
"principalType": "ROLE",
60+
"principalId": "$group:manager",
5661
"permission": "ALLOW",
57-
"property": "findById"
62+
"property": "create"
5863
},
5964
{
60-
"accessType": "EXECUTE",
65+
"accessType": "WRITE",
6166
"principalType": "ROLE",
62-
"principalId": "$authenticated",
67+
"principalId": "$group:manager",
6368
"permission": "ALLOW",
64-
"property": "addUser"
69+
"property": "updateAttributes"
6570
},
6671
{
67-
"accessType": "EXECUTE",
72+
"accessType": "WRITE",
6873
"principalType": "ROLE",
69-
"principalId": "$authenticated",
74+
"principalId": "$group:manager",
7075
"permission": "ALLOW",
71-
"property": "removeUser"
76+
"property": "upsert"
77+
},
78+
{
79+
"accessType": "*",
80+
"principalType": "ROLE",
81+
"principalId": "$group:admin",
82+
"permission": "ALLOW"
7283
}
7384
],
7485
"methods": {}

test/rest-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@ describe('REST API', function() {
6464

6565
users.forEach(user => {
6666
describe(`${user.username} (User with ${user.abilities.join(', ')} permissions):`, function() {
67+
// related group content
68+
describe('group model', function() {
69+
if (_includes(user.abilities, 'read')) {
70+
it('should get a teams store', function() {
71+
return logInAs(user.username)
72+
.then(res => json('get', `/api/stores/A?access_token=${res.body.id}`)
73+
.expect(200))
74+
.then(res => {
75+
expect(res.body).to.be.an('object');
76+
expect(res.body).to.have.property('name', 'Store A');
77+
});
78+
});
79+
}
80+
it('should not get another teams store', function() {
81+
return logInAs(user.username)
82+
.then(res => json('get', `/api/stores/B?access_token=${res.body.id}`)
83+
.expect(401));
84+
});
85+
});
86+
6787
// related group content
6888
describe('related group content', function() {
6989
if (_includes(user.abilities, 'read')) {

0 commit comments

Comments
 (0)