Skip to content

Commit

Permalink
Pass user to the pulgin
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdryden committed Nov 4, 2022
1 parent c69012b commit 789f33e
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Mvc/Controller/Plugin/TeamAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Doctrine\ORM\EntityManager;
use InvalidArgumentException;
use Laminas\Mvc\Controller\Plugin\AbstractPlugin;
use \Omeka\Entity\User;

/**
* Controller plugin for authorize the current user.
Expand All @@ -18,32 +19,34 @@ class TeamAuth extends AbstractPlugin
*/
protected $entityManager;

/**
* @var \Omeka\Entity\User
*/
protected $user;

/**
* Construct the plugin.
*
* @param EntityManager $entityManager
*/
public function __construct(EntityManager $entityManager)
public function __construct(EntityManager $entityManager, User $user)
{
$this->entityManager = $entityManager;
$this->user = $user;
}

public function user()
{
return $this->getController()->identity();
}

public function isGlobAdmin()
{
return $this->user()->getRole() === 'global_admin';
return $this->user->getRole() === 'global_admin';
}

public function isSuper()
{
return ($this->isGlobAdmin() && $this->user()->getId() === 1);
return ($this->isGlobAdmin() && $this->user->getId() === 1);
}

public function teamAuthorized(string $action, string $domain)
public function teamAuthorized(string $action, string $domain, int $context=0): bool
{
//validate inputs
if (!in_array($action, $this->actions)) {
Expand All @@ -69,7 +72,7 @@ public function teamAuthorized(string $action, string $domain)
}

$em = $this->entityManager;
$user_id = $this->user()->getId();
$user_id = $this->user->getId();
$authorized = false;


Expand Down

0 comments on commit 789f33e

Please sign in to comment.