Skip to content

Commit

Permalink
Merge pull request #6759 from nextcloud/allow-multiple-settings-and-s…
Browse files Browse the repository at this point in the history
…ections-per-app

Allow multiple settings and sections per app
  • Loading branch information
nickvergessen authored Oct 6, 2017
2 parents 4c54ca5 + 6292f66 commit 8e9505e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 18 deletions.
27 changes: 27 additions & 0 deletions lib/private/App/InfoParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ public function parse($file) {
if (!array_key_exists('providers', $array['activity'])) {
$array['activity']['providers'] = [];
}
if (!array_key_exists('settings', $array)) {
$array['settings'] = [];
}
if (!array_key_exists('admin', $array['settings'])) {
$array['settings']['admin'] = [];
}
if (!array_key_exists('admin-section', $array['settings'])) {
$array['settings']['admin-section'] = [];
}
if (!array_key_exists('personal', $array['settings'])) {
$array['settings']['personal'] = [];
}
if (!array_key_exists('personal-section', $array['settings'])) {
$array['settings']['personal-section'] = [];
}

if (array_key_exists('types', $array)) {
if (is_array($array['types'])) {
Expand Down Expand Up @@ -171,6 +186,18 @@ public function parse($file) {
) {
$array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin'];
}
if (isset($array['settings']['admin']) && !is_array($array['settings']['admin'])) {
$array['settings']['admin'] = [$array['settings']['admin']];
}
if (isset($array['settings']['admin-section']) && !is_array($array['settings']['admin-section'])) {
$array['settings']['admin-section'] = [$array['settings']['admin-section']];
}
if (isset($array['settings']['personal']) && !is_array($array['settings']['personal'])) {
$array['settings']['personal'] = [$array['settings']['personal']];
}
if (isset($array['settings']['personal-section']) && !is_array($array['settings']['personal-section'])) {
$array['settings']['personal-section'] = [$array['settings']['personal-section']];
}

if(!is_null($this->cache)) {
$this->cache->set($fileCacheKey, json_encode($array));
Expand Down
48 changes: 32 additions & 16 deletions lib/private/Settings/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,26 @@ public function __construct(
* @inheritdoc
*/
public function setupSettings(array $settings) {
if (isset($settings[IManager::KEY_ADMIN_SECTION])) {
$this->setupSectionEntry($settings[IManager::KEY_ADMIN_SECTION], 'admin');
if (!empty($settings[IManager::KEY_ADMIN_SECTION])) {
foreach ($settings[IManager::KEY_ADMIN_SECTION] as $className) {
$this->setupSectionEntry($className, 'admin');
}
}
if (isset($settings[IManager::KEY_ADMIN_SETTINGS])) {
$this->setupSettingsEntry($settings[IManager::KEY_ADMIN_SETTINGS], 'admin');
if (!empty($settings[IManager::KEY_ADMIN_SETTINGS])) {
foreach ($settings[IManager::KEY_ADMIN_SETTINGS] as $className) {
$this->setupSettingsEntry($className, 'admin');
}
}

if (isset($settings[IManager::KEY_PERSONAL_SECTION])) {
$this->setupSectionEntry($settings[IManager::KEY_PERSONAL_SECTION], 'personal');
if (!empty($settings[IManager::KEY_PERSONAL_SECTION])) {
foreach ($settings[IManager::KEY_PERSONAL_SECTION] as $className) {
$this->setupSectionEntry($className, 'personal');
}
}
if (isset($settings[IManager::KEY_PERSONAL_SETTINGS])) {
$this->setupSettingsEntry($settings[IManager::KEY_PERSONAL_SETTINGS], 'personal');
if (!empty($settings[IManager::KEY_PERSONAL_SETTINGS])) {
foreach ($settings[IManager::KEY_PERSONAL_SETTINGS] as $className) {
$this->setupSettingsEntry($className, 'personal');
}
}
}

Expand All @@ -153,18 +161,26 @@ public function setupSettings(array $settings) {
public function onAppDisabled($appId) {
$appInfo = \OC_App::getAppInfo($appId); // hello static legacy

if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) {
$this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\'));
if (!empty($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) {
foreach ($appInfo['settings'][IManager::KEY_ADMIN_SECTION] as $className) {
$this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($className, '\\'));
}
}
if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) {
$this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\'));
if (!empty($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) {
foreach ($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS] as $className) {
$this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($className, '\\'));
}
}

if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) {
$this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SECTION], '\\'));
if (!empty($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) {
foreach ($appInfo['settings'][IManager::KEY_PERSONAL_SECTION] as $className) {
$this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($className, '\\'));
}
}
if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) {
$this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS], '\\'));
if (!empty($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) {
foreach ($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS] as $className) {
$this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($className, '\\'));
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions tests/data/app/expected-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,11 @@
"filters": [],
"settings": [],
"providers": []
},
"settings": {
"admin": [],
"admin-section": [],
"personal": [],
"personal-section": []
}
}
4 changes: 2 additions & 2 deletions tests/lib/Settings/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function testSetupSettingsUpdate($type, $table) {
->method('add');

$this->manager->setupSettings([
$type => $className,
$type => [$className],
]);
}

Expand All @@ -174,7 +174,7 @@ public function testSetupSettingsAdd($type, $table) {
->method('update');

$this->manager->setupSettings([
$type => 'OCA\Files\Settings\Admin',
$type => ['OCA\Files\Settings\Admin'],
]);
}

Expand Down

0 comments on commit 8e9505e

Please sign in to comment.