added team permissions for activities (#1872)

This commit is contained in:
Kevin Papst
2020-08-08 18:50:04 +02:00
committed by GitHub
parent dc162bf385
commit 0914ebf737
84 changed files with 4300 additions and 3279 deletions

View File

@@ -19,19 +19,15 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
*/
class ActivityVoter extends AbstractVoter
{
public const VIEW = 'view';
public const EDIT = 'edit';
public const BUDGET = 'budget';
public const DELETE = 'delete';
/**
* support rules based on the given $subject (here: Activity)
* support rules based on the given activity
*/
public const ALLOWED_ATTRIBUTES = [
self::VIEW,
self::EDIT,
self::BUDGET,
self::DELETE,
'view',
'edit',
'budget',
'delete',
'permissions',
];
/**
@@ -70,8 +66,8 @@ class ActivityVoter extends AbstractVoter
return true;
}
// new and global activities have no project
if (null === ($project = $subject->getProject())) {
// those cannot be assigned to teams
if (\in_array($attribute, ['create', 'delete'])) {
return false;
}
@@ -82,6 +78,22 @@ class ActivityVoter extends AbstractVoter
return false;
}
/** @var Team $team */
foreach ($subject->getTeams() as $team) {
if ($hasTeamleadPermission && $user->isTeamleadOf($team)) {
return true;
}
if ($hasTeamPermission && $user->isInTeam($team)) {
return true;
}
}
// new and global activities have no project
if (null === ($project = $subject->getProject())) {
return false;
}
/** @var Team $team */
foreach ($project->getTeams() as $team) {
if ($hasTeamleadPermission && $user->isTeamleadOf($team)) {