Simplify the settings module
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
4a319ef21a
commit
7d1fd1b49a
|
|
@ -13,7 +13,6 @@
|
||||||
namespace OCA\Registration\Controller;
|
namespace OCA\Registration\Controller;
|
||||||
|
|
||||||
use \OCP\IRequest;
|
use \OCP\IRequest;
|
||||||
use \OCP\AppFramework\Http\TemplateResponse;
|
|
||||||
use \OCP\AppFramework\Http\DataResponse;
|
use \OCP\AppFramework\Http\DataResponse;
|
||||||
use \OCP\AppFramework\Http;
|
use \OCP\AppFramework\Http;
|
||||||
use \OCP\AppFramework\Controller;
|
use \OCP\AppFramework\Controller;
|
||||||
|
|
@ -40,8 +39,6 @@ class SettingsController extends Controller {
|
||||||
$this->appName = $appName;
|
$this->appName = $appName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @AdminRequired
|
* @AdminRequired
|
||||||
*
|
*
|
||||||
|
|
@ -71,53 +68,25 @@ class SettingsController extends Controller {
|
||||||
$this->config->deleteAppValue($this->appName, 'registered_user_group');
|
$this->config->deleteAppValue($this->appName, 'registered_user_group');
|
||||||
return new DataResponse([
|
return new DataResponse([
|
||||||
'data' => [
|
'data' => [
|
||||||
'message' => (string) $this->l10n->t('Saved'),
|
'message' => $this->l10n->t('Saved'),
|
||||||
],
|
],
|
||||||
'status' => 'success'
|
'status' => 'success',
|
||||||
|
|
||||||
]);
|
]);
|
||||||
} elseif (in_array($registered_user_group, $group_id_list)) {
|
} elseif (in_array($registered_user_group, $group_id_list)) {
|
||||||
$this->config->setAppValue($this->appName, 'registered_user_group', $registered_user_group);
|
$this->config->setAppValue($this->appName, 'registered_user_group', $registered_user_group);
|
||||||
return new DataResponse([
|
return new DataResponse([
|
||||||
'data' => [
|
'data' => [
|
||||||
'message' => (string) $this->l10n->t('Saved'),
|
'message' => $this->l10n->t('Saved'),
|
||||||
],
|
],
|
||||||
'status' => 'success'
|
'status' => 'success',
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
return new DataResponse([
|
return new DataResponse([
|
||||||
'data' => [
|
'data' => [
|
||||||
'message' => (string) $this->l10n->t('No such group'),
|
'message' => $this->l10n->t('No such group'),
|
||||||
],
|
],
|
||||||
'status' => 'error'
|
'status' => 'error',
|
||||||
], Http::STATUS_NOT_FOUND);
|
], Http::STATUS_NOT_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @AdminRequired
|
|
||||||
*
|
|
||||||
* @return TemplateResponse
|
|
||||||
*/
|
|
||||||
public function displayPanel() {
|
|
||||||
// handle groups
|
|
||||||
$groups = $this->groupmanager->search('');
|
|
||||||
$group_id_list = [];
|
|
||||||
foreach ($groups as $group) {
|
|
||||||
$group_id_list[] = $group->getGid();
|
|
||||||
}
|
|
||||||
$current_value = $this->config->getAppValue($this->appName, 'registered_user_group', 'none');
|
|
||||||
|
|
||||||
// handle domains
|
|
||||||
$allowed_domains = $this->config->getAppValue($this->appName, 'allowed_domains', '');
|
|
||||||
|
|
||||||
// handle admin validation
|
|
||||||
$admin_approval_required = $this->config->getAppValue($this->appName, 'admin_approval_required', "no");
|
|
||||||
|
|
||||||
return new TemplateResponse('registration', 'admin', [
|
|
||||||
'groups' => $group_id_list,
|
|
||||||
'current' => $current_value,
|
|
||||||
'allowed' => $allowed_domains,
|
|
||||||
'approval_required' => $admin_approval_required
|
|
||||||
], '');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,80 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2017 Pellaeon Lin <pellaeon@hs.ntnu.edu.tw>
|
||||||
|
*
|
||||||
|
* @author Pellaeon Lin <pellaeon@hs.ntnu.edu.tw>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
namespace OCA\Registration\Settings;
|
namespace OCA\Registration\Settings;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\IConfig;
|
||||||
|
use OCP\IGroupManager;
|
||||||
use OCP\Settings\ISettings;
|
use OCP\Settings\ISettings;
|
||||||
|
|
||||||
use OCA\Registration\Controller\SettingsController;
|
|
||||||
|
|
||||||
class RegistrationSettings implements ISettings {
|
class RegistrationSettings implements ISettings {
|
||||||
public function getForm() {
|
/** @var IConfig */
|
||||||
$controller = \OC::$server->query(SettingsController::class);
|
private $config;
|
||||||
return $controller->displayPanel();
|
/** @var IGroupManager */
|
||||||
|
private $groupManager;
|
||||||
|
/** @var string */
|
||||||
|
protected $appName;
|
||||||
|
|
||||||
|
public function __construct(string $appName,
|
||||||
|
IConfig $config,
|
||||||
|
IGroupManager $groupManager) {
|
||||||
|
$this->appName = $appName;
|
||||||
|
$this->config = $config;
|
||||||
|
$this->groupManager = $groupManager;
|
||||||
|
$this->appName = $appName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSection() {
|
public function getForm(): TemplateResponse {
|
||||||
|
// handle groups
|
||||||
|
$groups = $this->groupManager->search('');
|
||||||
|
$groupIds = [];
|
||||||
|
foreach ($groups as $group) {
|
||||||
|
$groupIds[] = $group->getGid();
|
||||||
|
}
|
||||||
|
$assignedGroups = $this->config->getAppValue($this->appName, 'registered_user_group', 'none');
|
||||||
|
|
||||||
|
// handle domains
|
||||||
|
$allowedDomains = $this->config->getAppValue($this->appName, 'allowed_domains', '');
|
||||||
|
|
||||||
|
// handle admin validation
|
||||||
|
$adminApprovalRequired = $this->config->getAppValue($this->appName, 'admin_approval_required', "no");
|
||||||
|
|
||||||
|
return new TemplateResponse('registration', 'admin', [
|
||||||
|
'groups' => $groupIds,
|
||||||
|
'current' => $assignedGroups,
|
||||||
|
'allowed' => $allowedDomains,
|
||||||
|
'approval_required' => $adminApprovalRequired
|
||||||
|
], '');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSection(): string {
|
||||||
return 'additional';
|
return 'additional';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPriority() {
|
public function getPriority(): int {
|
||||||
return 50;
|
return 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Below for ownCloud
|
|
||||||
*/
|
|
||||||
public function getPanel() {
|
|
||||||
return $this->getForm();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSectionID() {
|
|
||||||
return $this->getSection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue