-
Notifications
You must be signed in to change notification settings - Fork 73
/
PollController.php
175 lines (157 loc) · 4.25 KB
/
PollController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
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\MailService;
use OCA\Polls\Service\OptionService;
use OCA\Polls\Service\PollService;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCP\Server;
/**
* @psalm-api
*/
class PollController extends BaseController {
public function __construct(
string $appName,
IRequest $request,
private Acl $acl,
private MailService $mailService,
private OptionService $optionService,
private PollService $pollService,
) {
parent::__construct($appName, $request);
}
/**
* Get list of polls
*/
#[NoAdminRequired]
public function list(): JSONResponse {
return $this->response(function () {
$appSettings = Server::get(AppSettings::class);
return [
'list' => $this->pollService->list(),
'permissions' => [
'pollCreationAllowed' => $appSettings->getPollCreationAllowed(),
'comboAllowed' => $appSettings->getComboAllowed(),
],
];
});
}
/**
* get complete poll
* @param int $pollId Poll id
*/
#[NoAdminRequired]
public function get(int $pollId): JSONResponse {
return $this->response(fn () => [
'poll' => $this->pollService->get($pollId),
'acl' => $this->acl,
]);
}
/**
* Add poll
* @param string $title Poll title
* @param string $type Poll type ('datePoll', 'textPoll')
*/
#[NoAdminRequired]
public function add(string $type, string $title): JSONResponse {
return $this->responseCreate(fn () => $this->pollService->add($type, $title));
}
/**
* Update poll configuration
* @param int $pollId Poll id
* @param array $poll poll config
*/
#[NoAdminRequired]
public function update(int $pollId, array $poll): JSONResponse {
return $this->response(fn () => [
'poll' => $this->pollService->update($pollId, $poll),
'acl' => $this->acl,
]);
}
/**
* Send confirmation mails
* @param int $pollId Poll id
*/
#[NoAdminRequired]
public function sendConfirmation(int $pollId): JSONResponse {
return $this->response(fn () => [
'confirmations' => $this->mailService->sendConfirmations($pollId),
]);
}
/**
* Switch deleted status (move to deleted polls)
* @param int $pollId Poll id
*/
#[NoAdminRequired]
public function toggleArchive(int $pollId): JSONResponse {
return $this->response(fn () => $this->pollService->toggleArchive($pollId));
}
/**
* Delete poll
* @param int $pollId Poll id
*/
#[NoAdminRequired]
public function delete(int $pollId): JSONResponse {
return $this->responseDeleteTolerant(fn () => $this->pollService->delete($pollId));
}
/**
* Close poll
* @param int $pollId Poll id
*/
#[NoAdminRequired]
public function close(int $pollId): JSONResponse {
return $this->response(fn () => [
'poll' => $this->pollService->close($pollId),
'acl' => $this->acl,
]);
}
/**
* Reopen poll
* @param int $pollId Poll id
*/
#[NoAdminRequired]
public function reopen(int $pollId): JSONResponse {
return $this->response(fn () => [
'poll' => $this->pollService->reopen($pollId),
'acl' => $this->acl,
]);
}
/**
* Clone poll
* @param int $pollId Poll id
*/
#[NoAdminRequired]
public function clone(int $pollId): JSONResponse {
return $this->response(fn () => $this->clonePoll($pollId));
}
private function clonePoll(int $pollId): JSONResponse {
$poll = $this->pollService->clone($pollId);
$this->optionService->clone($pollId, $poll->getId());
return $this->get($pollId);
}
/**
* Transfer polls between users
* @param string $sourceUser User to transfer polls from
* @param string $targetUser User to transfer polls to
*/
public function transferPolls(string $sourceUser, string $targetUser): JSONResponse {
return $this->response(fn () => $this->pollService->transferPolls($sourceUser, $targetUser));
}
/**
* Collect email addresses from particitipants
* @param int $pollId Poll id
*/
#[NoAdminRequired]
public function getParticipantsEmailAddresses(int $pollId): JSONResponse {
return $this->response(fn () => $this->pollService->getParticipantsEmailAddresses($pollId));
}
}