Skip to content

Commit 15d6aeb

Browse files
authored
Merge pull request #9033 from ProcessMaker/task/FOUR-33050
FOUR-33050: Fix updates for users without authentication metadata
2 parents 520e403 + 544179f commit 15d6aeb

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

‎ProcessMaker/Http/Controllers/Api/UserController.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ public function update(User $user, Request $request)
518518
session()->forget('login-error');
519519
}
520520
$original = $user->getOriginal();
521-
$isLdapUser = $user->meta?->authenticationType === 'ldap';
521+
$isLdapUser = isset($user->meta?->authenticationType)
522+
&& $user->meta->authenticationType === 'ldap';
522523
$user->fill($fields);
523524
if (array_key_exists('cell', $fields)) {
524525
$response = $this->validateCellPhoneNumber($user, $fields['cell']);

‎tests/Feature/Api/UsersTest.php‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,51 @@ public function testUpdateUser()
459459
$this->assertNotEquals($verify, $verify_new);
460460
}
461461

462+
public function testAdministratorCanUpdateNewNonSsoUserMoreThanOnce(): void
463+
{
464+
$response = $this->apiCall('POST', self::API_TEST_URL, [
465+
'username' => 'new-non-sso-user',
466+
'firstname' => 'New',
467+
'lastname' => 'User',
468+
'email' => Faker::create()->email(),
469+
'status' => 'ACTIVE',
470+
'password' => $this->makePassword(),
471+
]);
472+
473+
$response->assertStatus(201);
474+
$user = User::findOrFail($response->json('id'));
475+
$this->assertNull($user->meta);
476+
$url = self::API_TEST_URL . '/' . $user->id;
477+
$metadata = ['customProfileProperty' => null];
478+
479+
$response = $this->apiCall(
480+
'PUT',
481+
$url,
482+
$this->getSelfServiceUpdateData($user, ['meta' => $metadata])
483+
);
484+
485+
$response->assertStatus(204);
486+
$user->refresh();
487+
$this->assertNotNull($user->meta);
488+
$this->assertTrue(property_exists($user->meta, 'customProfileProperty'));
489+
$this->assertFalse(property_exists($user->meta, 'authenticationType'));
490+
491+
$response = $this->apiCall(
492+
'PUT',
493+
$url,
494+
$this->getSelfServiceUpdateData($user, [
495+
'title' => 'Updated Twice',
496+
'meta' => $metadata,
497+
])
498+
);
499+
500+
$response->assertStatus(204);
501+
$this->assertDatabaseHas('users', [
502+
'id' => $user->id,
503+
'title' => 'Updated Twice',
504+
]);
505+
}
506+
462507
/**
463508
* Update user in process
464509
*/

0 commit comments

Comments
 (0)