added domain logic for permission checks (#1803)

This commit is contained in:
Kevin Papst
2020-07-04 13:29:03 +02:00
committed by GitHub
parent 091740f407
commit 682681afa5
16 changed files with 39 additions and 14 deletions

View File

@@ -150,7 +150,6 @@ class Activity implements EntityWithMetaFields
}
/**
* @internal only here for symfony forms
* @return Collection|MetaTableTypeInterface[]
*/
public function getMetaFields(): Collection

View File

@@ -393,7 +393,6 @@ class Customer implements EntityWithMetaFields
}
/**
* @internal only here for symfony forms
* @return Collection|MetaTableTypeInterface[]
*/
public function getMetaFields(): Collection

View File

@@ -14,7 +14,6 @@ use Doctrine\Common\Collections\Collection;
interface EntityWithMetaFields
{
/**
* @internal only here for symfony forms
* @return Collection|MetaTableTypeInterface[]
*/
public function getMetaFields(): Collection;

View File

@@ -298,7 +298,6 @@ class Project implements EntityWithMetaFields
}
/**
* @internal only here for symfony forms
* @return Collection|MetaTableTypeInterface[]
*/
public function getMetaFields(): Collection

View File

@@ -509,7 +509,6 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
}
/**
* @internal only here for symfony forms
* @return Collection|MetaTableTypeInterface[]
*/
public function getMetaFields(): Collection

View File

@@ -354,6 +354,11 @@ class User extends BaseUser implements UserInterface
$team->removeUser($this);
}
public function hasTeamAssignment(): bool
{
return !$this->getTeams()->isEmpty();
}
/**
* @return Collection<Team>
*/
@@ -372,6 +377,11 @@ class User extends BaseUser implements UserInterface
return $team->getTeamLead() === $this;
}
public function canSeeAllData(): bool
{
return $this->isSuperAdmin() || $this->isAdmin();
}
public function isTeamlead(): bool
{
return $this->hasRole(static::ROLE_TEAMLEAD);

View File

@@ -31,7 +31,7 @@ class AjaxAuthenticationSubscriber implements EventSubscriberInterface
$request = $event->getRequest();
if ($request->isXmlHttpRequest()) {
$exception = $event->getException();
$exception = $event->getThrowable();
if ($exception instanceof AuthenticationExpiredException) {
$event->setResponse(new Response('Session expired', 403, ['Login-Required' => true]));
} elseif ($exception instanceof AuthenticationException) {

View File

@@ -45,7 +45,7 @@ class TeamMemberType extends AbstractType
/** @var User $user */
$user = $options['user'];
if (null !== $user && !$user->getTeams()->isEmpty() && !$user->isSuperAdmin() && !$user->isAdmin()) {
if (null !== $user && $user->hasTeamAssignment() && !$user->canSeeAllData()) {
$qb
->leftJoin('u.teams', 'teams')
->leftJoin('teams.users', 'users')

View File

@@ -122,7 +122,7 @@ class ActivityRepository extends EntityRepository
}
// make sure that admins see all activities
if (null !== $user && ($user->isSuperAdmin() || $user->isAdmin())) {
if (null !== $user && $user->canSeeAllData()) {
return;
}

View File

@@ -139,7 +139,7 @@ class CustomerRepository extends EntityRepository
}
// make sure that admins see all customers
if (null !== $user && ($user->isSuperAdmin() || $user->isAdmin())) {
if (null !== $user && $user->canSeeAllData()) {
return;
}

View File

@@ -92,7 +92,7 @@ class InvoiceRepository extends EntityRepository
}
// make sure that admins see all projects
if (null !== $user && ($user->isSuperAdmin() || $user->isAdmin())) {
if (null !== $user && $user->canSeeAllData()) {
return;
}

View File

@@ -131,7 +131,7 @@ class ProjectRepository extends EntityRepository
}
// make sure that admins see all projects
if (null !== $user && ($user->isSuperAdmin() || $user->isAdmin())) {
if (null !== $user && $user->canSeeAllData()) {
return;
}

View File

@@ -174,7 +174,7 @@ class TeamRepository extends EntityRepository
}
// make sure that admins see all user
if (null !== $user && ($user->isSuperAdmin() || $user->isAdmin())) {
if (null !== $user && $user->canSeeAllData()) {
return;
}

View File

@@ -549,7 +549,7 @@ class TimesheetRepository extends EntityRepository
}
// make sure that admins see all timesheet records
if (null !== $user && ($user->isSuperAdmin() || $user->isAdmin())) {
if (null !== $user && $user->canSeeAllData()) {
return;
}

View File

@@ -159,7 +159,7 @@ class UserRepository extends EntityRepository implements UserLoaderInterface
}
// make sure that admins see all user
if (null !== $user && ($user->isSuperAdmin() || $user->isAdmin())) {
if (null !== $user && $user->canSeeAllData()) {
return;
}