Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Controller/AccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@ public function patchAccount(int $id,
#[TrapError]
public function updateSignature(int $id, ?string $signature = null): JSONResponse {
$effectiveUserId = $this->delegationService->resolveAccountUserId($id, $this->userId);
$this->accountService->updateSignature($id, $effectiveUserId, $signature);
if ($this->userId === $effectiveUserId) {
$this->accountService->updateSignature($id, $effectiveUserId, $signature);
} else {
$this->delegationService->updateSignatureForDelegatedUser($id, $this->userId, $signature);
}
$this->delegationService->logDelegatedAction($this->userId, $effectiveUserId, "$this->userId updated signature for account <$id> on behalf of $effectiveUserId");
return new JSONResponse();
}
Expand Down
5 changes: 5 additions & 0 deletions lib/Db/Delegation.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@
* @method void setAccountId(int $accountId)
* @method string getUserId()
* @method void setUserId(string $userId)
* @method void setSignature(string|null $string)
* @method string getSignature()
*/
class Delegation extends Entity implements JsonSerializable {
protected $accountId;
protected $userId;
protected $signature;

private ?string $displayName = null;

public function __construct() {
$this->addType('userId', 'string');
$this->addType('accountId', 'integer');
$this->addType('signature', 'string');
}

public function getDisplayName(): ?string {
Expand All @@ -46,6 +50,7 @@ public function jsonSerialize() {
'accountId' => $this->getAccountId(),
'userId' => $this->getUserId(),
'displayName' => $this->displayName ?? $this->getUserId(),
'signature' => $this->getSignature(),
];
}
}
42 changes: 42 additions & 0 deletions lib/Migration/Version5201Date20260909105301.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Mail\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use Override;

class Version5201Date20260909105301 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
#[Override]
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
$schema = $schemaClosure();

$table = $schema->getTable('mail_delegations');

if (!$table->hasColumn('signature')) {
$table->addColumn('signature', Types::TEXT, [
'notnull' => false,
]);
}

return $schema;
}

}
6 changes: 6 additions & 0 deletions lib/Service/DelegationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,10 @@ private function notify(string $userId, string $currentUserId, Account $account,
$this->logger->warning('Failed to send delegation notification to {userId}', ['userId' => $userId,'exception' => $e]);
}
}

public function updateSignatureForDelegatedUser(int $accountId, string $userId, ?string $signature): void {
$delegation = $this->delegationMapper->find($accountId, $userId);
$delegation->setSignature($signature);
$this->delegationMapper->update($delegation);
}
}
Loading