Skip to content

Commit

Permalink
Merge pull request #968 from ushahidi/954-duplicate-notifications
Browse files Browse the repository at this point in the history
Use user param to filter notifications and contacts
  • Loading branch information
rjmackay committed Mar 4, 2016
2 parents 7e62949 + 8c02bd6 commit d36f44e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
9 changes: 5 additions & 4 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 Down Expand Up @@ -63,8 +63,9 @@ protected function setSearchConditions(SearchData $search)
$user = $this->getUser();

// Limit search to user's records unless they are admin
if (! $this->isUserAdmin($user)) {
$search->user = $user->getId();
// or if we get user=me as a search param
if (! $this->isUserAdmin($user) || $search->user === 'me') {
$search->user = $this->getUserId();
}

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

$state = [
'created' => time(),
];
Expand Down
7 changes: 4 additions & 3 deletions application/classes/Ushahidi/Repository/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ 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();
// or if we get user=me as a search param
if (! $this->isUserAdmin($user) || $search->user === 'me') {
$search->user = $this->getUserId();
}

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

0 comments on commit d36f44e

Please sign in to comment.