Skip to content

Commit bcef4c4

Browse files
committed
fix: Move away from deprecated methods to set user config
Signed-off-by: Julius Knorr <[email protected]>
1 parent 5266aef commit bcef4c4

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

lib/Controller/SettingsController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use OCP\AppFramework\Http;
1313
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
1414
use OCP\AppFramework\Http\DataResponse;
15-
use OCP\IConfig;
15+
use OCP\Config\IUserConfig;
1616
use OCP\IRequest;
1717

1818
class SettingsController extends Controller {
@@ -24,7 +24,7 @@ class SettingsController extends Controller {
2424
public function __construct(
2525
string $appName,
2626
IRequest $request,
27-
private IConfig $config,
27+
private IUserConfig $userConfig,
2828
private ?string $userId,
2929
) {
3030
parent::__construct($appName, $request);
@@ -40,8 +40,9 @@ public function updateConfig(string $key, int|string $value): DataResponse {
4040
if (!in_array($key, self::ACCEPTED_KEYS, true)) {
4141
return new DataResponse(['message' => 'Invalid config key'], Http::STATUS_BAD_REQUEST);
4242
}
43+
4344
/** @psalm-suppress PossiblyNullArgument */
44-
$this->config->setUserValue($this->userId, Application::APP_NAME, $key, (string)$value);
45+
$this->userConfig->setValueBool($this->userId, Application::APP_NAME, $key, (string)($value) === '1');
4546
return new DataResponse([
4647
$key => $value
4748
]);

lib/DAV/WorkspacePlugin.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
use OC\Files\Node\File;
1313
use OCA\DAV\Connector\Sabre\Directory;
1414
use OCA\DAV\Files\FilesHome;
15-
use OCA\Text\AppInfo\Application;
15+
use OCA\Text\Service\ConfigService;
1616
use OCA\Text\Service\WorkspaceService;
1717
use OCP\Files\GenericFileException;
18-
use OCP\Files\IRootFolder;
1918
use OCP\Files\NotPermittedException;
2019
use OCP\ICacheFactory;
21-
use OCP\IConfig;
2220
use OCP\Lock\LockedException;
2321
use Psr\Log\LoggerInterface;
2422
use Sabre\DAV\INode;
@@ -35,9 +33,8 @@ class WorkspacePlugin extends ServerPlugin {
3533

3634
public function __construct(
3735
private WorkspaceService $workspaceService,
38-
private IRootFolder $rootFolder,
3936
private ICacheFactory $cacheFactory,
40-
private IConfig $config,
37+
private ConfigService $configService,
4138
private LoggerInterface $logger,
4239
private ?string $userId,
4340
) {
@@ -71,8 +68,8 @@ public function propFind(PropFind $propFind, INode $node) {
7168
return;
7269
}
7370

74-
$workspaceAvailable = $this->config->getAppValue(Application::APP_NAME, 'workspace_available', '1') === '1';
75-
$workspaceEnabled = $this->config->getUserValue($this->userId, Application::APP_NAME, 'workspace_enabled', '1') === '1';
71+
$workspaceAvailable = $this->configService->isRichWorkspaceAvailable();
72+
$workspaceEnabled = $this->configService->isRichWorkspaceEnabledForUser($this->userId);
7673

7774
if (!$workspaceAvailable || !$workspaceEnabled) {
7875
return;

lib/Service/ConfigService.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
namespace OCA\Text\Service;
99

1010
use OCA\Text\AppInfo\Application;
11+
use OCP\Config\IUserConfig;
1112
use OCP\IAppConfig;
1213
use OCP\IConfig;
1314

1415
class ConfigService {
1516
public function __construct(
1617
private IAppConfig $appConfig,
18+
private IUserConfig $userConfig,
1719
private IConfig $config,
1820
) {
1921
}
@@ -41,7 +43,7 @@ public function isRichWorkspaceEnabledForUser(?string $userId): bool {
4143
if ($userId === null) {
4244
return true;
4345
}
44-
return $this->config->getUserValue($userId, Application::APP_NAME, 'workspace_enabled', '1') === '1';
46+
return $this->userConfig->getValueBool($userId, Application::APP_NAME, 'workspace_enabled', true);
4547
}
4648

4749
public function isNotifyPushSyncEnabled(): bool {
@@ -50,6 +52,9 @@ public function isNotifyPushSyncEnabled(): bool {
5052
}
5153

5254
public function isFullWidthEditor(?string $userId): bool {
53-
return $this->config->getUserValue($userId, Application::APP_NAME, 'is_full_width_editor', '0') === '1';
55+
if ($userId === null) {
56+
return false;
57+
}
58+
return $this->userConfig->getValueBool($userId, Application::APP_NAME, 'is_full_width_editor');
5459
}
5560
}

0 commit comments

Comments
 (0)