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

Migrate vuex to pinia #3575

Merged
merged 11 commits into from
Jun 23, 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: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<name>Polls</name>
<summary>A polls app, similar to Doodle/Dudle with the possibility to restrict access.</summary>
<description>A polls app, similar to Doodle/Dudle with the possibility to restrict access (members, certain groups/users, hidden and public).</description>
<version>7.1.0-beta5</version>
<version>8.0.0-alpha1</version>
<licence>agpl</licence>
<author>Vinzenz Rosenkranz</author>
<author>René Gieling</author>
Expand Down
5 changes: 5 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
return [
'routes' => [
['name' => 'public#get_acl', 'url' => '/s/{token}/acl', 'verb' => 'GET'],
['name' => 'public#get_session', 'url' => '/s/{token}/session', '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 @@ -51,6 +52,7 @@
['name' => 'page#vote', 'url' => '/vote/{id}', 'verb' => 'GET'],

['name' => 'poll#list', 'url' => '/polls', 'verb' => 'GET'],
['name' => 'poll#get_full', 'url' => '/poll/{pollId}', 'verb' => 'GET'],
['name' => 'poll#get', 'url' => '/poll/{pollId}/poll', 'verb' => 'GET'],
['name' => 'poll#add', 'url' => '/poll/add', 'verb' => 'POST'],
['name' => 'poll#update', 'url' => '/poll/{pollId}', 'verb' => 'PUT'],
Expand Down Expand Up @@ -118,18 +120,21 @@
['name' => 'watch#watch_poll', 'url' => '/poll/{pollId}/watch', 'verb' => 'GET'],

['name' => 'user#get_acl', 'url' => '/acl', 'verb' => 'GET'],
['name' => 'user#get_session', 'url' => '/session', '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' => 'user_api#get_session', 'url' => '/session', '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_full', 'url' => '/api/v1.0/poll/{pollId}', '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
32 changes: 31 additions & 1 deletion lib/Controller/PollApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
use OCA\Polls\AppConstants;
use OCA\Polls\Exceptions\Exception;
use OCA\Polls\Model\Acl as Acl;
use OCA\Polls\Service\CommentService;
use OCA\Polls\Service\OptionService;
use OCA\Polls\Service\PollService;
use OCA\Polls\Service\ShareService;
use OCA\Polls\Service\SubscriptionService;
use OCA\Polls\Service\VoteService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\CORS;
Expand All @@ -28,7 +33,12 @@ public function __construct(
string $appName,
IRequest $request,
private Acl $acl,
private PollService $pollService
private CommentService $commentService,
private PollService $pollService,
private OptionService $optionService,
private ShareService $shareService,
private SubscriptionService $subscriptionService,
private VoteService $voteService,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -66,6 +76,26 @@ public function get(int $pollId): JSONResponse {
}
}

/**
* get complete poll
* @param int $pollId Poll id
*/
#[CORS]
#[NoAdminRequired]
#[NoCSRFRequired]
public function getFull(int $pollId): JSONResponse {
return $this->response(fn () => [
'poll' => $this->pollService->get($pollId),
'options' => $this->optionService->list($pollId),
'votes' => $this->voteService->list($pollId),
'comments' => $this->commentService->list($pollId),
'shares' => $this->shareService->list($pollId),
'subscribed' => $this->subscriptionService->get($pollId),
'acl' => $this->acl,
]);
}


/**
* get acl for poll
* @param $pollId Poll id
Expand Down
28 changes: 26 additions & 2 deletions lib/Controller/PollController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@

namespace OCA\Polls\Controller;

use OCA\Polls\Db\Poll;
use OCA\Polls\Model\Acl as Acl;
use OCA\Polls\Model\Settings\AppSettings;
use OCA\Polls\Service\CommentService;
use OCA\Polls\Service\MailService;
use OCA\Polls\Service\OptionService;
use OCA\Polls\Service\PollService;
use OCA\Polls\Service\ShareService;
use OCA\Polls\Service\SubscriptionService;
use OCA\Polls\Service\VoteService;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
Expand All @@ -30,6 +33,10 @@ public function __construct(
private MailService $mailService,
private OptionService $optionService,
private PollService $pollService,
private VoteService $voteService,
private CommentService $commentService,
private SubscriptionService $subscriptionService,
private ShareService $shareService,
) {
parent::__construct($appName, $request);
}
Expand All @@ -52,7 +59,7 @@ public function list(): JSONResponse {
}

/**
* get complete poll
* get poll
* @param int $pollId Poll id
*/
#[NoAdminRequired]
Expand All @@ -63,6 +70,23 @@ public function get(int $pollId): JSONResponse {
]);
}

/**
* get complete poll
* @param int $pollId Poll id
*/
#[NoAdminRequired]
public function getFull(int $pollId): JSONResponse {
return $this->response(fn () => [
'poll' => $this->pollService->get($pollId),
'options' => $this->optionService->list($pollId),
'votes' => $this->voteService->list($pollId),
'comments' => $this->commentService->list($pollId),
'shares' => $this->shareService->list($pollId),
'subscribed' => $this->subscriptionService->get($pollId),
'acl' => $this->acl,
]);
}

/**
* Add poll
* @param string $title Poll title
Expand Down
23 changes: 22 additions & 1 deletion lib/Controller/PublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,19 @@ public function getPoll(): JSONResponse {
return $this->response(function () {
return [
'poll' => $this->pollService->get($this->userSession->getShare()->getPollId()),
'options' => $this->optionService->list($this->userSession->getShare()->getPollId()),
'votes' => $this->voteService->list($this->userSession->getShare()->getPollId()),
'comments' => $this->commentService->list($this->userSession->getShare()->getPollId()),
'shares' => $this->shareService->list($this->userSession->getShare()->getPollId()),
'subscribed' => $this->subscriptionService->get($this->userSession->getShare()->getPollId()),
'acl' => $this->acl,
];
});
}

/**
* get complete poll via token
* get acl for user
* @deprecated 8.0.0 Use getSession instead
*/
#[PublicPage]
#[ShareTokenRequired]
Expand All @@ -97,6 +103,21 @@ public function getAcl(): JSONResponse {
]);
}

/**
* get session information
*/
#[PublicPage]
#[ShareTokenRequired]
public function getSession(): JSONResponse {
return $this->response(fn () => [
'token' => $this->request->getParam('token'),
'currentUser' => $this->userSession->getUser(),
'appPermissions' => $this->acl->getPermissionsArray(),
'appSettings' => $this->acl->getAppSettings(),
'share' => $this->userSession->getShare(),
]);
}


/**
* Watch poll for updates
Expand Down
16 changes: 16 additions & 0 deletions lib/Controller/UserApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,27 @@ public function writePreferences(array $preferences): JSONResponse {
/**
* get acl for poll
* @param $pollId Poll id
* @deprecated 8.0.0 Use getSession instead
*/
#[CORS]
#[NoAdminRequired]
#[NoCSRFRequired]
public function getAcl(): JSONResponse {
return $this->response(fn () => ['acl' => $this->acl]);
}
/**
* get acl for poll
* @param $pollId Poll id
*/
#[CORS]
#[NoAdminRequired]
#[NoCSRFRequired]
public function getSession(): JSONResponse {
return new JSONResponse([
'token' => $this->request->getParam('token'),
'currentUser' => $this->acl->getCurrentUser(),
'appPermissions' => $this->acl->getPermissionsArray(),
'appSettings' => $this->acl->getAppSettings(),
]);
}
}
24 changes: 19 additions & 5 deletions lib/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use OCA\Polls\Model\Acl;
use OCA\Polls\Service\CalendarService;
use OCA\Polls\Service\PreferencesService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
Expand Down Expand Up @@ -49,19 +48,34 @@ public function writePreferences(array $preferences): JSONResponse {

/**
* get acl for user
* @param $pollId Poll id
* @deprecated 8.0.0 Use getSession instead
*/
#[NoAdminRequired]
public function getAcl(): JSONResponse {
return new JSONResponse(['acl' => $this->acl], Http::STATUS_OK);
return $this->response(fn () => [
'acl' => $this->acl,
]);
}

/**
* get session information
*/
public function getSession(): JSONResponse {
return $this->response(fn () => [
'token' => $this->request->getParam('token'),
'currentUser' => $this->acl->getCurrentUser(),
'appPermissions' => $this->acl->getPermissionsArray(),
'appSettings' => $this->acl->getAppSettings(),
]);
}


/**
* Read all calendars
*/
#[NoAdminRequired]
public function getCalendars(): JSONResponse {
return new JSONResponse(['calendars' => $this->calendarService->getCalendars()], Http::STATUS_OK);
return $this->response(fn () => [
'calendars' => $this->calendarService->getCalendars(),
]);
}
}
5 changes: 4 additions & 1 deletion lib/Db/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
* @method int getCurrentUserCountOrphanedVotes()
* @method int getCurrentUserCountVotes()
* @method int getCurrentUserCountVotesYes()
* @method int getParticipantsCount()
*/

class Poll extends EntityWithUser implements JsonSerializable {
Expand Down Expand Up @@ -160,6 +161,7 @@ class Poll extends EntityWithUser implements JsonSerializable {
protected int $currentUserCountOrphanedVotes = 0;
protected int $currentUserCountVotes = 0;
protected int $currentUserCountVotesYes = 0;
protected int $participantsCount = 0;

public function __construct() {
$this->addType('created', 'int');
Expand All @@ -186,6 +188,7 @@ public function __construct() {
$this->addType('currentUserCountVotes', 'int');
$this->addType('currentUserCountVotesYes', 'int');
$this->addType('currentUserCountOrphanedVotes', 'int');
$this->addType('participantsCount', 'int');

$this->urlGenerator = Container::queryClass(IURLGenerator::class);
$this->userSession = Container::queryClass(UserSession::class);
Expand All @@ -204,7 +207,6 @@ public function jsonSerialize(): array {
'configuration' => $this->getConfigurationArray(),
// read only properties
'descriptionSafe' => $this->getDescriptionSafe(),
// read only properties
'owner' => $this->getUser(),
'status' => $this->getStatusArray(),
'currentUserStatus' => $this->getCurrentUserStatus(),
Expand All @@ -220,6 +222,7 @@ public function getStatusArray(): array {
'expired' => $this->getExpired(),
'relevantThreshold' => $this->getRelevantThreshold(),
'countOptions' => $this->getCountOptions(),
'countParticipants' => $this->getIsAllowed(self::PERMISSION_POLL_RESULTS_VIEW) ? $this->getParticipantsCount() : 0,
];
}
public function getConfigurationArray(): array {
Expand Down
12 changes: 12 additions & 0 deletions lib/Db/PollMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ protected function buildQuery(): IQueryBuilder {
$qb->selectAlias($qb->createFunction('(' . $this->subQueryVotesCount(self::TABLE, $paramUser)->getSQL() . ')'), 'current_user_count_votes');
$qb->selectAlias($qb->createFunction('(' . $this->subQueryVotesCount(self::TABLE, $paramUser, $paramAnswerYes)->getSQL() . ')'), 'current_user_count_votes_yes');
$qb->selectAlias($qb->createFunction('(' . $this->subQueryOrphanedVotesCount(self::TABLE, $paramUser)->getSQL() . ')'), 'current_user_count_orphaned_votes');
$qb->selectAlias($qb->createFunction('(' . $this->subQueryParticipantsCount(self::TABLE)->getSQL() . ')'), 'participants_count');

$this->joinOptionsForMaxDate($qb, self::TABLE);
$this->joinUserRole($qb, self::TABLE, $currentUserId);
Expand Down Expand Up @@ -338,5 +339,16 @@ protected function subQueryOrphanedVotesCount(string $fromAlias, IParameter $cur
);
return $subQuery;
}
/**
* Subquery for count of orphaned votes
*/
protected function subQueryParticipantsCount(string $fromAlias): IQueryBuilder {
$subAlias = 'user_vote_sub';

$subQuery = $this->db->getQueryBuilder();
$subQuery->select($subQuery->createFunction('COUNT(DISTINCT ' . $subAlias . '.user_id)'))
->from(Vote::TABLE, $subAlias)
->where($subQuery->expr()->eq($subAlias . '.poll_id', $fromAlias . '.id'));
return $subQuery;
}
}
18 changes: 14 additions & 4 deletions lib/Db/Preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Preferences extends Entity implements JsonSerializable {
'useAlternativeStyling' => false,
'calendarPeek' => false,
'checkCalendars' => [],
'checkCalendarsBefore' => 0,
'checkCalendarsAfter' => 0,
'checkCalendarsHoursBefore' => 0,
'checkCalendarsHoursAfter' => 0,
'defaultViewTextPoll' => 'table-view',
'defaultViewDatePoll' => 'table-view',
'performanceThreshold' => 1000,
Expand All @@ -56,14 +56,24 @@ public function getPreferences_decoded(): mixed {
return json_decode($this->getPreferences() ?? '');
}

public function getCheckCalendarsBefore(): int {
public function getCheckCalendarsHoursBefore(): int {
if (isset($this->getPreferences_decoded()->checkCalendarsHoursBefore)) {
return intval($this->getPreferences_decoded()->checkCalendarsHoursBefore);
}

// in case old property name is used, return the value
if (isset($this->getPreferences_decoded()->checkCalendarsBefore)) {
return intval($this->getPreferences_decoded()->checkCalendarsBefore);
}
return 0;
}

public function getCheckCalendarsAfter(): int {
public function getCheckCalendarsHoursAfter(): int {
if (isset($this->getPreferences_decoded()->checkCalendarsHoursAfter)) {
return intval($this->getPreferences_decoded()->checkCalendarsHoursAfter);
}

// in case old property name is used, return the value
if (isset($this->getPreferences_decoded()->checkCalendarsAfter)) {
return intval($this->getPreferences_decoded()->checkCalendarsAfter);
}
Expand Down
Loading