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 shares to poll schema #3513

Merged
merged 27 commits into from
May 25, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
All notable changes to this project will be documented in this file.
##
## [7.1.0] - tbd
### !!! changed API structure, please refer to the documentation
### Fix
- fixed counting of orphaned votes
### Changes
- mainly performance improvements
- Changed API structure for polls, please refer to the documentation
### Performance
- Added an option to allow to add polls to the navigation (default)
- Limited polls inside the navigation to 6 items
Expand Down
14 changes: 10 additions & 4 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

return [
'routes' => [
['name' => 'public#get_acl', 'url' => '/s/{token}/acl', 'verb' => 'GET'],
['name' => 'public#vote_page', 'url' => '/s/{token}', 'verb' => 'GET'],
['name' => 'public#get_share', 'url' => '/s/{token}/share', 'verb' => 'GET'],
['name' => 'public#get_poll', 'url' => '/s/{token}/poll', 'verb' => 'GET'],
Expand Down Expand Up @@ -56,6 +57,9 @@

['name' => 'admin#list', 'url' => '/administration/polls', 'verb' => 'GET'],
['name' => 'admin#takeover', 'url' => '/administration/poll/{pollId}/takeover', 'verb' => 'PUT'],
['name' => 'admin#run_auto_reminder_job', 'url' => 'administration/autoreminder/run', 'verb' => 'GET'],
['name' => 'admin#run_janitor_job', 'url' => 'administration/janitor/run', 'verb' => 'GET'],
['name' => 'admin#run_notification_job', 'url' => 'administration/notification/run', 'verb' => 'GET'],

['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'page#index', 'url' => '/not-found', 'verb' => 'GET', 'postfix' => 'notfound'],
Expand Down Expand Up @@ -130,17 +134,19 @@

['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'],
['name' => 'user#get_acl', 'url' => '/acl', 'verb' => 'GET'],
['name' => 'user#write_preferences', 'url' => '/preferences', 'verb' => 'POST'],
['name' => 'user#get_preferences', 'url' => '/preferences', 'verb' => 'GET'],
['name' => 'user#get_calendars', 'url' => '/calendars', 'verb' => 'GET'],


// REST-API calls
['name' => 'user_api#get_acl', 'url' => '/api/v1.0/acl', 'verb' => 'GET'],
['name' => 'base_api#preflighted_cors', 'url' => '/api/v1.0/{path}', 'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']],
['name' => 'poll_api#list', 'url' => '/api/v1.0/polls', 'verb' => 'GET'],
['name' => 'poll_api#transfer_polls', 'url' => '/api/v1.0/polls/transfer/{sourceUser}/{destinationUser}', 'verb' => 'PUT'],
['name' => 'poll_api#transfer_poll', 'url' => '/api/v1.0/poll/{pollId}/transfer/{destinationUser}', 'verb' => 'PUT'],
['name' => 'poll_api#add', 'url' => '/api/v1.0/poll', 'verb' => 'POST'],
['name' => 'poll_api#get_acl', 'url' => '/api/v1.0/poll/{pollId}/acl', 'verb' => 'GET'],
['name' => 'poll_api#get', 'url' => '/api/v1.0/poll/{pollId}', 'verb' => 'GET'],
['name' => 'poll_api#update', 'url' => '/api/v1.0/poll/{pollId}', 'verb' => 'PUT'],
['name' => 'poll_api#delete', 'url' => '/api/v1.0/poll/{pollId}', 'verb' => 'DELETE'],
Expand Down
91 changes: 62 additions & 29 deletions docs/API_v1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,57 @@ Example calls:
```

### Update poll
Send the full or a partial structure.
`expire' field is set to 0 to make it an endless poll (without an expiration date). This field can be set to a date in the future to automatically close the poll on that date.
A poll can be closed immediately by using the endpoint `poll/{pollId}/close` and reopened by using `poll/{pollId}/reopen` or by setting `expire` to 0.
Send the full or a partial structure of "configuration" (see return strucure below).
`expire` field is set to 0 to make it an endless poll (without an expiration date). This field can be set to a date in the future to automatically close the poll on that date.
A poll can be closed immediately by using the endpoint `poll/{pollId}/close` or by setting `expire` to a negative number and reopened by using `poll/{pollId}/reopen` or by setting `expire` to 0.
```json
{
"poll": {
"title": "Changed Title",
"description": "Updated description",
"expire": 1,
"expire": 0,
"access": "private",
"anonymous": true,
"allowMaybe": true,
"allowComment": true,
"allowProposals": true,
"showResults": "never"
}
"showResults": "never",
"autoReminder": false,
"hideBookedUp": false,
"proposalsExpire": 0,
"useNo": true,
"maxVotesPerOption": 0,
"maxVotesPerUser": 0
}
}
```
## Return value
A poll newly created will look like this.
#### Notice: Only the attributes of the "configuration" section are changeable.

```json
{
"poll": {
"title": "New Poll",
"description": "",
"descriptionSafe": "",
"id": 1,
"type": "datePoll",
"configuration": {
"title": "New Poll",
"description": "Description of poll",
"access":"private",
"allowComment":false,
"allowMaybe":false,
"allowProposals":"",
"anonymous":false,
"autoReminder":false,
"expire":0,
"hideBookedUp":false,
"proposalsExpire":0,
"showResults":"always",
"useNo":false,
"maxVotesPerOption":0,
"maxVotesPerUser":0
},
"descriptionSafe": "Description of poll",
"owner": {
"userId": "username",
"displayName": "Username",
Expand All @@ -93,33 +118,41 @@ A poll newly created will look like this.
"icon":"icon-user",
"categories":[]
},
"access":"private",
"allowComment":false,
"allowMaybe":false,
"allowProposals":"",
"anonymous":false,
"autoReminder":false,
"created":1714078369,
"deleted":false,
"expire":0,
"hideBookedUp":false,
"proposalsExpire":0,
"showResults":"always",
"useNo":false,
"limits": {
"maxVotesPerOption":0,
"maxVotesPerUser":0
},
"status": {
"lastInteraction":1714078369
"lastInteraction":1714078369,
"created":1714078369,
"deleted":false,
"expired": false,
"relevandThreshold" : 1714078369
},
"currentUserStatus": {
"userRole":"owner",
"isLocked":false,
"isLoggedIn": true,
"isNoUser": false,
"isOwner": true,
"userId": "username",
"orphanedVotes":0,
"yesVotes":0,
"countVotes":0
}
"countVotes":0,
"shareToken": "",
"groupInvitations": {
"1": "Users",
"2": "Administrators",
},
},
"permissions": {
"addOptions": true,
"archive": true,
"comment": true,
"delete": true,
"edit": true,
"seeResults": true,
"seeUsernames": true,
"subscribe": true,
"view": true,
"vote": true
}
}
}
```
Expand Down
16 changes: 16 additions & 0 deletions lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
namespace OCA\Polls\Controller;

use OCA\Polls\AppConstants;
use OCA\Polls\Cron\AutoReminderCron;
use OCA\Polls\Cron\JanitorCron;
use OCA\Polls\Cron\NotificationCron;
use OCA\Polls\Service\PollService;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\JSONResponse;
Expand All @@ -46,6 +49,9 @@ public function __construct(
private IURLGenerator $urlGenerator,
private PollService $pollService,
private IEventDispatcher $eventDispatcher,
private AutoReminderCron $autoReminderCron,
private JanitorCron $janitorCron,
private NotificationCron $notificationCron,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -90,4 +96,14 @@ public function toggleArchive(int $pollId): JSONResponse {
public function delete(int $pollId): JSONResponse {
return $this->responseDeleteTolerant(fn () => $this->pollService->delete($pollId));
}

public function runAutoReminderJob(): JSONResponse {
return $this->response(fn () => $this->autoReminderCron->manuallyRun());
}
public function runJanitorJob(): JSONResponse {
return $this->response(fn () => $this->janitorCron->manuallyRun());
}
public function runNotificationJob(): JSONResponse {
return $this->response(fn () => $this->notificationCron->manuallyRun());
}
}
6 changes: 0 additions & 6 deletions lib/Controller/BasePublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@
namespace OCA\Polls\Controller;

use Closure;
use OCA\Polls\Db\ShareMapper;
use OCA\Polls\Exceptions\Exception;
use OCA\Polls\Exceptions\NoUpdatesException;
use OCA\Polls\Model\Acl;
use OCA\Polls\UserSession;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
Expand All @@ -44,9 +41,6 @@ class BasePublicController extends Controller {
public function __construct(
string $appName,
IRequest $request,
protected Acl $acl,
protected ShareMapper $shareMapper,
protected UserSession $userSession,
) {
parent::__construct($appName, $request);
}
Expand Down
8 changes: 2 additions & 6 deletions lib/Controller/CommentApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ public function add(int $pollId, string $comment): JSONResponse {
#[NoAdminRequired]
#[NoCSRFRequired]
public function delete(int $commentId): JSONResponse {
$comment = $this->commentService->get($commentId);

return $this->response(fn () => [
'comment' => $this->commentService->delete($comment)]);
'comment' => $this->commentService->delete($commentId)]);
}

/**
Expand All @@ -93,10 +91,8 @@ public function delete(int $commentId): JSONResponse {
#[NoAdminRequired]
#[NoCSRFRequired]
public function restore(int $commentId): JSONResponse {
$comment = $this->commentService->get($commentId);

return $this->response(fn () => [
'comment' => $this->commentService->delete($comment, true)
'comment' => $this->commentService->delete($commentId, true)
]);
}
}
8 changes: 2 additions & 6 deletions lib/Controller/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ public function add(int $pollId, string $message): JSONResponse {
*/
#[NoAdminRequired]
public function delete(int $commentId): JSONResponse {
$comment = $this->commentService->get($commentId);

return $this->response(fn () => [
'comment' => $this->commentService->delete($comment)
'comment' => $this->commentService->delete($commentId)
]);
}

Expand All @@ -84,10 +82,8 @@ public function delete(int $commentId): JSONResponse {
*/
#[NoAdminRequired]
public function restore(int $commentId): JSONResponse {
$comment = $this->commentService->get($commentId);

return $this->response(fn () => [
'comment' => $this->commentService->delete($comment, true)
'comment' => $this->commentService->delete($commentId, true)
]);
}
}
2 changes: 1 addition & 1 deletion lib/Controller/OptionApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function list(int $pollId): JSONResponse {
#[NoAdminRequired]
#[NoCSRFRequired]
public function add(int $pollId, int $timestamp = 0, string $pollOptionText = '', int $duration = 0): JSONResponse {
return $this->responseCreate(fn () => ['option' => $this->optionService->addForPoll($pollId, $timestamp, $pollOptionText, $duration)]);
return $this->responseCreate(fn () => ['option' => $this->optionService->add($pollId, $timestamp, $pollOptionText, $duration)]);
}


Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/OptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function list(int $pollId): JSONResponse {
*/
#[NoAdminRequired]
public function add(int $pollId, int $timestamp = 0, string $text = '', int $duration = 0): JSONResponse {
return $this->responseCreate(fn () => ['option' => $this->optionService->addForPoll($pollId, $timestamp, $text, $duration)]);
return $this->responseCreate(fn () => ['option' => $this->optionService->add($pollId, $timestamp, $text, $duration)]);
}

/**
Expand Down
13 changes: 5 additions & 8 deletions lib/Controller/PollApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

use OCA\Polls\AppConstants;
use OCA\Polls\Exceptions\Exception;
use OCA\Polls\Model\Acl;
use OCA\Polls\Model\Acl as Acl;
use OCA\Polls\Service\PollService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
Expand Down Expand Up @@ -90,9 +90,8 @@ public function get(int $pollId): JSONResponse {
#[CORS]
#[NoAdminRequired]
#[NoCSRFRequired]
public function getAcl(int $pollId): JSONResponse {
public function getAcl(): JSONResponse {
try {
$this->acl->setPollId($pollId);
return new JSONResponse(['acl' => $this->acl], Http::STATUS_OK);
} catch (DoesNotExistException $e) {
return new JSONResponse(['error' => 'Not found'], Http::STATUS_NOT_FOUND);
Expand Down Expand Up @@ -120,17 +119,15 @@ public function add(string $type, string $title): JSONResponse {
/**
* Update poll configuration
* @param int $pollId Poll id
* @param array $poll poll config
* @param array $pollConfiguration poll config
*/
#[CORS]
#[NoAdminRequired]
#[NoCSRFRequired]
public function update(int $pollId, array $poll): JSONResponse {
public function update(int $pollId, array $pollConfiguration): JSONResponse {
try {
$this->acl->setPollId($pollId, Acl::PERMISSION_POLL_EDIT);

return new JSONResponse([
'poll' => $this->pollService->update($pollId, $poll),
'poll' => $this->pollService->update($pollId, $pollConfiguration),
'acl' => $this->acl,
], Http::STATUS_OK);
} catch (DoesNotExistException $e) {
Expand Down
Loading
Loading