Skip to content

Commit

Permalink
Merge pull request #425 from rexxars/expand-acl-groups
Browse files Browse the repository at this point in the history
Add `expandGroups` option to ACL rules endpoint
  • Loading branch information
rexxars committed Dec 15, 2015
2 parents c44391e + 4d1fdbf commit a3a42ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions library/Imbo/Resource/AccessRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ public function getRules(EventInterface $event) {

$accessList = $accessControl->getAccessListForPublicKey($publicKey);

if ($request->query->has('expandGroups')) {
foreach ($accessList as &$rule) {
if (!isset($rule['group'])) {
continue;
}

$rule['resources'] = $accessControl->getGroup($rule['group']);
}
}

$model = new AccessRulesModel();
$model->setData($accessList);

Expand Down
15 changes: 15 additions & 0 deletions tests/behat/features/access-control-keys.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ Feature: Imbo provides a keys endpoint
| json | application/json | #^\[{"id":".*?","group":"user-stats","users":"\*"}\]$# |
| xml | application/xml | #^<\?xml version="1\.0" encoding="UTF-8"\?>\s*<imbo>\s*<access>\s*<rule id=".*?">\s*<group>user-stats</group>\s*<users>\s*<user>\*</user>\s*</users>\s*</rule>\s*</access>\s*</imbo>$#ms |

Scenario Outline: Fetch access control rules with expanded groups
Given I use "master-pubkey" and "master-privkey" for public and private keys
And I include an access token in the query
When I request "/keys/group-based/access.<extension>?expandGroups=1"
Then I should get a response with "200 OK"
And the "Content-Type" response header is "<content-type>"
And the response body matches:
"""
<response>
"""
Examples:
| extension | content-type | response |
| json | application/json | #^\[{"id":".*?","group":"user-stats","users":\["user1"\],"resources":\["user\.get","user\.head"]}]$# |
| xml | application/xml | #^<\?xml version="1\.0" encoding="UTF-8"\?>\s*<imbo>\s*<access>\s*<rule id=".*?">\s*<resources>\s*<resource>user\.get</resource>\s*<resource>user\.head</resource>\s*</resources>\s*<group>user-stats</group>\s*<users>\s*<user>user1</user>\s*</users>\s*</rule>\s*</access>\s*</imbo>$#ms |

Scenario: Create a public key
Given I use "master-pubkey" and "master-privkey" for public and private keys
And the request body contains:
Expand Down

0 comments on commit a3a42ca

Please sign in to comment.