@@ -26,7 +26,7 @@ |
||
| 26 | 26 | </div> |
| 27 | 27 | </fieldset> |
| 28 | 28 | <fieldset> |
| 29 | - <input type="submit" value="<?php p($l->t('Save'));?>"> |
|
| 29 | + <input type="submit" value="<?php p($l->t('Save')); ?>"> |
|
| 30 | 30 | </fieldset> |
| 31 | 31 | </form> |
| 32 | 32 | </div> |
@@ -38,171 +38,171 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | class InvitationResponseController extends Controller { |
| 40 | 40 | |
| 41 | - /** @var IDBConnection */ |
|
| 42 | - private $db; |
|
| 43 | - |
|
| 44 | - /** @var ITimeFactory */ |
|
| 45 | - private $timeFactory; |
|
| 46 | - |
|
| 47 | - /** @var InvitationResponseServer */ |
|
| 48 | - private $responseServer; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * InvitationResponseController constructor. |
|
| 52 | - * |
|
| 53 | - * @param string $appName |
|
| 54 | - * @param IRequest $request |
|
| 55 | - * @param IDBConnection $db |
|
| 56 | - * @param ITimeFactory $timeFactory |
|
| 57 | - * @param InvitationResponseServer $responseServer |
|
| 58 | - */ |
|
| 59 | - public function __construct(string $appName, IRequest $request, |
|
| 60 | - IDBConnection $db, ITimeFactory $timeFactory, |
|
| 61 | - InvitationResponseServer $responseServer) { |
|
| 62 | - parent::__construct($appName, $request); |
|
| 63 | - $this->db = $db; |
|
| 64 | - $this->timeFactory = $timeFactory; |
|
| 65 | - $this->responseServer = $responseServer; |
|
| 66 | - // Don't run `$server->exec()`, because we just need access to the |
|
| 67 | - // fully initialized schedule plugin, but we don't want Sabre/DAV |
|
| 68 | - // to actually handle and reply to the request |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @PublicPage |
|
| 73 | - * @NoCSRFRequired |
|
| 74 | - * |
|
| 75 | - * @param string $token |
|
| 76 | - * @return TemplateResponse |
|
| 77 | - */ |
|
| 78 | - public function accept(string $token):TemplateResponse { |
|
| 79 | - $row = $this->getTokenInformation($token); |
|
| 80 | - if (!$row) { |
|
| 81 | - return new TemplateResponse($this->appName, 'schedule-response-error', [], 'guest'); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $iTipMessage = $this->buildITipResponse($row, 'ACCEPTED'); |
|
| 85 | - $this->responseServer->handleITipMessage($iTipMessage); |
|
| 86 | - if ($iTipMessage->getScheduleStatus() === '1.2') { |
|
| 87 | - return new TemplateResponse($this->appName, 'schedule-response-success', [], 'guest'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return new TemplateResponse($this->appName, 'schedule-response-error', [ |
|
| 91 | - 'organizer' => $row['organizer'], |
|
| 92 | - ], 'guest'); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @PublicPage |
|
| 97 | - * @NoCSRFRequired |
|
| 98 | - * |
|
| 99 | - * @param string $token |
|
| 100 | - * @return TemplateResponse |
|
| 101 | - */ |
|
| 102 | - public function decline(string $token):TemplateResponse { |
|
| 103 | - $row = $this->getTokenInformation($token); |
|
| 104 | - if (!$row) { |
|
| 105 | - return new TemplateResponse($this->appName, 'schedule-response-error', [], 'guest'); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $iTipMessage = $this->buildITipResponse($row, 'DECLINED'); |
|
| 109 | - $this->responseServer->handleITipMessage($iTipMessage); |
|
| 110 | - |
|
| 111 | - if ($iTipMessage->getScheduleStatus() === '1.2') { |
|
| 112 | - return new TemplateResponse($this->appName, 'schedule-response-success', [], 'guest'); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - return new TemplateResponse($this->appName, 'schedule-response-error', [ |
|
| 116 | - 'organizer' => $row['organizer'], |
|
| 117 | - ], 'guest'); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @PublicPage |
|
| 122 | - * @NoCSRFRequired |
|
| 123 | - * |
|
| 124 | - * @param string $token |
|
| 125 | - * @return TemplateResponse |
|
| 126 | - */ |
|
| 127 | - public function options(string $token):TemplateResponse { |
|
| 128 | - return new TemplateResponse($this->appName, 'schedule-response-options', [ |
|
| 129 | - 'token' => $token |
|
| 130 | - ], 'guest'); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @PublicPage |
|
| 135 | - * @NoCSRFRequired |
|
| 136 | - * |
|
| 137 | - * @param string $token |
|
| 138 | - * |
|
| 139 | - * @return TemplateResponse |
|
| 140 | - */ |
|
| 141 | - public function processMoreOptionsResult(string $token):TemplateResponse { |
|
| 142 | - $partstat = $this->request->getParam('partStat'); |
|
| 143 | - |
|
| 144 | - $row = $this->getTokenInformation($token); |
|
| 145 | - if (!$row || !\in_array($partstat, ['ACCEPTED', 'DECLINED', 'TENTATIVE'])) { |
|
| 146 | - return new TemplateResponse($this->appName, 'schedule-response-error', [], 'guest'); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $iTipMessage = $this->buildITipResponse($row, $partstat); |
|
| 150 | - $this->responseServer->handleITipMessage($iTipMessage); |
|
| 151 | - if ($iTipMessage->getScheduleStatus() === '1.2') { |
|
| 152 | - return new TemplateResponse($this->appName, 'schedule-response-success', [], 'guest'); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return new TemplateResponse($this->appName, 'schedule-response-error', [ |
|
| 156 | - 'organizer' => $row['organizer'], |
|
| 157 | - ], 'guest'); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @param string $token |
|
| 162 | - * @return array|null |
|
| 163 | - */ |
|
| 164 | - private function getTokenInformation(string $token) { |
|
| 165 | - $query = $this->db->getQueryBuilder(); |
|
| 166 | - $query->select('*') |
|
| 167 | - ->from('calendar_invitations') |
|
| 168 | - ->where($query->expr()->eq('token', $query->createNamedParameter($token))); |
|
| 169 | - $stmt = $query->execute(); |
|
| 170 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 171 | - |
|
| 172 | - if (!$row) { |
|
| 173 | - return null; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $currentTime = $this->timeFactory->getTime(); |
|
| 177 | - if (((int) $row['expiration']) < $currentTime) { |
|
| 178 | - return null; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return $row; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @param array $row |
|
| 186 | - * @param string $partStat participation status of attendee - SEE RFC 5545 |
|
| 187 | - * @param int|null $guests |
|
| 188 | - * @param string|null $comment |
|
| 189 | - * @return Message |
|
| 190 | - */ |
|
| 191 | - private function buildITipResponse(array $row, string $partStat):Message { |
|
| 192 | - $iTipMessage = new Message(); |
|
| 193 | - $iTipMessage->uid = $row['uid']; |
|
| 194 | - $iTipMessage->component = 'VEVENT'; |
|
| 195 | - $iTipMessage->method = 'REPLY'; |
|
| 196 | - $iTipMessage->sequence = $row['sequence']; |
|
| 197 | - $iTipMessage->sender = $row['attendee']; |
|
| 198 | - |
|
| 199 | - if ($this->responseServer->isExternalAttendee($row['attendee'])) { |
|
| 200 | - $iTipMessage->recipient = $row['organizer']; |
|
| 201 | - } else { |
|
| 202 | - $iTipMessage->recipient = $row['attendee']; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $message = <<<EOF |
|
| 41 | + /** @var IDBConnection */ |
|
| 42 | + private $db; |
|
| 43 | + |
|
| 44 | + /** @var ITimeFactory */ |
|
| 45 | + private $timeFactory; |
|
| 46 | + |
|
| 47 | + /** @var InvitationResponseServer */ |
|
| 48 | + private $responseServer; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * InvitationResponseController constructor. |
|
| 52 | + * |
|
| 53 | + * @param string $appName |
|
| 54 | + * @param IRequest $request |
|
| 55 | + * @param IDBConnection $db |
|
| 56 | + * @param ITimeFactory $timeFactory |
|
| 57 | + * @param InvitationResponseServer $responseServer |
|
| 58 | + */ |
|
| 59 | + public function __construct(string $appName, IRequest $request, |
|
| 60 | + IDBConnection $db, ITimeFactory $timeFactory, |
|
| 61 | + InvitationResponseServer $responseServer) { |
|
| 62 | + parent::__construct($appName, $request); |
|
| 63 | + $this->db = $db; |
|
| 64 | + $this->timeFactory = $timeFactory; |
|
| 65 | + $this->responseServer = $responseServer; |
|
| 66 | + // Don't run `$server->exec()`, because we just need access to the |
|
| 67 | + // fully initialized schedule plugin, but we don't want Sabre/DAV |
|
| 68 | + // to actually handle and reply to the request |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @PublicPage |
|
| 73 | + * @NoCSRFRequired |
|
| 74 | + * |
|
| 75 | + * @param string $token |
|
| 76 | + * @return TemplateResponse |
|
| 77 | + */ |
|
| 78 | + public function accept(string $token):TemplateResponse { |
|
| 79 | + $row = $this->getTokenInformation($token); |
|
| 80 | + if (!$row) { |
|
| 81 | + return new TemplateResponse($this->appName, 'schedule-response-error', [], 'guest'); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $iTipMessage = $this->buildITipResponse($row, 'ACCEPTED'); |
|
| 85 | + $this->responseServer->handleITipMessage($iTipMessage); |
|
| 86 | + if ($iTipMessage->getScheduleStatus() === '1.2') { |
|
| 87 | + return new TemplateResponse($this->appName, 'schedule-response-success', [], 'guest'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return new TemplateResponse($this->appName, 'schedule-response-error', [ |
|
| 91 | + 'organizer' => $row['organizer'], |
|
| 92 | + ], 'guest'); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @PublicPage |
|
| 97 | + * @NoCSRFRequired |
|
| 98 | + * |
|
| 99 | + * @param string $token |
|
| 100 | + * @return TemplateResponse |
|
| 101 | + */ |
|
| 102 | + public function decline(string $token):TemplateResponse { |
|
| 103 | + $row = $this->getTokenInformation($token); |
|
| 104 | + if (!$row) { |
|
| 105 | + return new TemplateResponse($this->appName, 'schedule-response-error', [], 'guest'); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $iTipMessage = $this->buildITipResponse($row, 'DECLINED'); |
|
| 109 | + $this->responseServer->handleITipMessage($iTipMessage); |
|
| 110 | + |
|
| 111 | + if ($iTipMessage->getScheduleStatus() === '1.2') { |
|
| 112 | + return new TemplateResponse($this->appName, 'schedule-response-success', [], 'guest'); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + return new TemplateResponse($this->appName, 'schedule-response-error', [ |
|
| 116 | + 'organizer' => $row['organizer'], |
|
| 117 | + ], 'guest'); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @PublicPage |
|
| 122 | + * @NoCSRFRequired |
|
| 123 | + * |
|
| 124 | + * @param string $token |
|
| 125 | + * @return TemplateResponse |
|
| 126 | + */ |
|
| 127 | + public function options(string $token):TemplateResponse { |
|
| 128 | + return new TemplateResponse($this->appName, 'schedule-response-options', [ |
|
| 129 | + 'token' => $token |
|
| 130 | + ], 'guest'); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @PublicPage |
|
| 135 | + * @NoCSRFRequired |
|
| 136 | + * |
|
| 137 | + * @param string $token |
|
| 138 | + * |
|
| 139 | + * @return TemplateResponse |
|
| 140 | + */ |
|
| 141 | + public function processMoreOptionsResult(string $token):TemplateResponse { |
|
| 142 | + $partstat = $this->request->getParam('partStat'); |
|
| 143 | + |
|
| 144 | + $row = $this->getTokenInformation($token); |
|
| 145 | + if (!$row || !\in_array($partstat, ['ACCEPTED', 'DECLINED', 'TENTATIVE'])) { |
|
| 146 | + return new TemplateResponse($this->appName, 'schedule-response-error', [], 'guest'); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $iTipMessage = $this->buildITipResponse($row, $partstat); |
|
| 150 | + $this->responseServer->handleITipMessage($iTipMessage); |
|
| 151 | + if ($iTipMessage->getScheduleStatus() === '1.2') { |
|
| 152 | + return new TemplateResponse($this->appName, 'schedule-response-success', [], 'guest'); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return new TemplateResponse($this->appName, 'schedule-response-error', [ |
|
| 156 | + 'organizer' => $row['organizer'], |
|
| 157 | + ], 'guest'); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @param string $token |
|
| 162 | + * @return array|null |
|
| 163 | + */ |
|
| 164 | + private function getTokenInformation(string $token) { |
|
| 165 | + $query = $this->db->getQueryBuilder(); |
|
| 166 | + $query->select('*') |
|
| 167 | + ->from('calendar_invitations') |
|
| 168 | + ->where($query->expr()->eq('token', $query->createNamedParameter($token))); |
|
| 169 | + $stmt = $query->execute(); |
|
| 170 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 171 | + |
|
| 172 | + if (!$row) { |
|
| 173 | + return null; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $currentTime = $this->timeFactory->getTime(); |
|
| 177 | + if (((int) $row['expiration']) < $currentTime) { |
|
| 178 | + return null; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return $row; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @param array $row |
|
| 186 | + * @param string $partStat participation status of attendee - SEE RFC 5545 |
|
| 187 | + * @param int|null $guests |
|
| 188 | + * @param string|null $comment |
|
| 189 | + * @return Message |
|
| 190 | + */ |
|
| 191 | + private function buildITipResponse(array $row, string $partStat):Message { |
|
| 192 | + $iTipMessage = new Message(); |
|
| 193 | + $iTipMessage->uid = $row['uid']; |
|
| 194 | + $iTipMessage->component = 'VEVENT'; |
|
| 195 | + $iTipMessage->method = 'REPLY'; |
|
| 196 | + $iTipMessage->sequence = $row['sequence']; |
|
| 197 | + $iTipMessage->sender = $row['attendee']; |
|
| 198 | + |
|
| 199 | + if ($this->responseServer->isExternalAttendee($row['attendee'])) { |
|
| 200 | + $iTipMessage->recipient = $row['organizer']; |
|
| 201 | + } else { |
|
| 202 | + $iTipMessage->recipient = $row['attendee']; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $message = <<<EOF |
|
| 206 | 206 | BEGIN:VCALENDAR |
| 207 | 207 | PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN |
| 208 | 208 | METHOD:REPLY |
@@ -217,14 +217,14 @@ discard block |
||
| 217 | 217 | END:VCALENDAR |
| 218 | 218 | EOF; |
| 219 | 219 | |
| 220 | - $vObject = Reader::read(vsprintf($message, [ |
|
| 221 | - $partStat, $row['attendee'], $row['organizer'], |
|
| 222 | - $row['uid'], $row['sequence'] ?? 0, $row['recurrenceid'] ?? '' |
|
| 223 | - ])); |
|
| 224 | - $vEvent = $vObject->{'VEVENT'}; |
|
| 225 | - $vEvent->DTSTAMP = date('Ymd\\THis\\Z', $this->timeFactory->getTime()); |
|
| 226 | - $iTipMessage->message = $vObject; |
|
| 220 | + $vObject = Reader::read(vsprintf($message, [ |
|
| 221 | + $partStat, $row['attendee'], $row['organizer'], |
|
| 222 | + $row['uid'], $row['sequence'] ?? 0, $row['recurrenceid'] ?? '' |
|
| 223 | + ])); |
|
| 224 | + $vEvent = $vObject->{'VEVENT'}; |
|
| 225 | + $vEvent->DTSTAMP = date('Ymd\\THis\\Z', $this->timeFactory->getTime()); |
|
| 226 | + $iTipMessage->message = $vObject; |
|
| 227 | 227 | |
| 228 | - return $iTipMessage; |
|
| 229 | - } |
|
| 228 | + return $iTipMessage; |
|
| 229 | + } |
|
| 230 | 230 | } |