@@ -72,7 +72,7 @@ public function createSelectOption(CreateSelectOptionParameters $parameters): Se
7272 public function updateSelectOption (string $ id , UpdateSelectOptionParameters $ parameters ): SelectOptionDetail
7373 {
7474 $ config = $ this ->selectOptionRepository ->getById ($ id );
75- $ this ->checkAdminAccess ($ config );
75+ $ this ->validateAdminAccess ($ config );
7676
7777 $ this ->validateSelectOptions ($ parameters ->getSelectOptions ());
7878
@@ -100,7 +100,7 @@ public function updateSelectOption(string $id, UpdateSelectOptionParameters $par
100100 public function deleteSelectOption (string $ id ): void
101101 {
102102 $ config = $ this ->selectOptionRepository ->getById ($ id );
103- $ this ->checkAdminAccess ($ config );
103+ $ this ->validateAdminAccess ($ config );
104104 $ this ->selectOptionRepository ->delete ($ config );
105105 }
106106
@@ -130,6 +130,9 @@ public function getSelectOptionUsages(string $id): array
130130 private function hydrateDetail (Config $ config ): SelectOptionDetail
131131 {
132132 $ isWriteable = $ this ->selectOptionRepository ->isWriteable ($ config );
133+ if (!$ this ->hasAccess ($ config )) {
134+ $ isWriteable = false ;
135+ }
133136 $ detail = $ this ->detailHydrator ->hydrate ($ config , $ isWriteable );
134137 $ this ->eventDispatcher ->dispatch (new DetailEvent ($ detail ), DetailEvent::EVENT_NAME );
135138
@@ -160,10 +163,15 @@ private function validateSelectOptions(?array $selectOptions): void
160163 /**
161164 * @throws ForbiddenException
162165 */
163- private function checkAdminAccess (Config $ config ): void
166+ private function validateAdminAccess (Config $ config ): void
164167 {
165- if ($ config -> getAdminOnly () && ! $ this -> securityService -> getCurrentUser ()-> isAdmin () ) {
168+ if ($ this -> hasAccess ( $ config ) === false ) {
166169 throw new ForbiddenException ('Restricted to admin users ' );
167170 }
168171 }
172+
173+ private function hasAccess (Config $ config ): bool
174+ {
175+ return !($ config ->getAdminOnly () && !$ this ->securityService ->getCurrentUser ()->isAdmin ());
176+ }
169177}
0 commit comments