-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow anonymous access to Users API but exclude details
Summary: - Restore allowed_methods to post and layers API - Use CRUD privs not REST methods for for allowed* response - Allow read access to all users, but strip most details in formatter Test Plan: - bin/behat - Check API responses in browser console - allow_privileges should now get returned for posts - Should see read/create/update/delete, instead of REST verbs - Access users api with client creds should see only username and realname Reviewers: vladimir, aMoniker Reviewed By: aMoniker Differential Revision: https://phabricator.ushahidi.com/D666
- Loading branch information
Showing
9 changed files
with
80 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,48 @@ Feature: Testing the Users API | |
Then the response is JSON | ||
And the response has a "id" property | ||
And the type of the "id" property is "numeric" | ||
And the "username" property equals "robbie" | ||
Then the guzzle status code should be 200 | ||
|
||
Scenario: Finding a User as admin gives full details | ||
Given that I want to find a "User" | ||
And that its "id" is "3" | ||
And that the request "Authorization" header is "Bearer defaulttoken" | ||
When I request "/users" | ||
Then the response is JSON | ||
And the response has a "id" property | ||
And the type of the "id" property is "numeric" | ||
And the "username" property equals "test" | ||
And the "email" property equals "[email protected]" | ||
Then the guzzle status code should be 200 | ||
|
||
Scenario: Loading own user gives full details | ||
Given that I want to find a "User" | ||
And that its "id" is "me" | ||
And that the request "Authorization" header is "Bearer testbasicuser" | ||
When I request "/users" | ||
Then the response is JSON | ||
And the response has a "id" property | ||
And the type of the "id" property is "numeric" | ||
And the "username" property equals "robbie" | ||
And the "email" property equals "[email protected]" | ||
Then the guzzle status code should be 200 | ||
|
||
Scenario: Finding a User as anonymous user gives partial details | ||
Given that I want to find a "User" | ||
And that its "id" is "1" | ||
And that the request "Authorization" header is "Bearer testanon" | ||
When I request "/users" | ||
Then the response is JSON | ||
And the response has a "id" property | ||
And the type of the "id" property is "numeric" | ||
And the response has a "realname" property | ||
And the response has a "username" property | ||
And the response does not have a "email" property | ||
And the response does not have a "logins" property | ||
And the response does not have a "failed_attempts" property | ||
And the response does not have a "last_login" property | ||
And the response does not have a "last_attempt" property | ||
Then the guzzle status code should be 200 | ||
|
||
Scenario: Finding a non-existent user | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
/** | ||
* Ushahidi Formatter + Authorizer Trait | ||
* | ||
* Injects "allowed_methods" into formatted data using an Authorizer. | ||
* Injects "allowed_privileges" into formatted data using an Authorizer. | ||
* | ||
* @author Ushahidi Team <[email protected]> | ||
* @package Ushahidi\Platform | ||
|
@@ -26,7 +26,7 @@ public function setAuth(Authorizer $auth) | |
return $this; | ||
} | ||
|
||
protected function getAllowedMethods(Entity $entity) | ||
protected function getAllowedPrivs(Entity $entity) | ||
{ | ||
if (!$this->auth) { | ||
throw new \LogicException('Authorizer must be defined by calling setAuth'); | ||
|
@@ -39,7 +39,7 @@ protected function getAllowedMethods(Entity $entity) | |
protected function add_metadata(Array $data, Entity $entity) | ||
{ | ||
return $data + [ | ||
'allowed_methods' => $this->getAllowedMethods($entity), | ||
'allowed_privileges' => $this->getAllowedPrivs($entity), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters