new: [user:edit] Added keycloak updates when a user gets modified

cli-modification-summary
Sami Mokaddem 2022-09-21 10:11:09 +02:00
parent 37094e0abb
commit 21403995e3
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 39 additions and 0 deletions

View File

@ -145,6 +145,30 @@ class AuthKeycloakBehavior extends Behavior
return true;
}
/**
* handleUserUpdate
*
* @param \App\Model\Entity\User $user
* @return boolean If the update was a success
*/
public function handleUserUpdate(\App\Model\Entity\User $user): bool
{
$user['individual'] = $this->_table->Individuals->find()->where([
'id' => $user['individual_id']
])->first();
$user['role'] = $this->_table->Roles->find()->where([
'id' => $user['role_id']
])->first();
$user['organisation'] = $this->_table->Organisations->find()->where([
'id' => $user['organisation_id']
])->first();
$users = [$user->toArray()];
$clientId = $this->getClientId();
$changes = $this->syncUsers($users, $clientId);
return !empty($changes);
}
private function getAdminAccessToken()
{
$keycloakConfig = Configure::read('keycloak');

View File

@ -61,6 +61,12 @@ class UsersTable extends AppTable
$data['username'] = trim(mb_strtolower($data['username']));
}
public function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options)
{
$success = $this->handleUserUpdateRouter($entity);
return $success;
}
private function initAuthBehaviors()
{
if (!empty(Configure::read('keycloak'))) {
@ -208,4 +214,13 @@ class UsersTable extends AppTable
$this->enrollUser($data);
}
}
public function handleUserUpdateRouter(\App\Model\Entity\User $user): bool
{
if (!empty(Configure::read('keycloak'))) {
$success = $this->handleUserUpdate($user);
return $success;
}
return true;
}
}