Skip to content

Commit

Permalink
Rename hasAccess() to canAccessDeployment() in Authorizers
Browse files Browse the repository at this point in the history
`hasAccess` was confusing and provided little context for when
reading the code. `canAccessDeployment` makes it clear we're
checking auth for the entire deployment. It also now accepts
the user as a parameter so its clear its checking access for
that user.
  • Loading branch information
rjmackay committed Jul 10, 2017
1 parent 2835ae3 commit 10501e8
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Core/Tool/Authorizer/ContactAuthorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function isAllowed(Entity $entity, $privilege)
$user = $this->getUser();

// Only logged in users have access if the deployment is private
if (!$this->hasAccess()) {
if (!$this->canAccessDeployment($user)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Tool/Authorizer/FormAuthorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function isAllowed(Entity $entity, $privilege)
$user = $this->getUser();

// Only logged in users have access if the deployment is private
if (!$this->hasAccess()) {
if (!$this->canAccessDeployment($user)) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Core/Tool/Authorizer/LayerAuthorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public function isAllowed(Entity $entity, $privilege)
$user = $this->getUser();

// Only logged in users have access if the deployment is private
if (!$this->hasAccess()) {
if (!$this->canAccessDeployment($user)) {
return false;
}

// Then we check if a user has the 'admin' role. If they do they're
// allowed access to everything (all entities and all privileges)
if ($this->isUserAdmin($user)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Tool/Authorizer/MediaAuthorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function isAllowed(Entity $entity, $privilege)
$user = $this->getUser();

// Only logged in users have access if the deployment is private
if (!$this->hasAccess()) {
if (!$this->canAccessDeployment($user)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Tool/Authorizer/MessageAuthorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function isAllowed(Entity $entity, $privilege)
$user = $this->getUser();

// Only logged in users have access if the deployment is private
if (!$this->hasAccess()) {
if (!$this->canAccessDeployment($user)) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Core/Tool/Authorizer/NotificationAuthorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class NotificationAuthorizer implements Authorizer

// It uses `PrivateDeployment` to check whether a deployment is private
use PrivateDeployment;


/* Authorizer */
public function isAllowed(Entity $entity, $privilege)
Expand All @@ -44,15 +44,15 @@ public function isAllowed(Entity $entity, $privilege)
$user = $this->getUser();

// Only logged in users have access if the deployment is private
if (!$this->hasAccess()) {
if (!$this->canAccessDeployment($user)) {
return false;
}

// Admin is allowed access to everything
if ($this->isUserAdmin($user)) {
return true;
}

// Allow create, read, update and delete if owner.
if ($this->isUserOwner($entity, $user)
and in_array($privilege, ['create', 'read', 'update', 'delete'])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Tool/Authorizer/PostAuthorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function isAllowed(Entity $entity, $privilege)
$user = $this->getUser();

// Only logged in users have access if the deployment is private
if (!$this->hasAccess()) {
if (!$this->canAccessDeployment($user)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Tool/Authorizer/SetAuthorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function isAllowed(Entity $entity, $privilege)
$user = $this->getUser();

// Only logged in users have access if the deployment is private
if (!$this->hasAccess()) {
if (!$this->canAccessDeployment($user)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Tool/Authorizer/TagAuthorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function isAllowed(Entity $entity, $privilege)
$user = $this->getUser();

// Only logged in users have access if the deployment is private
if (!$this->hasAccess()) {
if (!$this->canAccessDeployment($user)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Tool/Authorizer/UserAuthorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function isAllowed(Entity $entity, $privilege)
$user = $this->getUser();

// Only logged in users have access if the deployment is private
if (!$this->hasAccess()) {
if (!$this->canAccessDeployment($user)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Tool/Authorizer/WebhookAuthorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function isAllowed(Entity $entity, $privilege)
$user = $this->getUser();

// Only logged in users have access if the deployment is private
if (!$this->hasAccess()) {
if (!$this->canAccessDeployment($user)) {
return false;
}

Expand Down
6 changes: 4 additions & 2 deletions src/Core/Traits/PrivateDeployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Ushahidi\Core\Traits;

use Ushahidi\Core\Entity\User;

trait PrivateDeployment
{
protected $private;
Expand All @@ -35,10 +37,10 @@ public function isPrivate()
* Check if user can access deployment
* @return boolean
*/
public function hasAccess()
public function canAccessDeployment(User $user)
{
// Only logged in users have access if the deployment is private
if ($this->isPrivate() and !$this->getUserId()) {
if ($this->isPrivate() and !$this->user->id) {
return false;
}

Expand Down

0 comments on commit 10501e8

Please sign in to comment.