diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 150dd0229d..ca3b39c57e 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -30,7 +30,7 @@ use OCP\AppFramework\Http\Attribute\PublicPage; use OCP\AppFramework\Http\Attribute\UseSession; use OCP\AppFramework\Http\DataResponse; -use OCP\IConfig; +use OCP\Config\IUserConfig; use OCP\IL10N; use OCP\IRequest; use OCP\IURLGenerator; @@ -58,7 +58,7 @@ public function __construct( protected IUserSession $userSession, protected SessionService $sessionService, private ValidateHelper $validateHelper, - private IConfig $config, + private IUserConfig $userConfig, ) { parent::__construct(Application::APP_ID, $request); } @@ -419,7 +419,7 @@ public function setConfig(string $key): DataResponse { $value = json_encode($value); } - $this->config->setUserValue($user->getUID(), Application::APP_ID, $key, $value); + $this->userConfig->setValueString($user->getUID(), Application::APP_ID, $key, $value); return new DataResponse([ 'key' => $key, diff --git a/lib/Migration/Version12000Date20250517134200.php b/lib/Migration/Version12000Date20250517134200.php index 97a4f8aacc..1a8ccd047c 100644 --- a/lib/Migration/Version12000Date20250517134200.php +++ b/lib/Migration/Version12000Date20250517134200.php @@ -12,13 +12,13 @@ use Closure; use OCA\Libresign\AppInfo\Application; use OCP\DB\ISchemaWrapper; -use OCP\IConfig; +use OCP\IAppConfig; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; class Version12000Date20250517134200 extends SimpleMigrationStep { public function __construct( - protected IConfig $config, + protected IAppConfig $appConfig, ) { } @@ -29,11 +29,11 @@ public function __construct( */ #[\Override] public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { - $keys = $this->config->getAppKeys(Application::APP_ID); + $keys = $this->appConfig->getKeys(Application::APP_ID); if (in_array('notify_unsigned_user', $keys)) { - $current = $this->config->getAppValue(Application::APP_ID, 'notify_unsigned_user'); - $this->config->setAppValue('activity', 'notify_email_libresign_file_to_sign', $current ? '1' : '0'); - $this->config->deleteAppValue(Application::APP_ID, 'notify_unsigned_user'); + $current = $this->appConfig->getValueString(Application::APP_ID, 'notify_unsigned_user'); + $this->appConfig->setValueString('activity', 'notify_email_libresign_file_to_sign', $current ? '1' : '0'); + $this->appConfig->deleteKey(Application::APP_ID, 'notify_unsigned_user'); } } } diff --git a/lib/Service/AccountService.php b/lib/Service/AccountService.php index e3e6742363..4742dd25db 100644 --- a/lib/Service/AccountService.php +++ b/lib/Service/AccountService.php @@ -28,6 +28,7 @@ use OCP\Accounts\IAccountManager; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Config\IUserConfig; use OCP\Files\Config\IMountProviderCollection; use OCP\Files\File; use OCP\Files\IMimeTypeDetector; @@ -35,7 +36,6 @@ use OCP\Files\NotFoundException; use OCP\Http\Client\IClientService; use OCP\IAppConfig; -use OCP\IConfig; use OCP\IGroupManager; use OCP\IL10N; use OCP\IURLGenerator; @@ -61,8 +61,8 @@ public function __construct( private SignFileService $signFileService, private RequestSignatureService $requestSignatureService, private CertificateEngineFactory $certificateEngineFactory, - private IConfig $config, private IAppConfig $appConfig, + private IUserConfig $userConfig, private IMountProviderCollection $mountProviderCollection, private NewUserMailHelper $newUserMail, private IdentifyMethodService $identifyMethodService, @@ -160,7 +160,7 @@ public function createToSign(string $uuid, string $email, string $password, ?str $this->updateIdentifyMethodToAccount($signRequest->getId(), $email, $newUser->getUID()); - if ($this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') { + if ($this->appConfig->getValueString('core', 'newUser.sendEmail', 'yes') === 'yes') { try { $emailTemplate = $this->newUserMail->generateTemplate($newUser, false); $this->newUserMail->sendMail($newUser, $emailTemplate); @@ -262,8 +262,7 @@ private function getUserConfigByKey(string $key, ?IUser $user = null): string { if (!$user) { return ''; } - - return $this->config->getUserValue($user->getUID(), Application::APP_ID, $key); + return $this->userConfig->getValueString($user->getUID(), Application::APP_ID, $key); } private function getUserConfigIdDocsFilters(?IUser $user = null): array { @@ -271,7 +270,7 @@ private function getUserConfigIdDocsFilters(?IUser $user = null): array { return []; } - $value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'id_docs_filters', ''); + $value = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'id_docs_filters', ''); if (empty($value)) { return []; } @@ -285,7 +284,7 @@ private function getUserConfigCrlFilters(?IUser $user = null): array { return []; } - $value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'crl_filters', ''); + $value = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'crl_filters', ''); if (empty($value)) { return []; } @@ -299,7 +298,7 @@ private function getUserConfigCrlSort(?IUser $user): array { return ['sortBy' => 'revoked_at', 'sortOrder' => 'DESC']; } - $value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'crl_sort', ''); + $value = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'crl_sort', ''); if (empty($value)) { return ['sortBy' => 'revoked_at', 'sortOrder' => 'DESC']; } @@ -313,7 +312,7 @@ private function getUserConfigIdDocsSort(?IUser $user): array { return ['sortBy' => null, 'sortOrder' => null]; } - $value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'id_docs_sort', ''); + $value = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'id_docs_sort', ''); if (empty($value)) { return ['sortBy' => null, 'sortOrder' => null]; } diff --git a/tests/php/Unit/Service/AccountServiceTest.php b/tests/php/Unit/Service/AccountServiceTest.php index 56cafff05d..0b19ad17da 100644 --- a/tests/php/Unit/Service/AccountServiceTest.php +++ b/tests/php/Unit/Service/AccountServiceTest.php @@ -32,6 +32,7 @@ use OCA\Settings\Mailer\NewUserMailHelper; use OCP\Accounts\IAccountManager; use OCP\AppFramework\Db\DoesNotExistException; +use OCP\Config\IUserConfig; use OCP\Files\Config\IMountProviderCollection; use OCP\Files\File; use OCP\Files\Folder; @@ -39,7 +40,6 @@ use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\IAppConfig; -use OCP\IConfig; use OCP\IGroupManager; use OCP\IL10N; use OCP\IURLGenerator; @@ -63,8 +63,8 @@ final class AccountServiceTest extends \OCA\Libresign\Tests\Unit\TestCase { private FileTypeMapper&MockObject $fileTypeMapper; private SignFileService&MockObject $signFile; private CertificateEngineFactory&MockObject $certificateEngineFactory; - private IConfig&MockObject $config; private IAppConfig&MockObject $appConfig; + private IUserConfig&MockObject $userConfig; private IMountProviderCollection&MockObject $mountProviderCollection; private NewUserMailHelper&MockObject $newUserMail; private IdentifyMethodService&MockObject $identifyMethodService; @@ -98,8 +98,8 @@ public function setUp(): void { $this->signFile = $this->createMock(SignFileService::class); $this->requestSignatureService = $this->createMock(RequestSignatureService::class); $this->certificateEngineFactory = $this->createMock(CertificateEngineFactory::class); - $this->config = $this->createMock(IConfig::class); $this->appConfig = $this->createMock(IAppConfig::class); + $this->userConfig = $this->createMock(IUserConfig::class); $this->mountProviderCollection = $this->createMock(IMountProviderCollection::class); $this->newUserMail = $this->createMock(NewUserMailHelper::class); $this->identifyMethodService = $this->createMock(IdentifyMethodService::class); @@ -130,8 +130,8 @@ private function getService(): AccountService { $this->signFile, $this->requestSignatureService, $this->certificateEngineFactory, - $this->config, $this->appConfig, + $this->userConfig, $this->mountProviderCollection, $this->newUserMail, $this->identifyMethodService, @@ -218,7 +218,7 @@ public function testCreateToSignWithErrorInSendingEmail():void { $userToSign->method('getUID')->willReturn('username'); $this->userManager->method('createUser')->willReturn($userToSign); $this->identifyMethodService->method('getIdentifyMethodsFromSignRequestId')->willReturn([]); - $this->config->method('getAppValue')->willReturn('yes'); + $this->appConfig->method('getValueString')->willReturn('yes'); $template = $this->createMock(\OCP\Mail\IEMailTemplate::class); $this->newUserMail->method('generateTemplate')->willReturn($template); $this->newUserMail->method('sendMail')->willReturnCallback(function ():void {