| @@ 74-96 (lines=23) @@ | ||
| 71 | * @param string $institution |
|
| 72 | * @param InstitutionConfigurationOptions $institutionConfigurationOptions |
|
| 73 | */ |
|
| 74 | public function changeInstitutionScope( |
|
| 75 | $institution, |
|
| 76 | InstitutionConfigurationOptions $institutionConfigurationOptions |
|
| 77 | ) { |
|
| 78 | if ($this->getUser() === null) { |
|
| 79 | throw new LogicException('Cannot change institution scope: token does not contain a user'); |
|
| 80 | } |
|
| 81 | ||
| 82 | $roles = array_map(function (RoleInterface $role) { |
|
| 83 | return $role->getRole(); |
|
| 84 | }, $this->getRoles()); |
|
| 85 | ||
| 86 | if (!in_array('ROLE_SRAA', $roles)) { |
|
| 87 | throw new RuntimeException(sprintf( |
|
| 88 | 'Unauthorized to change institution scope to "%s": role SRAA required, found roles "%s"', |
|
| 89 | $institution, |
|
| 90 | implode(', ', $roles) |
|
| 91 | )); |
|
| 92 | } |
|
| 93 | ||
| 94 | $this->getUser()->institution = $institution; |
|
| 95 | $this->institutionConfigurationOptions = $institutionConfigurationOptions; |
|
| 96 | } |
|
| 97 | ||
| 98 | /** |
|
| 99 | * @param string $institution |
|
| @@ 101-119 (lines=19) @@ | ||
| 98 | /** |
|
| 99 | * @param string $institution |
|
| 100 | */ |
|
| 101 | public function changeRaaInstitutionScope($institution) |
|
| 102 | { |
|
| 103 | if ($this->getUser() === null) { |
|
| 104 | throw new LogicException('Cannot change RAA institution scope: token does not contain a user'); |
|
| 105 | } |
|
| 106 | ||
| 107 | $roles = array_map(function (RoleInterface $role) { |
|
| 108 | return $role->getRole(); |
|
| 109 | }, $this->getRoles()); |
|
| 110 | ||
| 111 | if (!in_array('ROLE_RAA', $roles)) { |
|
| 112 | throw new RuntimeException(sprintf( |
|
| 113 | 'Unauthorized to change institution scope to "%s": role SRAA required, found roles "%s"', |
|
| 114 | $institution, |
|
| 115 | implode(', ', $roles) |
|
| 116 | )); |
|
| 117 | } |
|
| 118 | ||
| 119 | $this->raManagementInstitution = $institution; |
|
| 120 | } |
|
| 121 | ||
| 122 | /** |
|