prevent duplicate if overlapping records are disabled (#2311)

This commit is contained in:
Kevin Papst
2021-02-06 17:31:14 +01:00
committed by GitHub
parent 8d41fa20bd
commit 9eb25c412e
9 changed files with 2110 additions and 1130 deletions

View File

@@ -495,7 +495,7 @@ class TimesheetRepository extends EntityRepository
// yes, we only want to compare the day, not the time
if ((int) $end->format('Ymd') < (int) $newDateBegin->format('Ymd')) {
break 1;
break;
}
} while ($dateKey !== $dateKeyEnd);
}

View File

@@ -9,6 +9,7 @@
namespace App\Voter;
use App\Configuration\SystemConfiguration;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Security\RolePermissionManager;
@@ -47,6 +48,9 @@ final class TimesheetVoter extends Voter
'duplicate'
];
private $configuration;
private $cacheAllowCopy;
private $permissionManager;
private $lockdownService;
@@ -55,10 +59,11 @@ final class TimesheetVoter extends Voter
private $editExported;
private $now;
public function __construct(RolePermissionManager $permissionManager, LockdownService $lockdownService)
public function __construct(RolePermissionManager $permissionManager, LockdownService $lockdownService, SystemConfiguration $configuration)
{
$this->permissionManager = $permissionManager;
$this->lockdownService = $lockdownService;
$this->configuration = $configuration;
}
/**
@@ -204,6 +209,17 @@ final class TimesheetVoter extends Voter
protected function canDuplicate(User $user, Timesheet $timesheet): bool
{
if ($this->cacheAllowCopy === null) {
$this->cacheAllowCopy = $this->configuration->isTimesheetAllowOverlappingRecords();
}
// This is a quickfix, because the API cannot open dialogs. if the method is copied to the timesheet controller,
// we could open the edit dialog instead of directly saving the copied entry.
// Probably add a new permission is required to differentiate between API and UI.
if (!$this->cacheAllowCopy) {
return false;
}
if (!$this->isAllowedInLockdown($user, $timesheet)) {
return false;
}