add "duration + fixed start time" tracking mode (#859)
This commit is contained in:
@@ -11,6 +11,7 @@ namespace App\Validator\Constraints;
|
||||
|
||||
use App\Configuration\TimesheetConfiguration;
|
||||
use App\Entity\Timesheet as TimesheetEntity;
|
||||
use App\Timesheet\TrackingModeService;
|
||||
use App\Validator\Constraints\Timesheet as TimesheetConstraint;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
@@ -28,15 +29,20 @@ class TimesheetValidator extends ConstraintValidator
|
||||
* @var TimesheetConfiguration
|
||||
*/
|
||||
protected $configuration;
|
||||
/**
|
||||
* @var TrackingModeService
|
||||
*/
|
||||
protected $trackingModeService;
|
||||
|
||||
/**
|
||||
* @param AuthorizationCheckerInterface $auth
|
||||
* @param TimesheetConfiguration $configuration
|
||||
*/
|
||||
public function __construct(AuthorizationCheckerInterface $auth, TimesheetConfiguration $configuration)
|
||||
public function __construct(AuthorizationCheckerInterface $auth, TimesheetConfiguration $configuration, TrackingModeService $service)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->configuration = $configuration;
|
||||
$this->trackingModeService = $service;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,9 +74,16 @@ class TimesheetValidator extends ConstraintValidator
|
||||
// an entry is edited and the end date is removed (or duration deleted) would restart the record,
|
||||
// which might be disallowed for the current user
|
||||
if ($context->getViolations()->count() == 0 && null === $timesheet->getEnd()) {
|
||||
$mode = $this->trackingModeService->getActiveMode();
|
||||
$path = 'start';
|
||||
if ($mode->canEditEnd()) {
|
||||
$path = 'end';
|
||||
} elseif ($mode->canEditDuration()) {
|
||||
$path = 'duration';
|
||||
}
|
||||
if (!$this->auth->isGranted('start', $timesheet)) {
|
||||
$context->buildViolation('You are not allowed to start this timesheet record.')
|
||||
->atPath($this->configuration->isDurationOnly() ? 'duration' : 'end')
|
||||
->atPath($path)
|
||||
->setTranslationDomain('validators')
|
||||
->setCode(TimesheetConstraint::START_DISALLOWED)
|
||||
->addViolation();
|
||||
|
||||
Reference in New Issue
Block a user