Skip to content

Commit

Permalink
feat: Copy password hash to target
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal committed Jun 25, 2024
1 parent a203223 commit 962eab6
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lib/BackgroundJob/TransferJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ private function notifySuccess(Transfer $transfer): void {
$this->notificationManager->notify($notification);
}

private function fail(Transfer $transfer): void {
$this->notifyFailure($transfer);
$this->transferMapper->delete($transfer);
}

public function run($argument): void {
/** @var int $id */
$id = $argument['id'];
Expand All @@ -87,15 +92,13 @@ public function run($argument): void {
$sourceUser = $this->userManager->get($source);
if (!($sourceUser instanceof IUser)) {
$this->logger->error('Failed to transfer missing guest user: ' . $source);
$this->notifyFailure($transfer);
$this->transferMapper->delete($transfer);
$this->fail($transfer);
return;
}

if ($this->userManager->userExists($target)) {
$this->logger->error("Cannot transfer guest user \"$source\", target user \"$target\" already exists");
$this->notifyFailure($transfer);
$this->transferMapper->delete($transfer);
$this->fail($transfer);
return;
}

Expand All @@ -106,14 +109,25 @@ public function run($argument): void {

if (!($targetUser instanceof IUser)) {
$this->logger->error('Failed to create new user: ' . $target);
$this->notifyFailure($transfer);
$this->transferMapper->delete($transfer);
$this->fail($transfer);
return;
}

$targetUser->setSystemEMailAddress($sourceUser->getUID()); // Guest user id is an email

// TODO copy password hash to target user
$passwordHash = $sourceUser->getPasswordHash();

Check failure on line 118 in lib/BackgroundJob/TransferJob.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable29

UndefinedInterfaceMethod

lib/BackgroundJob/TransferJob.php:118:32: UndefinedInterfaceMethod: Method OCP\IUser::getPasswordHash does not exist (see https://psalm.dev/181)

Check failure on line 118 in lib/BackgroundJob/TransferJob.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master

UndefinedInterfaceMethod

lib/BackgroundJob/TransferJob.php:118:32: UndefinedInterfaceMethod: Method OCP\IUser::getPasswordHash does not exist (see https://psalm.dev/181)
if (empty($passwordHash)) {
$this->logger->error('Invalid guest password hash', ['guest' => $sourceUser->getUID(), 'passwordHash' => $passwordHash]);
$this->fail($transfer);
return;
}

$setPasswordHashResult = $targetUser->setPasswordHash($passwordHash);

Check failure on line 125 in lib/BackgroundJob/TransferJob.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable29

UndefinedInterfaceMethod

lib/BackgroundJob/TransferJob.php:125:41: UndefinedInterfaceMethod: Method OCP\IUser::setPasswordHash does not exist (see https://psalm.dev/181)

Check failure on line 125 in lib/BackgroundJob/TransferJob.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master

UndefinedInterfaceMethod

lib/BackgroundJob/TransferJob.php:125:41: UndefinedInterfaceMethod: Method OCP\IUser::setPasswordHash does not exist (see https://psalm.dev/181)
if (!$setPasswordHashResult) {
$this->logger->error('Failed to set password hash on target user', ['user' => $targetUser->getUID()]);
$this->fail($transfer);
return;
}

try {
$this->transferService->transfer($sourceUser, $targetUser);
Expand Down

0 comments on commit 962eab6

Please sign in to comment.