Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add admin page for polls #1919

Merged
merged 21 commits into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0"?>
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<id>polls</id>
<name>Polls</name>
<summary>A polls app, similar to doodle/dudle with the possibility to restrict access.</summary>
Expand All @@ -26,24 +25,30 @@
<php min-version="7.3"/>
<nextcloud min-version="21" max-version="22" />
</dependencies>
<background-jobs>
<job>OCA\Polls\Cron\NotificationCron</job>
<background-jobs>
<job>OCA\Polls\Cron\NotificationCron</job>
<job>OCA\Polls\Cron\JanitorCron</job>
</background-jobs>
<commands>
<command>OCA\Polls\Command\Share\Add</command>
<command>OCA\Polls\Command\Share\Remove</command>
</commands>
<repair-steps>
<pre-migration>
<step>OCA\Polls\Migration\RemoveIndices</step>
<step>OCA\Polls\Migration\DeleteInvalidRecords</step>
</background-jobs>
<commands>
<command>OCA\Polls\Command\Share\Add</command>
<command>OCA\Polls\Command\Share\Remove</command>
</commands>
<settings>
<admin-section>OCA\Polls\Settings\AdminSection</admin-section>
<personal-section>OCA\Polls\Settings\PersonalSection</personal-section>
<admin>OCA\Polls\Settings\AdminSettings</admin>
<personal>OCA\Polls\Settings\PersonalSettings</personal>
</settings>
<repair-steps>
<pre-migration>
<step>OCA\Polls\Migration\RemoveIndices</step>
<step>OCA\Polls\Migration\DeleteInvalidRecords</step>
</pre-migration>
<post-migration>
<step>OCA\Polls\Migration\CreateIndices</step>
<post-migration>
<step>OCA\Polls\Migration\CreateIndices</step>
</post-migration>
</repair-steps>
<navigations>
<navigations>
<navigation>
<name>Polls</name>
<route>polls.page.index</route>
Expand Down
11 changes: 8 additions & 3 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion lib/Controller/PollController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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(),
];
});
}

Expand Down
66 changes: 66 additions & 0 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
*
* @author René Gieling <[email protected]>
*
* @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\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()];
});
}
}
15 changes: 14 additions & 1 deletion lib/Controller/SystemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
1 change: 0 additions & 1 deletion lib/Exceptions/InvalidUsernameException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/Version030000Date20210704120000.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions lib/Model/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -90,6 +95,7 @@ public function __construct(
$this->shareMapper = $shareMapper;
$this->poll = new Poll;
$this->share = new Share;
$this->appSettings = new AppSettings;
}


Expand Down Expand Up @@ -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;
Expand All @@ -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),
Expand Down
Loading