Skip to content

Commit 583c90b

Browse files
authored
Merge pull request #889 from nextcloud/feat/migrate-exapp-config-to-server-tables
feat(config): store ExApp config & preferences in the server's app/user config
2 parents 4452269 + 74d7ad2 commit 583c90b

16 files changed

Lines changed: 971 additions & 660 deletions

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Two options are available:
3737
3838
See the [admin documentation](https://docs.nextcloud.com/server/latest/admin_manual/exapps_management/DeployConfigurations.html) for setup instructions.
3939
]]></description>
40-
<version>35.0.0-dev.0</version>
40+
<version>35.0.0-dev.1</version>
4141
<licence>agpl</licence>
4242
<author mail="andrey18106x@gmail.com" homepage="https://github.com/andrey18106">Andrey Borysenko</author>
4343
<author mail="bigcat88@icloud.com" homepage="https://github.com/bigcat88">Alexander Piskun</author>

appinfo/routes.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,16 @@
8787
// ExApps actions
8888
['name' => 'OCSExApp#setExAppEnabled', 'url' => '/api/v1/ex-app/{appId}/enabled', 'verb' => 'PUT'],
8989

90-
// appconfig_ex (app configuration)
90+
// ExApp app configuration (backed by the server's IAppConfig / oc_appconfig).
91+
// Intentionally kept as AppAPI endpoints: the server's own provisioning_api app-config
92+
// routes require admin / delegated-admin authorization, which an ExApp request lacks.
9193
['name' => 'AppConfig#setAppConfigValue', 'url' => '/api/v1/ex-app/config', 'verb' => 'POST'],
9294
['name' => 'AppConfig#getAppConfigValues', 'url' => '/api/v1/ex-app/config/get-values', 'verb' => 'POST'],
9395
['name' => 'AppConfig#deleteAppConfigValues', 'url' => '/api/v1/ex-app/config', 'verb' => 'DELETE'],
9496

95-
// preferences_ex (user-specific configuration)
97+
// ExApp per-user preferences (backed by the server's IUserConfig / oc_preferences).
98+
// Intentionally kept: the server's provisioning_api user-config routes are write-only
99+
// (no read endpoint) and have no sensitive/encrypted-value support.
96100
['name' => 'Preferences#setUserConfigValue', 'url' => '/api/v1/ex-app/preference', 'verb' => 'POST'],
97101
['name' => 'Preferences#getUserConfigValues', 'url' => '/api/v1/ex-app/preference/get-values', 'verb' => 'POST'],
98102
['name' => 'Preferences#deleteUserConfigValues', 'url' => '/api/v1/ex-app/preference', 'verb' => 'DELETE'],

lib/Controller/AppConfigController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function deleteAppConfigValues(array $configKeys): DataResponse {
7676
throw new OCSBadRequestException('Error deleting app config values');
7777
}
7878
if ($result === 0) {
79-
throw new OCSNotFoundException('No appconfig_ex values deleted');
79+
throw new OCSNotFoundException('No app config values deleted');
8080
}
8181
return new DataResponse($result, Http::STATUS_OK);
8282
}

lib/Controller/PreferencesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function deleteUserConfigValues(array $configKeys): DataResponse {
8181
throw new OCSBadRequestException('Failed to delete user config values');
8282
}
8383
if ($result === 0) {
84-
throw new OCSNotFoundException('No preferences_ex values deleted');
84+
throw new OCSNotFoundException('No user config values deleted');
8585
}
8686
return new DataResponse($result, Http::STATUS_OK);
8787
}

lib/Db/ExAppConfig.php

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,67 @@
1010
namespace OCA\AppAPI\Db;
1111

1212
use JsonSerializable;
13-
use OCP\AppFramework\Db\Entity;
1413

1514
/**
16-
* Class ExAppConfig
15+
* App configuration value object.
1716
*
18-
* @package OCA\AppAPI\Db
17+
* Historically a database entity backed by the `appconfig_ex` table. ExApp config now lives
18+
* in the server's standard `oc_appconfig` (via {@see \OCA\AppAPI\Service\ExAppConfigService});
19+
* this class remains as a plain serializable DTO for OCS responses and internal callers.
1920
*
20-
* @method string getAppid()
21-
* @method string getConfigkey()
22-
* @method string getConfigvalue()
23-
* @method int getSensitive()
24-
* @method void setAppid(string $appId)
25-
* @method void setConfigKey(string $configKey)
26-
* @method void setConfigvalue(string $configValue)
27-
* @method void setSensitive(int $sensitive)
21+
* The `id` field has no surrogate key anymore (the server table uses a composite primary key);
22+
* it is kept in the serialized shape as `0` for backwards compatibility and is unused.
2823
*/
29-
class ExAppConfig extends Entity implements JsonSerializable {
30-
protected $appid;
31-
protected $configkey;
32-
protected $configvalue;
33-
protected $sensitive;
24+
class ExAppConfig implements JsonSerializable {
25+
private int $id;
26+
private string $appid;
27+
private string $configkey;
28+
private string $configvalue;
29+
private int $sensitive;
3430

35-
/**
36-
* @param array $params
37-
*/
3831
public function __construct(array $params = []) {
39-
$this->addType('appid', 'string');
40-
$this->addType('configkey', 'string');
41-
$this->addType('configvalue', 'string');
42-
$this->addType('sensitive', 'integer');
32+
$this->id = isset($params['id']) ? (int)$params['id'] : 0;
33+
$this->appid = (string)($params['appid'] ?? '');
34+
$this->configkey = (string)($params['configkey'] ?? '');
35+
$this->configvalue = (string)($params['configvalue'] ?? '');
36+
$this->sensitive = (int)($params['sensitive'] ?? 0);
37+
}
38+
39+
public function getId(): int {
40+
return $this->id;
41+
}
42+
43+
public function getAppid(): string {
44+
return $this->appid;
45+
}
46+
47+
public function getConfigkey(): string {
48+
return $this->configkey;
49+
}
50+
51+
public function getConfigvalue(): string {
52+
return $this->configvalue;
53+
}
54+
55+
public function setConfigvalue(string $configValue): void {
56+
$this->configvalue = $configValue;
57+
}
58+
59+
public function getSensitive(): int {
60+
return $this->sensitive;
61+
}
4362

44-
if (isset($params['id'])) {
45-
$this->setId($params['id']);
46-
}
47-
if (isset($params['appid'])) {
48-
$this->setAppid($params['appid']);
49-
}
50-
if (isset($params['configkey'])) {
51-
$this->setConfigkey($params['configkey']);
52-
}
53-
if (isset($params['configvalue'])) {
54-
$this->setConfigvalue($params['configvalue']);
55-
}
56-
if (isset($params['sensitive'])) {
57-
$this->setSensitive($params['sensitive']);
58-
}
63+
public function setSensitive(int $sensitive): void {
64+
$this->sensitive = $sensitive;
5965
}
6066

6167
public function jsonSerialize(): array {
6268
return [
63-
'id' => $this->getId(),
64-
'appid' => $this->getAppid(),
65-
'configkey' => $this->getConfigkey(),
66-
'configvalue' => $this->getConfigvalue(),
67-
'sensitive' => $this->getSensitive(),
69+
'id' => $this->id,
70+
'appid' => $this->appid,
71+
'configkey' => $this->configkey,
72+
'configvalue' => $this->configvalue,
73+
'sensitive' => $this->sensitive,
6874
];
6975
}
7076
}

lib/Db/ExAppConfigMapper.php

Lines changed: 0 additions & 91 deletions
This file was deleted.

lib/Db/ExAppPreference.php

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,69 +10,74 @@
1010
namespace OCA\AppAPI\Db;
1111

1212
use JsonSerializable;
13-
use OCP\AppFramework\Db\Entity;
1413

1514
/**
16-
* Class ExAppPreference
15+
* App per-user preference value object.
1716
*
18-
* @package OCA\AppAPI\Db
17+
* Historically a database entity backed by the `preferences_ex` table. ExApp preferences now
18+
* live in the server's standard `oc_preferences` (via {@see \OCA\AppAPI\Service\ExAppPreferenceService});
19+
* this class remains as a plain serializable DTO for OCS responses and internal callers.
1920
*
20-
* @method string getUserid()
21-
* @method string getAppid()
22-
* @method string getConfigkey()
23-
* @method string getConfigvalue()
24-
* @method int getSensitive()
25-
* @method void setUserid(string $userid)
26-
* @method void setAppid(string $appid)
27-
* @method void setConfigkey(string $configkey)
28-
* @method void setConfigvalue(string $configvalue)
29-
* @method void setSensitive(int $sensitive)
21+
* The `id` field has no surrogate key anymore (the server table uses a composite primary key);
22+
* it is kept in the serialized shape as `0` for backwards compatibility and is unused.
3023
*/
31-
class ExAppPreference extends Entity implements JsonSerializable {
32-
protected $userid;
33-
protected $appid;
34-
protected $configkey;
35-
protected $configvalue;
36-
protected $sensitive;
24+
class ExAppPreference implements JsonSerializable {
25+
private int $id;
26+
private string $userid;
27+
private string $appid;
28+
private string $configkey;
29+
private string $configvalue;
30+
private int $sensitive;
3731

38-
/**
39-
* @param array $params
40-
*/
4132
public function __construct(array $params = []) {
42-
$this->addType('userid', 'string');
43-
$this->addType('appid', 'string');
44-
$this->addType('configkey', 'string');
45-
$this->addType('configvalue', 'string');
46-
$this->addType('sensitive', 'integer');
33+
$this->id = isset($params['id']) ? (int)$params['id'] : 0;
34+
$this->userid = (string)($params['userid'] ?? '');
35+
$this->appid = (string)($params['appid'] ?? '');
36+
$this->configkey = (string)($params['configkey'] ?? '');
37+
$this->configvalue = (string)($params['configvalue'] ?? '');
38+
$this->sensitive = (int)($params['sensitive'] ?? 0);
39+
}
40+
41+
public function getId(): int {
42+
return $this->id;
43+
}
44+
45+
public function getUserid(): string {
46+
return $this->userid;
47+
}
48+
49+
public function getAppid(): string {
50+
return $this->appid;
51+
}
52+
53+
public function getConfigkey(): string {
54+
return $this->configkey;
55+
}
56+
57+
public function getConfigvalue(): string {
58+
return $this->configvalue;
59+
}
60+
61+
public function setConfigvalue(string $configValue): void {
62+
$this->configvalue = $configValue;
63+
}
64+
65+
public function getSensitive(): int {
66+
return $this->sensitive;
67+
}
4768

48-
if (isset($params['id'])) {
49-
$this->setId($params['id']);
50-
}
51-
if (isset($params['userid'])) {
52-
$this->setUserid($params['userid']);
53-
}
54-
if (isset($params['appid'])) {
55-
$this->setAppid($params['appid']);
56-
}
57-
if (isset($params['configkey'])) {
58-
$this->setConfigkey($params['configkey']);
59-
}
60-
if (isset($params['configvalue'])) {
61-
$this->setConfigvalue($params['configvalue']);
62-
}
63-
if (isset($params['sensitive'])) {
64-
$this->setSensitive($params['sensitive']);
65-
}
69+
public function setSensitive(int $sensitive): void {
70+
$this->sensitive = $sensitive;
6671
}
6772

6873
public function jsonSerialize(): array {
6974
return [
70-
'id' => $this->getId(),
71-
'user_id' => $this->getUserid(),
72-
'appid' => $this->getAppid(),
73-
'configkey' => $this->getConfigkey(),
74-
'configvalue' => $this->getConfigvalue(),
75-
'sensitive' => $this->getSensitive(),
75+
'id' => $this->id,
76+
'user_id' => $this->userid,
77+
'appid' => $this->appid,
78+
'configkey' => $this->configkey,
79+
'configvalue' => $this->configvalue,
80+
'sensitive' => $this->sensitive,
7681
];
7782
}
7883
}

0 commit comments

Comments
 (0)