Skip to content

Commit 57bcbf7

Browse files
committed
Add createCommandJob check user role parameter
1 parent a4c0530 commit 57bcbf7

2 files changed

Lines changed: 30 additions & 20 deletions

File tree

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ The function __createCommandJob__ from __CommandJobFactory__ accepts:
194194
* job entity for parent job (optional)
195195
* entity of recurring parent job (optional)
196196
* datetime of postponed job start (optional)
197+
* check user role (optional)
197198

198199
and returns the created job.
199200

@@ -372,19 +373,20 @@ The tests are also run on every push / pull request on GitHub.
372373
* "dragonmantank/cron-expression": "^3",
373374
* "knplabs/knp-paginator-bundle": "^6",
374375
* "spiriitlabs/form-filter-bundle": "^11",
375-
* "symfony/form": "6.4 || ^7.2",
376-
* "symfony/framework-bundle": "6.4 || ^7.2",
377-
* "symfony/lock": "6.4 || ^7.2",
378-
* "symfony/messenger": "6.4 || ^7.2",
379-
* "symfony/process": "6.4 || ^7.2",
380-
* "symfony/scheduler": "6.4 || ^7.2",
381-
* "symfony/security-bundle": "6.4 || ^7.2",
382-
* "symfony/translation": "6.4 || ^7.2",
376+
* "symfony/form": "^6.4 || ^7.2",
377+
* "symfony/framework-bundle": "^6.4 || ^7.2",
378+
* "symfony/lock": "^6.4 || ^7.2",
379+
* "symfony/messenger": "^6.4 || ^7.2",
380+
* "symfony/process": "^6.4 || ^7.2",
381+
* "symfony/scheduler": "^6.4 || ^7.2",
382+
* "symfony/security-bundle": "^6.4 || ^7.2",
383+
* "symfony/translation": "^6.4 || ^7.2",
383384
* "twig/twig": "^2|^3"
384385

385386
## TODO
386387

387-
[Handle getting changes of recurring jobs in better way](/../../issues/3)
388+
- [Handle getting changes of recurring jobs in better way](/../../issues/3)
389+
- Handle jobs output better (key:value)
388390

389391
## Additional info / Contributing
390392

src/Service/CommandJobFactory.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Doctrine\ORM\OptimisticLockException;
1111
use Symfony\Bundle\SecurityBundle\Security;
1212
use Symfony\Component\Messenger\Envelope;
13+
use Symfony\Component\Messenger\Exception\ExceptionInterface;
1314
use Symfony\Component\Messenger\MessageBusInterface;
1415
use Symfony\Component\Messenger\Stamp\DelayStamp;
1516
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -31,22 +32,29 @@ public function __construct(
3132
}
3233

3334
/**
34-
* @param string $commandName - Command name
35-
* @param array $commandParams - Command params
36-
* @param int|null $entityId - Entity ID
37-
* @param string|null $entityClassName - Entity class name
38-
* @param Job|null $parentJob - Parent Job entity
39-
* @param JobRecurring|null $parentJobRecurring - Recurring job from which was created
40-
* @param DateTimeImmutable|null $postponedStartAt - Postponed job start time
35+
* @param string $commandName Command name
36+
* @param array $commandParams Command params
37+
* @param int|null $entityId Entity ID
38+
* @param string|null $entityClassName Entity class name
39+
* @param Job|null $parentJob Parent Job entity
40+
* @param JobRecurring|null $parentJobRecurring Recurring job from which was created
41+
* @param DateTimeImmutable|null $postponedStartAt Postponed job start time
42+
* @param bool $checkUserRole Check if user has a role with granted job creation
4143
* @return Job
4244
* @throws CommandJobException
43-
* @throws ORMException
44-
* @throws OptimisticLockException
45+
* @throws ExceptionInterface
4546
*/
46-
public function createCommandJob(string $commandName, array $commandParams, ?int $entityId = null, ?string $entityClassName = null, ?Job $parentJob = null, ?JobRecurring $parentJobRecurring = null, ?DateTimeImmutable $postponedStartAt = null): Job
47+
public function createCommandJob(string $commandName,
48+
array $commandParams,
49+
?int $entityId = null,
50+
?string $entityClassName = null,
51+
?Job $parentJob = null,
52+
?JobRecurring $parentJobRecurring = null,
53+
?DateTimeImmutable $postponedStartAt = null,
54+
?bool $checkUserRole = true): Job
4755
{
4856
// Check if user is loaded and is granted job creation
49-
if ($this->security->getUser() && !$this->security->isGranted(JobQueuePermissions::ROLE_JOB_CREATE)) {
57+
if ($checkUserRole && $this->security->getUser() && !$this->security->isGranted(JobQueuePermissions::ROLE_JOB_CREATE)) {
5058
throw new CommandJobException($this->translator->trans('job.creation.error_security'));
5159
}
5260

0 commit comments

Comments
 (0)