API begin and end fields for Admins (#5134)
This commit is contained in:
@@ -16,7 +16,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
final class DefaultMode extends AbstractTrackingMode
|
||||
{
|
||||
public function __construct(private RoundingService $rounding)
|
||||
public function __construct(private readonly RoundingService $rounding)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,16 @@ use App\Configuration\SystemConfiguration;
|
||||
use App\Entity\Timesheet;
|
||||
use DateTime;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
|
||||
final class DurationFixedBeginMode implements TrackingModeInterface
|
||||
{
|
||||
use TrackingModeTrait;
|
||||
|
||||
public function __construct(private SystemConfiguration $configuration)
|
||||
public function __construct(
|
||||
private readonly SystemConfiguration $configuration,
|
||||
private readonly AuthorizationCheckerInterface $authorizationChecker
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -39,7 +43,7 @@ final class DurationFixedBeginMode implements TrackingModeInterface
|
||||
|
||||
public function canUpdateTimesWithAPI(): bool
|
||||
{
|
||||
return false;
|
||||
return $this->authorizationChecker->isGranted('view_other_timesheet');
|
||||
}
|
||||
|
||||
public function create(Timesheet $timesheet, ?Request $request = null): void
|
||||
|
||||
@@ -12,11 +12,18 @@ namespace App\Timesheet\TrackingMode;
|
||||
use App\Entity\Timesheet;
|
||||
use DateTime;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
|
||||
final class PunchInOutMode implements TrackingModeInterface
|
||||
{
|
||||
use TrackingModeTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly AuthorizationCheckerInterface $authorizationChecker
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function canEditBegin(): bool
|
||||
{
|
||||
return false;
|
||||
@@ -34,7 +41,7 @@ final class PunchInOutMode implements TrackingModeInterface
|
||||
|
||||
public function canUpdateTimesWithAPI(): bool
|
||||
{
|
||||
return false;
|
||||
return $this->authorizationChecker->isGranted('view_other_timesheet');
|
||||
}
|
||||
|
||||
public function create(Timesheet $timesheet, ?Request $request = null): void
|
||||
|
||||
@@ -23,61 +23,44 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
interface TrackingModeInterface
|
||||
{
|
||||
/**
|
||||
* Set default values on this new timesheet entity,
|
||||
* before form data is rendered/processed.
|
||||
*
|
||||
* @param Timesheet $timesheet
|
||||
* @param Request|null $request
|
||||
* Set default values on this new timesheet entity, before form data is rendered/processed.
|
||||
*/
|
||||
public function create(Timesheet $timesheet, ?Request $request = null): void;
|
||||
|
||||
/**
|
||||
* Whether the user can edit the begin datetime.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canEditBegin(): bool;
|
||||
|
||||
/**
|
||||
* Whether the user can edit the end datetime.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canEditEnd(): bool;
|
||||
|
||||
/**
|
||||
* Whether the user can edit the duration.
|
||||
* If this is true, the result of canEditEnd() will be ignored.
|
||||
*
|
||||
* @return bool
|
||||
* If this is true, the result of canEditEnd() will be ignored.
|
||||
*/
|
||||
public function canEditDuration(): bool;
|
||||
|
||||
/**
|
||||
* Whether the API can be used to manipulate the start and end times.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canUpdateTimesWithAPI(): bool;
|
||||
|
||||
/**
|
||||
* Returns the edit template path for this tracking mode for regular user mode.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEditTemplate(): string;
|
||||
|
||||
/**
|
||||
* Whether the real begin and end times are shown in the user timesheet.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canSeeBeginAndEndTimes(): bool;
|
||||
|
||||
/**
|
||||
* Returns a unique identifier for this tracking mode.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,9 @@ use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||
|
||||
final class TrackingModeService
|
||||
{
|
||||
private ?TrackingModeInterface $active = null;
|
||||
|
||||
/**
|
||||
* @param SystemConfiguration $configuration
|
||||
* @param TrackingModeInterface[] $modes
|
||||
*/
|
||||
public function __construct(
|
||||
@@ -38,14 +39,23 @@ final class TrackingModeService
|
||||
|
||||
public function getActiveMode(): TrackingModeInterface
|
||||
{
|
||||
$trackingMode = $this->configuration->getTimesheetTrackingMode();
|
||||
// internal caching for the current request
|
||||
// there is no use-case to change that during one requests lifetime
|
||||
if ($this->active === null) {
|
||||
$trackingMode = $this->configuration->getTimesheetTrackingMode();
|
||||
|
||||
foreach ($this->getModes() as $mode) {
|
||||
if ($mode->getId() === $trackingMode) {
|
||||
return $mode;
|
||||
foreach ($this->getModes() as $mode) {
|
||||
if ($mode->getId() === $trackingMode) {
|
||||
$this->active = $mode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->active === null) {
|
||||
throw new ServiceNotFoundException($trackingMode);
|
||||
}
|
||||
}
|
||||
|
||||
throw new ServiceNotFoundException($trackingMode);
|
||||
return $this->active;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user