@@ -54,47 +54,24 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5454
5555 /* Check if operation is allowed without data */
5656 if (null === $ this ->event ) {
57- if (CrudOperation::LIST === $ crudOperation ) {
58- if (!$ this ->authorizationChecker ->isGranted (CrudOperation::LIST ->value , $ operation ->getClass ())) {
59- throw new AccessDeniedException ();
60- }
61- }
62-
63- if (CrudOperation::CREATE === $ crudOperation ) {
64- if (!$ this ->authorizationChecker ->isGranted (CrudOperation::CREATE ->value , $ operation ->getClass ())) {
57+ if (in_array ($ crudOperation , [CrudOperation::LIST , CrudOperation::CREATE ], true )) {
58+ if (!$ this ->authorizationChecker ->isGranted ($ crudOperation ->value , $ operation ->getClass ())) {
6559 throw new AccessDeniedException ();
6660 }
6761 }
6862 }
6963
7064 $ data = $ this ->decorated ->provide ($ operation , $ uriVariables , $ context );
7165
72- $ crudOperation = match ($ operation ::class) {
73- GetCollection::class => CrudOperation::LIST ,
74- Post::class => CrudOperation::CREATE ,
75- Get::class => CrudOperation::READ ,
76- Put::class, Patch::class => CrudOperation::UPDATE ,
77- Delete::class => CrudOperation::DELETE ,
78- default => null ,
79- };
80-
8166 if (null === $ this ->event ) {
82- if (CrudOperation::DELETE === $ crudOperation ) {
83- if (!$ this ->authorizationChecker ->isGranted (CrudOperation::DELETE ->value , $ data )) {
84- throw new AccessDeniedException ();
85- }
86- }
87- }
88-
89- /* Check if operation is allowed with data after denormalization */
90- if (in_array ($ this ->event , ['post_denormalize ' , 'post_validate ' ], true )) {
91- if (CrudOperation::CREATE === $ crudOperation ) {
92- if (!$ this ->authorizationChecker ->isGranted (CrudOperation::CREATE ->value , $ data )) {
67+ if (in_array ($ crudOperation , [CrudOperation::DELETE , CrudOperation::READ ], true )) {
68+ if (!$ this ->authorizationChecker ->isGranted ($ crudOperation ->value , $ data )) {
9369 throw new AccessDeniedException ();
9470 }
9571 }
96- if (CrudOperation::UPDATE === $ crudOperation ) {
97- if (!$ this ->authorizationChecker ->isGranted (CrudOperation::UPDATE ->value , $ data )) {
72+ } elseif (in_array ($ this ->event , ['post_denormalize ' , 'post_validate ' ], true )) {
73+ if (in_array ($ crudOperation , [CrudOperation::CREATE , CrudOperation::UPDATE ], true )) {
74+ if (!$ this ->authorizationChecker ->isGranted ($ crudOperation ->value , $ data )) {
9875 throw new AccessDeniedException ();
9976 }
10077 }
0 commit comments