mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Add workflow permission check to StoredObjectVoter
This commit introduces logic to grant permissions based on workflow conditions in the `AbstractStoredObjectVoter`. It also includes a new test case to ensure the workflow-based permission check functions correctly.
This commit is contained in:
parent
c99dda0126
commit
aad10cc61f
@ -49,6 +49,11 @@ abstract class AbstractStoredObjectVoter implements StoredObjectVoterInterface
|
|||||||
// Retrieve the related accompanying course document
|
// Retrieve the related accompanying course document
|
||||||
$entity = $this->getRepository()->findAssociatedEntityToStoredObject($subject);
|
$entity = $this->getRepository()->findAssociatedEntityToStoredObject($subject);
|
||||||
|
|
||||||
|
if ($this->workflowDocumentService->isAllowedByWorkflow($entity)) {
|
||||||
|
// read and write permissions are granted by workflow
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Determine the attribute to pass to AccompanyingCourseDocumentVoter
|
// Determine the attribute to pass to AccompanyingCourseDocumentVoter
|
||||||
$voterAttribute = $this->attributeToRole($attribute);
|
$voterAttribute = $this->attributeToRole($attribute);
|
||||||
|
|
||||||
|
@ -99,6 +99,25 @@ class AbstractStoredObjectVoterTest extends TestCase
|
|||||||
$this->workflowDocumentService->method('notBlockedByWorkflow')->willReturn($workflowAllowed);
|
$this->workflowDocumentService->method('notBlockedByWorkflow')->willReturn($workflowAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testIsAllowedByWorkflow(): void
|
||||||
|
{
|
||||||
|
[$user, $token, $subject, $entity] = $this->setupMockObjects();
|
||||||
|
$workflowRelatedEntityPermissionHelper = $this->createMock(WorkflowRelatedEntityPermissionHelper::class);
|
||||||
|
$workflowRelatedEntityPermissionHelper->method('isAllowedByWorkflow')->withAnyParameters()->willReturn(true);
|
||||||
|
|
||||||
|
$associatedObjectRepository = $this->createMock(AssociatedEntityToStoredObjectInterface::class);
|
||||||
|
$associatedObjectRepository->method('findAssociatedEntityToStoredObject')->willReturn($entity);
|
||||||
|
|
||||||
|
$voter = $this->buildStoredObjectVoter(
|
||||||
|
true,
|
||||||
|
$associatedObjectRepository,
|
||||||
|
$this->createMock(Security::class),
|
||||||
|
$workflowRelatedEntityPermissionHelper
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertTrue($voter->voteOnAttribute(StoredObjectRoleEnum::EDIT, $subject, $token));
|
||||||
|
}
|
||||||
|
|
||||||
public function testSupportsOnAttribute(): void
|
public function testSupportsOnAttribute(): void
|
||||||
{
|
{
|
||||||
[$user, $token, $subject, $entity] = $this->setupMockObjects();
|
[$user, $token, $subject, $entity] = $this->setupMockObjects();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user