diff --git a/appinfo/info.xml b/appinfo/info.xml index af89eebd7..f3c90abc3 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -1,6 +1,5 @@ - + polls Polls A polls app, similar to doodle/dudle with the possibility to restrict access. @@ -26,24 +25,30 @@ - - OCA\Polls\Cron\NotificationCron + + OCA\Polls\Cron\NotificationCron OCA\Polls\Cron\JanitorCron - - - OCA\Polls\Command\Share\Add - OCA\Polls\Command\Share\Remove - - - - OCA\Polls\Migration\RemoveIndices - OCA\Polls\Migration\DeleteInvalidRecords + + + OCA\Polls\Command\Share\Add + OCA\Polls\Command\Share\Remove + + + OCA\Polls\Settings\AdminSection + OCA\Polls\Settings\PersonalSection + OCA\Polls\Settings\AdminSettings + OCA\Polls\Settings\PersonalSettings + + + + OCA\Polls\Migration\RemoveIndices + OCA\Polls\Migration\DeleteInvalidRecords - - OCA\Polls\Migration\CreateIndices + + OCA\Polls\Migration\CreateIndices - + Polls polls.page.index diff --git a/appinfo/routes.php b/appinfo/routes.php index 533236c7f..1f3c95989 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -87,6 +87,9 @@ ['name' => 'share#sendInvitation', 'url' => '/share/{token}/invite', 'verb' => 'POST'], ['name' => 'share#resolveGroup', 'url' => '/share/{token}/resolve', 'verb' => 'GET'], + ['name' => 'settings#getAppSettings', 'url' => '/settings/app', 'verb' => 'GET'], + ['name' => 'settings#writeAppSettings', 'url' => '/settings/app', 'verb' => 'POST'], + ['name' => 'subscription#get', 'url' => '/poll/{pollId}/subscription', 'verb' => 'GET'], ['name' => 'subscription#set', 'url' => '/poll/{pollId}/subscription', 'verb' => 'PUT'], ['name' => 'subscription#subscribe', 'url' => '/poll/{pollId}/subscribe', 'verb' => 'PUT'], @@ -97,11 +100,13 @@ ['name' => 'comment#delete', 'url' => '/comment/{commentId}', 'verb' => 'DELETE', 'postfix' => 'auth'], ['name' => 'system#user_search', 'url' => '/search/users/{query}', 'verb' => 'GET'], - ['name' => 'watch#watch_poll', 'url' => '/poll/{pollId}/watch', 'verb' => 'GET'], + ['name' => 'system#group_search', 'url' => '/groups/{query}', 'verb' => 'GET', 'postfix' => 'query'], + ['name' => 'system#group_search', 'url' => '/groups', 'verb' => 'GET', 'postfix' => 'all'], - ['name' => 'preferences#write', 'url' => '/preferences/write', 'verb' => 'POST'], - ['name' => 'preferences#get', 'url' => '/preferences/get', 'verb' => 'GET'], + ['name' => 'watch#watch_poll', 'url' => '/poll/{pollId}/watch', 'verb' => 'GET'], + ['name' => 'preferences#write', 'url' => '/preferences', 'verb' => 'POST'], + ['name' => 'preferences#get', 'url' => '/preferences', 'verb' => 'GET'], ['name' => 'preferences#get_calendars', 'url' => '/calendars', 'verb' => 'GET'], // REST-API calls diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php index 7d39a4cd8..21540b8f5 100644 --- a/lib/Controller/PollController.php +++ b/lib/Controller/PollController.php @@ -31,6 +31,7 @@ use OCA\Polls\Service\PollService; use OCA\Polls\Service\OptionService; use OCA\Polls\Model\Acl; +use OCA\Polls\Model\AppSettings; class PollController extends Controller { @@ -70,7 +71,12 @@ public function __construct( public function list(): DataResponse { return $this->response(function () { - return $this->pollService->list(); + // return $this->pollService->list(); + $appSettings = new AppSettings; + return [ + 'list' => $this->pollService->list(), + 'pollCreationAllowed' => $appSettings->getCreationAllowed(), + ]; }); } diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php new file mode 100644 index 000000000..ec079515e --- /dev/null +++ b/lib/Controller/SettingsController.php @@ -0,0 +1,66 @@ + + * + * @author René Gieling + * + * @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 . + * + */ + +namespace OCA\Polls\Controller; + +use OCP\IRequest; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\DataResponse; +use OCA\Polls\Service\SettingsService; + +class SettingsController extends Controller { + + /** @var SettingsService */ + private $settingsService; + + use ResponseHandle; + + public function __construct( + string $appName, + IRequest $request, + SettingsService $settingsService + ) { + parent::__construct($appName, $request); + $this->settingsService = $settingsService; + } + + /** + * Read app settings + * @NoAdminRequired + */ + public function getAppSettings(): DataResponse { + return $this->response(function (): array { + return ['appSettings' => $this->settingsService->getAppSettings()]; + }); + } + + /** + * Write app settings + */ + public function writeAppSettings(array $appSettings): DataResponse { + $this->settingsService->writeAppSettings($appSettings); + return $this->response(function (): array { + return ['appSettings' => $this->settingsService->getAppSettings()]; + }); + } +} diff --git a/lib/Controller/SystemController.php b/lib/Controller/SystemController.php index a00bdce68..b70ea789e 100644 --- a/lib/Controller/SystemController.php +++ b/lib/Controller/SystemController.php @@ -47,10 +47,23 @@ public function __construct( /** * Get a combined list of NC users, groups and contacts * @NoAdminRequired - * $query */ public function userSearch(string $query = ''): DataResponse { return new DataResponse(['siteusers' => $this->systemService->getSiteUsersAndGroups( $query)], Http::STATUS_OK); } + /** + * Get a combined list of NC groups + */ + public function groupAll(): DataResponse { + return new DataResponse(['groups' => $this->systemService->getGroups()], Http::STATUS_OK); + } + + /** + * Get a combined list of NC groups + */ + public function groupSearch(string $query = ''): DataResponse { + return new DataResponse(['groups' => $this->systemService->getGroups( + $query)], Http::STATUS_OK); + } } diff --git a/lib/Exceptions/InvalidUsernameException.php b/lib/Exceptions/InvalidUsernameException.php index 9fd0f5844..6ecfd70e0 100644 --- a/lib/Exceptions/InvalidUsernameException.php +++ b/lib/Exceptions/InvalidUsernameException.php @@ -28,7 +28,6 @@ class InvalidUsernameException extends Exception { /** * InvalidUsernameException Constructor - * @param string $e exception message */ public function __construct(string $e = 'Username not allowed') { parent::__construct($e, Http::STATUS_FORBIDDEN); diff --git a/lib/Migration/Version030000Date20210704120000.php b/lib/Migration/Version030000Date20210704120000.php index 7792f3d12..a4463ec2f 100644 --- a/lib/Migration/Version030000Date20210704120000.php +++ b/lib/Migration/Version030000Date20210704120000.php @@ -75,7 +75,7 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op TableSchema::createOrUpdateSchema($schema, $output); // remove old migration entries from versions prior to polls 3.x // including migration versions from test releases - // theoretically, only this migration should be existen. If not, no matter + // theoretically, only this migration should be existent. If not, no matter TableSchema::removeObsoleteMigrations($this->connection, $output); $this->fixVotes->run($output); diff --git a/lib/Model/Acl.php b/lib/Model/Acl.php index 1c9f4bd26..78af4b819 100644 --- a/lib/Model/Acl.php +++ b/lib/Model/Acl.php @@ -54,10 +54,15 @@ class Acl implements JsonSerializable { public const PERMISSION_COMMENT_ADD = 'comment'; public const PERMISSION_OPTIONS_ADD = 'add_options'; public const PERMISSION_VOTE_EDIT = 'vote'; + public const PERMISSION_PUBLIC_SHARES = 'publicShares'; + public const PERMISSION_ALL_ACCESS = 'allAccess'; /** @var IUserManager */ private $userManager; + /** @var AppSettings */ + private $appSettings; + /** @var IGroupManager */ private $groupManager; @@ -90,6 +95,7 @@ public function __construct( $this->shareMapper = $shareMapper; $this->poll = new Poll; $this->share = new Share; + $this->appSettings = new AppSettings; } @@ -220,6 +226,11 @@ public function getIsAllowed(string $permission): bool { case self::PERMISSION_VOTE_EDIT: return !$this->poll->getExpired() && $this->share->getType() !== Share::TYPE_PUBLIC; + case self::PERMISSION_ALL_ACCESS: + return $this->appSettings->getAllAccessAllowed(); + + case self::PERMISSION_PUBLIC_SHARES: + return $this->appSettings->getPublicSharesAllowed(); } return false; @@ -234,10 +245,12 @@ public function request(string $permission): void { public function jsonSerialize(): array { return [ 'allowAddOptions' => $this->getIsAllowed(self::PERMISSION_OPTIONS_ADD), + 'allowAllAccess' => $this->getIsAllowed(self::PERMISSION_ALL_ACCESS), 'allowArchive' => $this->getIsAllowed(self::PERMISSION_POLL_ARCHIVE), 'allowComment' => $this->getIsAllowed(self::PERMISSION_COMMENT_ADD), 'allowDelete' => $this->getIsAllowed(self::PERMISSION_POLL_DELETE), 'allowEdit' => $this->getIsAllowed(self::PERMISSION_POLL_EDIT), + 'allowPublicShares' => $this->getIsAllowed(self::PERMISSION_PUBLIC_SHARES), 'allowSeeResults' => $this->getIsAllowed(self::PERMISSION_POLL_RESULTS_VIEW), 'allowSeeUsernames' => $this->getIsAllowed(self::PERMISSION_POLL_USERNAMES_VIEW), 'allowSubscribe' => $this->getIsAllowed(self::PERMISSION_POLL_SUBSCRIBE), diff --git a/lib/Model/AppSettings.php b/lib/Model/AppSettings.php new file mode 100644 index 000000000..6c53097dc --- /dev/null +++ b/lib/Model/AppSettings.php @@ -0,0 +1,169 @@ + + * + * @author René Gieling + * + * @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 . + * + */ + +namespace OCA\Polls\Model; + +use JsonSerializable; +use OCP\IConfig; +use OCP\IGroupManager; +use OCP\IUserSession; +use OCA\Polls\AppInfo\Application; + +class AppSettings implements JsonSerializable { + private const APP_NAME = 'polls'; + + /** @var IConfig */ + private $config; + + /** @var IGroupManager */ + private $groupManager; + + /** @var string */ + private $userId = ''; + + /** @var bool */ + private $allowPublicShares = true; + + /** @var bool */ + private $allowAllAccess = true; + + /** @var bool */ + private $allowPollCreation = true; + + /** @var array */ + private $publicSharesGroups = []; + + /** @var array */ + private $allAccessGroups = []; + + /** @var array */ + private $pollCreationGroups = []; + + public function __construct() { + $this->config = self::getContainer()->query(IConfig::class); + $this->userId = self::getContainer()->query(IUserSession::class)->getUser()->getUID(); + $this->groupManager = self::getContainer()->query(IGroupManager::class); + } + + // Getters + public function getAllowPublicShares(): bool { + return !!$this->config->getAppValue(self::APP_NAME, 'allowPublicShares'); + } + + public function getAllowAllAccess(): bool { + return !!$this->config->getAppValue(self::APP_NAME, 'allowAllAccess'); + } + + public function getAllowPollCreation(): bool { + return !!$this->config->getAppValue(self::APP_NAME, 'allowPollCreation'); + } + + public function getPublicSharesGroups(): array { + return json_decode($this->config->getAppValue(self::APP_NAME, 'publicSharesGroups')); + } + + public function getAllAccessGroups(): array { + return json_decode($this->config->getAppValue(self::APP_NAME, 'allAccessGroups')); + } + + public function getPollCreationGroups(): array { + return json_decode($this->config->getAppValue(self::APP_NAME, 'pollCreationGroups')); + } + + // Checks + public function getCreationAllowed() { + return $this->getAllowPollCreation() || $this->isMember($this->getPollCreationGroups()); + } + + public function getAllAccessAllowed() { + return $this->getAllowAllAccess() || $this->isMember($this->getAllAccessGroups()); + } + + public function getPublicSharesAllowed() { + return $this->getAllowPublicShares() || $this->isMember($this->getPublicSharesGroups()); + } + + // Setters + public function setAllowPublicShares(bool $value) { + $this->config->setAppValue(self::APP_NAME, 'allowPublicShares', strval($value)); + } + + public function setAllowAllAccess(bool $value) { + $this->config->setAppValue(self::APP_NAME, 'allowAllAccess', strval($value)); + } + + public function setAllowPollCreation(bool $value) { + $this->config->setAppValue(self::APP_NAME, 'allowPollCreation', strval($value)); + } + + public function setPublicSharesGroups(array $value) { + $this->config->setAppValue(self::APP_NAME, 'publicSharesGroups', json_encode($value)); + } + + public function setAllAccessGroups(array $value) { + $this->config->setAppValue(self::APP_NAME, 'allAccessGroups', json_encode($value)); + } + + public function setPollCreationGroups(array $value) { + $this->config->setAppValue(self::APP_NAME, 'pollCreationGroups', json_encode($value)); + } + + public function jsonSerialize() { + // convert group ids to group objects + $publicSharesGroups = []; + $allAccessGroups = []; + $pollCreationGroups = []; + + foreach ($this->getPublicSharesGroups() as $group) { + $publicSharesGroups[] = new Group($group); + } + foreach ($this->getAllAccessGroups() as $group) { + $allAccessGroups[] = new Group($group); + } + foreach ($this->getPollCreationGroups() as $group) { + $pollCreationGroups[] = new Group($group); + } + return [ + 'allowPublicShares' => $this->getAllowPublicShares(), + 'allowAllAccess' => $this->getAllowAllAccess(), + 'allowPollCreation' => $this->getAllowPollCreation(), + 'allAccessGroups' => $allAccessGroups, + 'pollCreationGroups' => $pollCreationGroups, + 'publicSharesGroups' => $publicSharesGroups, + ]; + } + + private function isMember(array $groups) { + foreach ($groups as $GID) { + if ($this->groupManager->isInGroup($this->userId, $GID)) { + return true; + } + } + return false; + } + + protected static function getContainer() { + $app = \OC::$server->query(Application::class); + return $app->getContainer(); + } +} diff --git a/lib/Service/CalendarService.php b/lib/Service/CalendarService.php index 99997a0ad..ddb453a31 100644 --- a/lib/Service/CalendarService.php +++ b/lib/Service/CalendarService.php @@ -57,9 +57,6 @@ public function __construct( /** * getEvents - get events from the user's calendars inside given timespan * - * @param DateTime $from - * @param DateTime $to - * * @return CalendarEvent[] * * @psalm-return list diff --git a/lib/Service/LogService.php b/lib/Service/LogService.php index 78ad090a4..7e307a5fd 100644 --- a/lib/Service/LogService.php +++ b/lib/Service/LogService.php @@ -46,8 +46,6 @@ public function __construct( /** * Log poll activity - * - * @param null|string $userId */ public function setLog(int $pollId, string $messageId, ?string $userId = null): ?Log { $this->log = new Log(); diff --git a/lib/Service/NotificationService.php b/lib/Service/NotificationService.php index 61af37044..b2680165f 100644 --- a/lib/Service/NotificationService.php +++ b/lib/Service/NotificationService.php @@ -63,19 +63,6 @@ public function sendInvitation(int $pollId, string $recipient): bool { return true; } - /** - * create a notification - * - * @param array $params - * List of parameters sent to the notification - * following types MUST be defined in the §params array: - * msgId => Type for setSubject - * objectType => Type for setObject - * objectValue => Value for setObject - * recipient => the recipient of the notification - * $params will be set as Subject value - */ - public function createNotification(array $params = []): bool { $notification = $this->notificationManager->createNotification(); $notification->setApp(self::APP_ID) diff --git a/lib/Service/OptionService.php b/lib/Service/OptionService.php index 9db06f2cc..d83a3531d 100644 --- a/lib/Service/OptionService.php +++ b/lib/Service/OptionService.php @@ -238,10 +238,6 @@ public function confirm(int $optionId): Option { /** * Make a sequence of date poll options - * @param int $optionId - * @param int $step - The step for creating the sequence - * @param string $unit - The timeunit (year, month, ...) - * @param int $amount - Number of sequence items to create * * @return Option[] * @@ -291,9 +287,6 @@ public function sequence(int $optionId, int $step, string $unit, int $amount): a /** * Shift all date options - * @param int $pollId - * @param int $step - The step for creating the sequence - * @param string $unit - The timeunit (year, month, ...) * * @return Option[] * @@ -410,9 +403,6 @@ public function setOrder(int $optionId, int $newOrder): array { /** * moveModifier - evaluate new order depending on the old and * the new position of a moved array item - * @param int $moveFrom - old position of the moved item - * @param int $moveTo - target posotion of the moved item - * @param int $currentPosition - current position of the current item * * @return int - The modified new new position of the current item */ diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php index 11bc500e0..a74392648 100644 --- a/lib/Service/PollService.php +++ b/lib/Service/PollService.php @@ -217,6 +217,10 @@ public function update(int $pollId, array $poll): Poll { throw new EmptyTitleException('Title must not be empty'); } + if (isset($poll['access']) && $poll['access'] === (Poll::ACCESS_PUBLIC)) { + $this->acl->request(Acl::PERMISSION_ALL_ACCESS); + } + // Set the expiry time to the actual servertime to avoid an // expiry misinterpration when using acl if (isset($poll['expire']) && $poll['expire'] < 0) { diff --git a/lib/Service/PreferencesService.php b/lib/Service/PreferencesService.php index a100e1ecf..5cd650024 100644 --- a/lib/Service/PreferencesService.php +++ b/lib/Service/PreferencesService.php @@ -25,12 +25,16 @@ use OCA\Polls\Exceptions\NotAuthorizedException; use OCP\AppFramework\Db\DoesNotExistException; +use OCP\IConfig; use OCA\Polls\Db\Preferences; use OCA\Polls\Db\PreferencesMapper; class PreferencesService { + /** @var IConfig */ + private $config; + /** @var PreferencesMapper */ private $preferencesMapper; @@ -42,14 +46,20 @@ class PreferencesService { public function __construct( ?string $UserId, + IConfig $config, PreferencesMapper $preferencesMapper ) { $this->userId = $UserId; + $this->config = $config; $this->preferencesMapper = $preferencesMapper; + $this->load(); + } + + public function load() { try { $this->preferences = $this->preferencesMapper->find($this->userId); } catch (DoesNotExistException $e) { - if ($UserId) { + if ($this->userId) { $this->preferences = new Preferences(); $this->preferences->setUserId($this->userId); $this->preferences->setPreferences(''); @@ -59,6 +69,7 @@ public function __construct( } } } + /** * Read all preferences * diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php new file mode 100644 index 000000000..59eaa665d --- /dev/null +++ b/lib/Service/SettingsService.php @@ -0,0 +1,74 @@ + + * + * @author René Gieling + * + * @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 . + * + */ + +namespace OCA\Polls\Service; + +use OCP\IConfig; +use OCA\Polls\Model\AppSettings; +use OCA\Polls\Model\Group; +use OCA\Polls\AppInfo\Application; + +class SettingsService { + + /** @var IConfig */ + private $config; + + /** @var AppSettings */ + private $appSettings; + + /** @var String */ + private $userId; + + public function __construct( + ?string $UserId, + IConfig $config + ) { + $this->userId = $UserId; + $this->config = $config; + $this->appSettings = new AppSettings; + } + + /** + * Get app settings with extended group information + */ + public function getAppSettings() { + return $this->appSettings; + } + + /** + * Write app settings + */ + public function writeAppSettings(array $settingsArray): void { + $this->appSettings->setAllowPublicShares($settingsArray['allowPublicShares']); + $this->appSettings->setAllowAllAccess($settingsArray['allowAllAccess']); + $this->appSettings->setAllowPollCreation($settingsArray['allowPollCreation']); + $this->appSettings->setAllAccessGroups(array_column($settingsArray['allAccessGroups'], 'id')); + $this->appSettings->setPublicSharesGroups(array_column($settingsArray['publicSharesGroups'], 'id')); + $this->appSettings->setPollCreationGroups(array_column($settingsArray['pollCreationGroups'], 'id')); + } + + protected static function getContainer() { + $app = \OC::$server->query(Application::class); + return $app->getContainer(); + } +} diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index f2dec1823..a10e961e1 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -244,7 +244,9 @@ private function create(int $pollId, UserGroupClass $userGroup, bool $preventInv public function add(int $pollId, string $type, string $userId = ''): Share { $this->acl->setPollId($pollId, Acl::PERMISSION_POLL_EDIT); - if ($type !== UserGroupClass::TYPE_PUBLIC) { + if ($type === UserGroupClass::TYPE_PUBLIC) { + $this->acl->request(ACL::PERMISSION_PUBLIC_SHARES); + } else { try { $this->shareMapper->findByPollAndUser($pollId, $userId); throw new ShareAlreadyExistsException; diff --git a/lib/Service/SystemService.php b/lib/Service/SystemService.php index fe99f1aa1..1e6087510 100644 --- a/lib/Service/SystemService.php +++ b/lib/Service/SystemService.php @@ -79,8 +79,8 @@ public static function validateEmailAddress(string $emailAddress, bool $emptyIsV /** * Get a list of users - * @param string $query - * @param string[] $skip + * + * @return User[] */ public static function getSiteUsers(string $query = '', array $skip = []): array { $users = []; @@ -92,6 +92,19 @@ public static function getSiteUsers(string $query = '', array $skip = []): array return $users; } + /** + * Get a list of groups + * + * @return Group[] + */ + public function getGroups(string $query = ''): array { + $groups = Group::search($query); + return $groups; + if ($query === '') { + return []; + } + } + /** * Get a combined list of users, groups, circles, contact groups and contacts * diff --git a/lib/Settings/AdminSection.php b/lib/Settings/AdminSection.php new file mode 100644 index 000000000..a8ea82eb9 --- /dev/null +++ b/lib/Settings/AdminSection.php @@ -0,0 +1,58 @@ + + * + * @author René Gieling + * + * @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 . + * + */ + +namespace OCA\Polls\Settings; + +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Settings\IIconSection; + +class AdminSection implements IIconSection { + + /** @var IL10N */ + private $trans; + + /** @var IURLGenerator */ + private $urlGenerator; + + public function __construct(IL10N $trans, IURLGenerator $urlGenerator) { + $this->trans = $trans; + $this->urlGenerator = $urlGenerator; + } + + public function getID(): string { + return 'polls-admin'; + } + + public function getName(): string { + return $this->trans->t('Polls'); + } + + public function getPriority(): int { + return 80; + } + + public function getIcon(): string { + return $this->urlGenerator->imagePath('polls', 'polls-black.svg'); + } +} diff --git a/lib/Settings/AdminSettings.php b/lib/Settings/AdminSettings.php new file mode 100644 index 000000000..8074ec220 --- /dev/null +++ b/lib/Settings/AdminSettings.php @@ -0,0 +1,41 @@ + + * + * @author René Gieling + * + * @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 . + * + */ + +namespace OCA\Polls\Settings; + +use OCP\AppFramework\Http\TemplateResponse; +use OCP\Settings\ISettings; + +class AdminSettings implements ISettings { + public function getForm(): TemplateResponse { + return new TemplateResponse('polls', 'admin', []); + } + + public function getSection(): string { + return 'polls-admin'; + } + + public function getPriority():int { + return 50; + } +} diff --git a/lib/Settings/PersonalSection.php b/lib/Settings/PersonalSection.php new file mode 100644 index 000000000..c7951f5b6 --- /dev/null +++ b/lib/Settings/PersonalSection.php @@ -0,0 +1,58 @@ + + * + * @author René Gieling + * + * @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 . + * + */ + +namespace OCA\Polls\Settings; + +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Settings\IIconSection; + +class PersonalSection implements IIconSection { + + /** @var IL10N */ + private $trans; + + /** @var IURLGenerator */ + private $urlGenerator; + + public function __construct(IL10N $trans, IURLGenerator $urlGenerator) { + $this->trans = $trans; + $this->urlGenerator = $urlGenerator; + } + + public function getID(): string { + return 'polls'; + } + + public function getName(): string { + return $this->trans->t('Polls'); + } + + public function getPriority(): int { + return 80; + } + + public function getIcon(): string { + return $this->urlGenerator->imagePath('polls', 'polls-black.svg'); + } +} diff --git a/lib/Settings/PersonalSettings.php b/lib/Settings/PersonalSettings.php new file mode 100644 index 000000000..4847bdf5e --- /dev/null +++ b/lib/Settings/PersonalSettings.php @@ -0,0 +1,41 @@ + + * + * @author René Gieling + * + * @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 . + * + */ + +namespace OCA\Polls\Settings; + +use OCP\AppFramework\Http\TemplateResponse; +use OCP\Settings\ISettings; + +class PersonalSettings implements ISettings { + public function getForm(): TemplateResponse { + return new TemplateResponse('polls', 'settings', []); + } + + public function getSection(): string { + return 'polls'; + } + + public function getPriority(): int { + return 50; + } +} diff --git a/src/js/App.vue b/src/js/App.vue index 776d7f865..2cdf4d900 100644 --- a/src/js/App.vue +++ b/src/js/App.vue @@ -243,7 +243,7 @@ export default { .app-content { display: flex; flex-direction: column; - padding: 0 8px 0 40px; + padding: 4px 8px 0 40px; min-width: 320px; } diff --git a/src/js/adminSettings.js b/src/js/adminSettings.js new file mode 100644 index 000000000..10a55121d --- /dev/null +++ b/src/js/adminSettings.js @@ -0,0 +1,59 @@ +/* jshint esversion: 6 */ +/** + * @copyright Copyright (c) 2018 René Gieling + * + * @author René Gieling + * + * @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 . + * + */ + +import Vue from 'vue' +import Vuex, { Store } from 'vuex' +import appSettings from './store/modules/appSettings' +import { translate, translatePlural } from '@nextcloud/l10n' + +import AdminSettingsPage from './views/AdminSettingsPage' +import ButtonDiv from './components/Base/ButtonDiv' + +// /* eslint-disable-next-line camelcase, no-undef */ +// __webpack_nonce__ = btoa(getRequestToken()) +// /* eslint-disable-next-line camelcase, no-undef */ +// __webpack_public_path__ = generateFilePath('polls', '', 'js/') + +Vue.prototype.t = translate +Vue.prototype.n = translatePlural + +Vue.config.debug = process.env.NODE_ENV !== 'production' +Vue.config.devTools = process.env.NODE_ENV !== 'production' +// eslint-disable-next-line vue/match-component-file-name +Vue.component('ButtonDiv', ButtonDiv) + +Vue.use(Vuex) + +const store = new Store({ + modules: { + appSettings, + }, + strict: process.env.NODE_ENV !== 'production', +}) + +/* eslint-disable-next-line no-new */ +new Vue({ + el: '#admin_settings', + store, + render: (h) => h(AdminSettingsPage), +}) diff --git a/src/js/components/Actions/ActionChangeView.vue b/src/js/components/Actions/ActionChangeView.vue index 26a494a4c..2cd4cdc68 100644 --- a/src/js/components/Actions/ActionChangeView.vue +++ b/src/js/components/Actions/ActionChangeView.vue @@ -60,10 +60,13 @@ export default { computed: { ...mapState({ pollType: (state) => state.poll.type, + manualViewDatePoll: (state) => state.settings.manualViewDatePoll, + manualViewTextPoll: (state) => state.settings.manualViewTextPoll, }), ...mapGetters({ - viewMode: 'settings/viewMode', + viewMode: 'poll/viewMode', + getNextViewMode: 'poll/getNextViewMode', }), caption() { @@ -84,10 +87,17 @@ export default { }, methods: { + changeView() { + if (this.pollType === 'datePoll') { + this.$store.commit('settings/setViewDatePoll', this.manualViewDatePoll ? '' : this.getNextViewMode) + } else if (this.pollType === 'textPoll') { + this.$store.commit('settings/setViewTextPoll', this.manualViewTextPoll ? '' : this.getNextViewMode) + } + }, clickAction() { emit('transitions-off', 500) - this.$store.dispatch('settings/changeView') + this.changeView() }, }, } diff --git a/src/js/components/Navigation/PollNavigationItems.vue b/src/js/components/Navigation/PollNavigationItems.vue index bdfd535ee..e799db091 100644 --- a/src/js/components/Navigation/PollNavigationItems.vue +++ b/src/js/components/Navigation/PollNavigationItems.vue @@ -26,7 +26,7 @@ :to="{name: 'vote', params: {id: poll.id}}" :class="{ closed: closed }">