Skip to content

Commit 4a77dfe

Browse files
authored
Merge pull request #7006 from LibreSign/backport/6999/stable33
[stable33] Fix/6855 replace deprecated iconfig methods
2 parents 438876e + 48483c3 commit 4a77dfe

4 files changed

Lines changed: 22 additions & 23 deletions

File tree

lib/Controller/AccountController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
use OCP\AppFramework\Http\Attribute\PublicPage;
3131
use OCP\AppFramework\Http\Attribute\UseSession;
3232
use OCP\AppFramework\Http\DataResponse;
33-
use OCP\IConfig;
33+
use OCP\Config\IUserConfig;
3434
use OCP\IL10N;
3535
use OCP\IRequest;
3636
use OCP\IURLGenerator;
@@ -58,7 +58,7 @@ public function __construct(
5858
protected IUserSession $userSession,
5959
protected SessionService $sessionService,
6060
private ValidateHelper $validateHelper,
61-
private IConfig $config,
61+
private IUserConfig $userConfig,
6262
) {
6363
parent::__construct(Application::APP_ID, $request);
6464
}
@@ -419,7 +419,7 @@ public function setConfig(string $key): DataResponse {
419419
$value = json_encode($value);
420420
}
421421

422-
$this->config->setUserValue($user->getUID(), Application::APP_ID, $key, $value);
422+
$this->userConfig->setValueString($user->getUID(), Application::APP_ID, $key, $value);
423423

424424
return new DataResponse([
425425
'key' => $key,

lib/Migration/Version12000Date20250517134200.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
use Closure;
1313
use OCA\Libresign\AppInfo\Application;
1414
use OCP\DB\ISchemaWrapper;
15-
use OCP\IConfig;
15+
use OCP\IAppConfig;
1616
use OCP\Migration\IOutput;
1717
use OCP\Migration\SimpleMigrationStep;
1818

1919
class Version12000Date20250517134200 extends SimpleMigrationStep {
2020
public function __construct(
21-
protected IConfig $config,
21+
protected IAppConfig $appConfig,
2222
) {
2323
}
2424

@@ -29,11 +29,11 @@ public function __construct(
2929
*/
3030
#[\Override]
3131
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
32-
$keys = $this->config->getAppKeys(Application::APP_ID);
32+
$keys = $this->appConfig->getKeys(Application::APP_ID);
3333
if (in_array('notify_unsigned_user', $keys)) {
34-
$current = $this->config->getAppValue(Application::APP_ID, 'notify_unsigned_user');
35-
$this->config->setAppValue('activity', 'notify_email_libresign_file_to_sign', $current ? '1' : '0');
36-
$this->config->deleteAppValue(Application::APP_ID, 'notify_unsigned_user');
34+
$current = $this->appConfig->getValueString(Application::APP_ID, 'notify_unsigned_user');
35+
$this->appConfig->setValueString('activity', 'notify_email_libresign_file_to_sign', $current ? '1' : '0');
36+
$this->appConfig->deleteKey(Application::APP_ID, 'notify_unsigned_user');
3737
}
3838
}
3939
}

lib/Service/AccountService.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
use OCP\Accounts\IAccountManager;
2929
use OCP\AppFramework\Db\DoesNotExistException;
3030
use OCP\AppFramework\Utility\ITimeFactory;
31+
use OCP\Config\IUserConfig;
3132
use OCP\Files\Config\IMountProviderCollection;
3233
use OCP\Files\File;
3334
use OCP\Files\IMimeTypeDetector;
3435
use OCP\Files\IRootFolder;
3536
use OCP\Files\NotFoundException;
3637
use OCP\Http\Client\IClientService;
3738
use OCP\IAppConfig;
38-
use OCP\IConfig;
3939
use OCP\IGroupManager;
4040
use OCP\IL10N;
4141
use OCP\IURLGenerator;
@@ -61,8 +61,8 @@ public function __construct(
6161
private SignFileService $signFileService,
6262
private RequestSignatureService $requestSignatureService,
6363
private CertificateEngineFactory $certificateEngineFactory,
64-
private IConfig $config,
6564
private IAppConfig $appConfig,
65+
private IUserConfig $userConfig,
6666
private IMountProviderCollection $mountProviderCollection,
6767
private NewUserMailHelper $newUserMail,
6868
private IdentifyMethodService $identifyMethodService,
@@ -160,7 +160,7 @@ public function createToSign(string $uuid, string $email, string $password, ?str
160160

161161
$this->updateIdentifyMethodToAccount($signRequest->getId(), $email, $newUser->getUID());
162162

163-
if ($this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') {
163+
if ($this->appConfig->getValueString('core', 'newUser.sendEmail', 'yes') === 'yes') {
164164
try {
165165
$emailTemplate = $this->newUserMail->generateTemplate($newUser, false);
166166
$this->newUserMail->sendMail($newUser, $emailTemplate);
@@ -262,16 +262,15 @@ private function getUserConfigByKey(string $key, ?IUser $user = null): string {
262262
if (!$user) {
263263
return '';
264264
}
265-
266-
return $this->config->getUserValue($user->getUID(), Application::APP_ID, $key);
265+
return $this->userConfig->getValueString($user->getUID(), Application::APP_ID, $key);
267266
}
268267

269268
private function getUserConfigIdDocsFilters(?IUser $user = null): array {
270269
if (!$user) {
271270
return [];
272271
}
273272

274-
$value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'id_docs_filters', '');
273+
$value = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'id_docs_filters', '');
275274
if (empty($value)) {
276275
return [];
277276
}
@@ -285,7 +284,7 @@ private function getUserConfigCrlFilters(?IUser $user = null): array {
285284
return [];
286285
}
287286

288-
$value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'crl_filters', '');
287+
$value = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'crl_filters', '');
289288
if (empty($value)) {
290289
return [];
291290
}
@@ -299,7 +298,7 @@ private function getUserConfigCrlSort(?IUser $user): array {
299298
return ['sortBy' => 'revoked_at', 'sortOrder' => 'DESC'];
300299
}
301300

302-
$value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'crl_sort', '');
301+
$value = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'crl_sort', '');
303302
if (empty($value)) {
304303
return ['sortBy' => 'revoked_at', 'sortOrder' => 'DESC'];
305304
}
@@ -313,7 +312,7 @@ private function getUserConfigIdDocsSort(?IUser $user): array {
313312
return ['sortBy' => null, 'sortOrder' => null];
314313
}
315314

316-
$value = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'id_docs_sort', '');
315+
$value = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'id_docs_sort', '');
317316
if (empty($value)) {
318317
return ['sortBy' => null, 'sortOrder' => null];
319318
}

tests/php/Unit/Service/AccountServiceTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
use OCA\Settings\Mailer\NewUserMailHelper;
3333
use OCP\Accounts\IAccountManager;
3434
use OCP\AppFramework\Db\DoesNotExistException;
35+
use OCP\Config\IUserConfig;
3536
use OCP\Files\Config\IMountProviderCollection;
3637
use OCP\Files\File;
3738
use OCP\Files\Folder;
3839
use OCP\Files\IMimeTypeDetector;
3940
use OCP\Files\IRootFolder;
4041
use OCP\Files\NotFoundException;
4142
use OCP\IAppConfig;
42-
use OCP\IConfig;
4343
use OCP\IGroupManager;
4444
use OCP\IL10N;
4545
use OCP\IURLGenerator;
@@ -63,8 +63,8 @@ final class AccountServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
6363
private FileTypeMapper&MockObject $fileTypeMapper;
6464
private SignFileService&MockObject $signFile;
6565
private CertificateEngineFactory&MockObject $certificateEngineFactory;
66-
private IConfig&MockObject $config;
6766
private IAppConfig&MockObject $appConfig;
67+
private IUserConfig&MockObject $userConfig;
6868
private IMountProviderCollection&MockObject $mountProviderCollection;
6969
private NewUserMailHelper&MockObject $newUserMail;
7070
private IdentifyMethodService&MockObject $identifyMethodService;
@@ -98,8 +98,8 @@ public function setUp(): void {
9898
$this->signFile = $this->createMock(SignFileService::class);
9999
$this->requestSignatureService = $this->createMock(RequestSignatureService::class);
100100
$this->certificateEngineFactory = $this->createMock(CertificateEngineFactory::class);
101-
$this->config = $this->createMock(IConfig::class);
102101
$this->appConfig = $this->createMock(IAppConfig::class);
102+
$this->userConfig = $this->createMock(IUserConfig::class);
103103
$this->mountProviderCollection = $this->createMock(IMountProviderCollection::class);
104104
$this->newUserMail = $this->createMock(NewUserMailHelper::class);
105105
$this->identifyMethodService = $this->createMock(IdentifyMethodService::class);
@@ -130,8 +130,8 @@ private function getService(): AccountService {
130130
$this->signFile,
131131
$this->requestSignatureService,
132132
$this->certificateEngineFactory,
133-
$this->config,
134133
$this->appConfig,
134+
$this->userConfig,
135135
$this->mountProviderCollection,
136136
$this->newUserMail,
137137
$this->identifyMethodService,
@@ -218,7 +218,7 @@ public function testCreateToSignWithErrorInSendingEmail():void {
218218
$userToSign->method('getUID')->willReturn('username');
219219
$this->userManager->method('createUser')->willReturn($userToSign);
220220
$this->identifyMethodService->method('getIdentifyMethodsFromSignRequestId')->willReturn([]);
221-
$this->config->method('getAppValue')->willReturn('yes');
221+
$this->appConfig->method('getValueString')->willReturn('yes');
222222
$template = $this->createMock(\OCP\Mail\IEMailTemplate::class);
223223
$this->newUserMail->method('generateTemplate')->willReturn($template);
224224
$this->newUserMail->method('sendMail')->willReturnCallback(function ():void {

0 commit comments

Comments
 (0)