@@ -54,9 +54,13 @@ public void update(final String id,
54
54
final AysUserUpdateRequest updateRequest ) {
55
55
56
56
final AysUser user = userReadPort .findById (id )
57
- .filter (userFromDatabase -> identity .getInstitutionId ().equals (userFromDatabase .getInstitution ().getId ()))
58
57
.orElseThrow (() -> new AysUserNotExistByIdException (id ));
59
58
59
+ String institutionId = identity .getInstitutionId ();
60
+ if (!institutionId .equals (user .getInstitution ().getId ())) {
61
+ throw new AysUserNotExistByIdException (id );
62
+ }
63
+
60
64
if (!(user .isActive () || user .isPassive ())) {
61
65
throw new AysUserIsNotActiveOrPassiveException (id );
62
66
}
@@ -76,7 +80,7 @@ public void update(final String id,
76
80
user .setEmailAddress (updateRequest .getEmailAddress ());
77
81
}
78
82
79
- this .validateRolesAndSet (user , updateRequest .getRoleIds ());
83
+ this .validateRolesAndSet (user , updateRequest .getRoleIds (), institutionId );
80
84
81
85
user .setFirstName (updateRequest .getFirstName ());
82
86
user .setLastName (updateRequest .getLastName ());
@@ -214,7 +218,7 @@ private void validateEmailAddress(AysUser user, String emailAddress) {
214
218
* @param roleIds The set of role IDs to be checked and retrieved.
215
219
* @throws AysRolesNotExistException if any of the provided role IDs do not exist.
216
220
*/
217
- private void validateRolesAndSet (final AysUser user , final Set <String > roleIds ) {
221
+ private void validateRolesAndSet (final AysUser user , final Set <String > roleIds , final String institutionId ) {
218
222
219
223
boolean isRoleNotChanged = user .getRoles ().stream ()
220
224
.allMatch (role -> roleIds .contains (role .getId ()));
@@ -224,7 +228,7 @@ private void validateRolesAndSet(final AysUser user, final Set<String> roleIds)
224
228
225
229
final List <AysRole > roles = roleReadPort .findAllByIds (roleIds ).stream ()
226
230
.filter (AysRole ::isActive )
227
- .filter (role -> identity . getInstitutionId () .equals (role .getInstitution ().getId ()))
231
+ .filter (role -> institutionId .equals (role .getInstitution ().getId ()))
228
232
.toList ();
229
233
230
234
if (roles .size () == roleIds .size ()) {
0 commit comments