Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use user param to filter notifications and contacts #968

Merged
merged 2 commits into from
Mar 4, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions application/classes/Ushahidi/Repository/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function getId(Entity $entity)
->execute($this->db);
return $result->get('id', 0);
}

// Ushahidi_Repository
protected function getTable()
{
Expand All @@ -60,11 +60,10 @@ protected function setSearchConditions(SearchData $search)
{
$query = $this->search_query;

$user = $this->getUser();

// Limit search to user's records unless they are admin
if (! $this->isUserAdmin($user)) {
$search->user = $user->getId();
// Replace 'me' with the user id
if ($search->user === 'me')
{
$search->user = $this->getUserId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be removing this. Though maybe we should update it to check a permission as well as isUserAdmin()

}

foreach ([
Expand Down Expand Up @@ -101,7 +100,7 @@ public function create(Entity $entity)
// Instead return the id of the contact that exists
return $id;
}

$state = [
'created' => time(),
];
Expand Down
9 changes: 4 additions & 5 deletions application/classes/Ushahidi/Repository/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ protected function getTable()
public function setSearchConditions(SearchData $search)
{
$query = $this->search_query;

$user = $this->getUser();

// Limit search to user's records unless they are admin
if (! $this->isUserAdmin($user)) {
$search->user = $user->getId();
// Replace 'me' with the user id
if ($search->user === 'me')
{
$search->user = $this->getUserId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be removing this. Though maybe we should update it to check a permission as well as isUserAdmin()

}

foreach ([
Expand Down
5 changes: 5 additions & 0 deletions application/tests/features/api.contacts.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@contacts
Feature: Testing the Contacts API
Scenario: Add a contact
Given that I want to make a new "Contact"
Expand Down Expand Up @@ -56,6 +57,10 @@ Feature: Testing the Contacts API
Scenario: Listing Contacts for a user
Given that I want to get all "Contacts"
And that the request "Authorization" header is "Bearer testbasicuser"
And that the request "query string" is:
"""
user=me
"""
When I request "/contacts"
Then the response is JSON
And the response has a "count" property
Expand Down
5 changes: 5 additions & 0 deletions application/tests/features/api.notifications.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notifications
Feature: Testing the Notifications API

Scenario: Subscribe to a notification
Expand Down Expand Up @@ -42,6 +43,10 @@ Feature: Testing the Notifications API
Scenario: Listing Notifications for a user
Given that I want to get all "Notifications"
And that the request "Authorization" header is "Bearer testbasicuser"
And that the request "query string" is:
"""
user=me
"""
When I request "/notifications"
Then the response is JSON
And the response has a "count" property
Expand Down