Passed
Pull Request — master (#487)
by René
04:26
created

PageController::insertComment()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 19
nc 2
nop 3
dl 0
loc 21
rs 9.6333
c 0
b 0
f 0
ccs 0
cts 20
cp 0
crap 6
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author Vinzenz Rosenkranz <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Polls\Controller;
25
26
use OCA\Polls\Db\Comment;
27
use OCA\Polls\Db\CommentMapper;
28
use OCA\Polls\Db\Event;
29
use OCA\Polls\Db\EventMapper;
30
use OCA\Polls\Db\Notification;
31
use OCA\Polls\Db\NotificationMapper;
32
use OCA\Polls\Db\Option;
33
use OCA\Polls\Db\OptionMapper;
34
use OCA\Polls\Db\Vote;
35
use OCA\Polls\Db\VoteMapper;
36
use OCP\AppFramework\Controller;
37
use OCP\AppFramework\Db\DoesNotExistException;
38
use OCP\AppFramework\Http\ContentSecurityPolicy;
39
use OCP\AppFramework\Http\JSONResponse;
40
use OCP\AppFramework\Http\RedirectResponse;
41
use OCP\AppFramework\Http\TemplateResponse;
42
use OCP\IAvatarManager;
43
use OCP\IConfig;
44
use OCP\IGroupManager;
45
use OCP\IL10N;
46
use OCP\ILogger;
47
use OCP\IRequest;
48
use OCP\IURLGenerator;
49
use OCP\IUser;
50
use OCP\IUserManager;
51
use OCP\L10N\IFactory;
52
use OCP\Mail\IMailer;
53
use OCP\Security\ISecureRandom;
54
use OCP\User; //To do: replace according to API
55
use OCP\Util;
56
57
class PageController extends Controller {
58
59
	private $userId;
60
	private $config;
61
	private $commentMapper;
62
	private $eventMapper;
63
	private $notificationMapper;
64
	private $optionMapper;
65
	private $voteMapper;
66
	private $urlGenerator;
67
	private $userMgr;
68
	private $avatarManager;
69
	private $logger;
70
	private $trans;
71
	private $transFactory;
72
	private $groupManager;
73
	private $mailer;
74
75
	/**
76
	 * PageController constructor.
77
	 * @param string $appName
78
	 * @param IRequest $request
79
	 * @param IConfig $config
80
	 * @param IUserManager $userMgr
81
	 * @param IGroupManager $groupManager
82
	 * @param IAvatarManager $avatarManager
83
	 * @param ILogger $logger
84
	 * @param IL10N $trans
85
	 * @param IFactory $transFactory
86
	 * @param IURLGenerator $urlGenerator
87
	 * @param string $userId
88
	 * @param CommentMapper $commentMapper
89
	 * @param OptionMapper $optionMapper
90
	 * @param EventMapper $eventMapper
91
	 * @param NotificationMapper $notificationMapper
92
	 * @param VoteMapper $VoteMapper
93
	 * @param IMailer $mailer
94
	 */
95 1
	public function __construct(
96
		$appName,
97
		IRequest $request,
98
		IConfig $config,
99
		IUserManager $userMgr,
100
		IGroupManager $groupManager,
101
		IAvatarManager $avatarManager,
102
		ILogger $logger,
103
		IL10N $trans,
104
		IFactory $transFactory,
105
		IURLGenerator $urlGenerator,
106
		$userId,
107
		CommentMapper $commentMapper,
108
		OptionMapper $optionMapper,
109
		EventMapper $eventMapper,
110
		NotificationMapper $notificationMapper,
111
		VoteMapper $VoteMapper,
112
		IMailer $mailer
113
	) {
114 1
		parent::__construct($appName, $request);
115 1
		$this->request = $request;
116 1
		$this->config = $config;
117 1
		$this->userMgr = $userMgr;
118 1
		$this->groupManager = $groupManager;
119 1
		$this->avatarManager = $avatarManager;
120 1
		$this->logger = $logger;
121 1
		$this->trans = $trans;
122 1
		$this->transFactory = $transFactory;
123 1
		$this->urlGenerator = $urlGenerator;
124 1
		$this->userId = $userId;
125 1
		$this->commentMapper = $commentMapper;
126 1
		$this->optionMapper = $optionMapper;
127 1
		$this->eventMapper = $eventMapper;
128 1
		$this->notificationMapper = $notificationMapper;
129 1
		$this->voteMapper = $VoteMapper;
130 1
		$this->mailer = $mailer;
131 1
	}
132
133
	/**
134
	 * @NoAdminRequired
135
	 * @NoCSRFRequired
136
	 */
137
	public function indexOld() {
138
		$polls = $this->eventMapper->findAllForUserWithInfo($this->userId);
139
		$comments = $this->commentMapper->findDistinctByUser($this->userId);
140
		$votes = $this->voteMapper->findDistinctByUser($this->userId);
141
		$response = new TemplateResponse('polls', 'main.tmpl', [
142
			'polls' => $polls,
143
			'comments' => $comments,
144
			'votes' => $votes,
145
			'userId' => $this->userId,
146
			'userMgr' => $this->userMgr,
147
			'urlGenerator' => $this->urlGenerator
148
		]);
149
		$csp = new ContentSecurityPolicy();
150
		$response->setContentSecurityPolicy($csp);
151
		return $response;
152
	}
153
154
	/**
155
	* @NoAdminRequired
156
	* @NoCSRFRequired
157
	*/
158
	public function createPoll() {
159
		return new TemplateResponse('polls', 'polls.tmpl',
160
		['urlGenerator' => $this->urlGenerator]);
161
	}
162
163
	/**
164
	* @NoAdminRequired
165
	* @NoCSRFRequired
166
	*/
167
	public function clonePoll() {
168
		return new TemplateResponse('polls', 'polls.tmpl',
169
		['urlGenerator' => $this->urlGenerator]);
170
	}
171
172
	/**
173
	* @NoAdminRequired
174
	* @NoCSRFRequired
175
	*/
176 1
	public function index() {
177 1
		return new TemplateResponse('polls', 'polls.tmpl',
178 1
		['urlGenerator' => $this->urlGenerator]);
179
	}
180
181
	/**
182
	 * @NoAdminRequired
183
	 * @NoCSRFRequired
184
	 * @param string $hash
185
	 * @return TemplateResponse
186
	 */
187
	public function editPoll($hash) {
188
		return new TemplateResponse('polls', 'polls.tmpl', [
189
			'urlGenerator' => $this->urlGenerator,
190
 			'hash' => $hash
191
		]);
192
	}
193
194
	/**
195
	 * @param int $pollId
196
	 * @param string $from
197
	 */
198
	private function sendNotifications($pollId, $from) {
199
		$poll = $this->eventMapper->find($pollId);
200
		$notifications = $this->notificationMapper->findAllByPoll($pollId);
201
		foreach ($notifications as $notification) {
202
			if ($from === $notification->getUserId()) {
203
				continue;
204
			}
205
			$recUser = $this->userMgr->get($notification->getUserId());
206
			if (!$recUser instanceof IUser) {
207
				continue;
208
			}
209
			$email = \OC::$server->getConfig()->getUserValue($notification->getUserId(), 'settings', 'email');
210
			if ($email === null || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
211
				continue;
212
			}
213
			$url = $this->urlGenerator->getAbsoluteURL(
214
				$this->urlGenerator->linkToRoute('polls.page.goto_poll',
215
					array('hash' => $poll->getHash()))
216
			);
217
218
			$sendUser = $this->userMgr->get($from);
219
			$sender = $from;
220
			if ($sendUser instanceof IUser) {
221
				$sender = $sendUser->getDisplayName();
222
			}
223
224
			$lang = $this->config->getUserValue($notification->getUserId(), 'core', 'lang');
225
			$trans = $this->transFactory->get('polls', $lang);
226
			$emailTemplate = $this->mailer->createEMailTemplate('polls.Notification', [
227
				'user' => $sender,
228
				'title' => $poll->getTitle(),
229
				'link' => $url,
230
			]);
231
			$emailTemplate->setSubject($trans->t('Polls App - New Activity'));
232
			$emailTemplate->addHeader();
233
			$emailTemplate->addHeading($trans->t('Polls App - New Activity'), false);
234
235
			$emailTemplate->addBodyText(str_replace(
236
				['{user}', '{title}'],
237
				[$sender, $poll->getTitle()],
238
				$trans->t('{user} participated in the poll "{title}"')
239
			));
240
241
			$emailTemplate->addBodyButton(
242
				htmlspecialchars($trans->t('Go to poll')),
243
				$url,
244
				false
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $plainText of OCP\Mail\IEMailTemplate::addBodyButton(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

244
				/** @scrutinizer ignore-type */ false
Loading history...
245
			);
246
247
			$emailTemplate->addFooter();
248
			try {
249
				$message = $this->mailer->createMessage();
250
				$message->setTo([$email => $recUser->getDisplayName()]);
251
				$message->useTemplate($emailTemplate);
252
				$this->mailer->send($message);
253
			} catch (\Exception $e) {
254
				$this->logger->logException($e, ['app' => 'polls']);
255
			}
256
		}
257
	}
258
259
	/**
260
	 * @NoAdminRequired
261
	 * @NoCSRFRequired
262
	 * @PublicPage
263
	 * @param string $hash
264
	 * @return TemplateResponse
265
	 */
266
	public function gotoPoll($hash) {
267
		try {
268
			$poll = $this->eventMapper->findByHash($hash);
269
		} catch (DoesNotExistException $e) {
270
			return new TemplateResponse('polls', 'no.acc.tmpl', []);
271
		}
272
		$options = $this->optionMapper->findByPoll($poll->getId());
273
		$votes = $this->voteMapper->findByPoll($poll->getId());
274
		$participants = $this->voteMapper->findParticipantsByPoll($poll->getId());
275
		$comments = $this->commentMapper->findByPoll($poll->getId());
276
277
		try {
278
			$notification = $this->notificationMapper->findByUserAndPoll($poll->getId(), $this->userId);
279
		} catch (DoesNotExistException $e) {
280
			$notification = null;
281
		}
282
		if ($this->hasUserAccess($poll)) {
283
			return new TemplateResponse('polls', 'vote.tmpl', [
284
				'poll' => $poll,
285
				'options' => $options,
286
				'comments' => $comments,
287
				'votes' => $votes,
288
				'participant' => $participants,
289
				'notification' => $notification,
290
				'userId' => $this->userId,
291
				'userMgr' => $this->userMgr,
292
				'urlGenerator' => $this->urlGenerator,
293
				'avatarManager' => $this->avatarManager
294
			]);
295
		} else {
296
			User::checkLoggedIn();
0 ignored issues
show
Deprecated Code introduced by
The function OCP\User::checkLoggedIn() has been deprecated: 13.0.0 Use annotation based ACLs from the AppFramework instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

296
			/** @scrutinizer ignore-deprecated */ User::checkLoggedIn();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
297
			return new TemplateResponse('polls', 'no.acc.tmpl', []);
298
		}
299
	}
300
301
	/**
302
	 * @NoAdminRequired
303
	 * @NoCSRFRequired
304
	 * @param int $pollId
305
	 * @return TemplateResponse|RedirectResponse
306
	 */
307
	public function deletePoll($pollId) {
308
		$pollToDelete = $this->eventMapper->find($pollId);
309
		if ($this->userId !== $pollToDelete->getOwner() && !$this->groupManager->isAdmin($this->userId)) {
310
			return new TemplateResponse('polls', 'no.delete.tmpl');
311
		}
312
		$poll = new Event();
313
		$poll->setId($pollId);
314
		$this->commentMapper->deleteByPoll($pollId);
315
		$this->voteMapper->deleteByPoll($pollId);
316
		$this->optionMapper->deleteByPoll($pollId);
317
		$this->eventMapper->delete($poll);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\AppFramework\Db\Mapper::delete() has been deprecated: 14.0.0 Move over to QBMapper ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

317
		/** @scrutinizer ignore-deprecated */ $this->eventMapper->delete($poll);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
318
		$url = $this->urlGenerator->linkToRoute('polls.page.index');
319
		return new RedirectResponse($url);
320
	}
321
322
	/**
323
	 * @NoAdminRequired
324
	 * @NoCSRFRequired
325
	 * @PublicPage
326
	 * @param int $pollId
327
	 * @param string $userId
328
	 * @param string $answers
329
	 * @param string $options
330
	 * @param bool $receiveNotifications
331
	 * @param bool $changed
332
	 * @return RedirectResponse
333
	 */
334
	public function insertVote($pollId, $userId, $answers, $options, $receiveNotifications, $changed) {
335
		if ($this->userId !== null) {
336
			if ($receiveNotifications) {
337
				try {
338
					//check if user already set notification for this poll
339
					$this->notificationMapper->findByUserAndPoll($pollId, $userId);
340
				} catch (DoesNotExistException $e) {
341
					//insert if not exist
342
					$not = new Notification();
343
					$not->setUserId($userId);
344
					$not->setPollId($pollId);
345
					$this->notificationMapper->insert($not);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\AppFramework\Db\Mapper::insert() has been deprecated: 14.0.0 Move over to QBMapper ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

345
					/** @scrutinizer ignore-deprecated */ $this->notificationMapper->insert($not);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
346
				}
347
			} else {
348
				try {
349
					//delete if entry is in db
350
					$not = $this->notificationMapper->findByUserAndPoll($pollId, $userId);
351
					$this->notificationMapper->delete($not);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\AppFramework\Db\Mapper::delete() has been deprecated: 14.0.0 Move over to QBMapper ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

351
					/** @scrutinizer ignore-deprecated */ $this->notificationMapper->delete($not);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
352
				} catch (DoesNotExistException $e) {
353
					//doesn't exist in db, nothing to do
354
				}
355
			}
356
		}
357
		$poll = $this->eventMapper->find($pollId);
358
359
		if ($changed) {
360
			$options = json_decode($options);
361
			$answers = json_decode($answers);
362
			$count_options = count($options);
363
			$this->voteMapper->deleteByPollAndUser($pollId, $userId);
364
365
			for ($i = 0; $i < $count_options; $i++) {
366
				$vote = new Vote();
367
				$vote->setPollId($pollId);
368
				$vote->setUserId($userId);
369
				$vote->setVoteOptionText(htmlspecialchars($options[$i]));
370
				$vote->setVoteAnswer($answers[$i]);
371
				$this->voteMapper->insert($vote);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\AppFramework\Db\Mapper::insert() has been deprecated: 14.0.0 Move over to QBMapper ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

371
				/** @scrutinizer ignore-deprecated */ $this->voteMapper->insert($vote);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
372
373
			}
374
			$this->sendNotifications($pollId, $userId);
375
		}
376
		$hash = $poll->getHash();
377
		$url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', ['hash' => $hash]);
378
		return new RedirectResponse($url);
379
	}
380
381
	/**
382
	 * @NoAdminRequired
383
	 * @NoCSRFRequired
384
	 * @PublicPage
385
	 * @param int $pollId
386
	 * @param string $userId
387
	 * @param string $commentBox
388
	 * @return JSONResponse
389
	 */
390
	public function insertComment($pollId, $userId, $commentBox) {
391
		$comment = new Comment();
392
		$comment->setPollId($pollId);
393
		$comment->setUserId($userId);
394
		$comment->setComment($commentBox);
395
		$comment->setDt(date('Y-m-d H:i:s'));
396
		$this->commentMapper->insert($comment);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\AppFramework\Db\Mapper::insert() has been deprecated: 14.0.0 Move over to QBMapper ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

396
		/** @scrutinizer ignore-deprecated */ $this->commentMapper->insert($comment);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
397
		$this->sendNotifications($pollId, $userId);
398
		$timeStamp = time();
399
		$displayName = $userId;
400
		$user = $this->userMgr->get($userId);
401
		if ($user !== null) {
402
			$displayName = $user->getDisplayName();
403
		}
404
		return new JSONResponse(array(
405
			'userId' => $userId,
406
			'displayName' => $displayName,
407
			'timeStamp' => $timeStamp * 100,
408
			'date' => date('Y-m-d H:i:s', $timeStamp),
409
			'relativeNow' => $this->trans->t('just now'),
410
			'comment' => $commentBox
411
		));
412
	}
413
414
	/**
415
	 * @NoAdminRequired
416
	 * @NoCSRFRequired
417
	 * @param string $searchTerm
418
	 * @param string $groups
419
	 * @param string $users
420
	 * @return array
421
	 */
422
	public function search($searchTerm, $groups, $users) {
423
		return array_merge($this->searchForGroups($searchTerm, $groups), $this->searchForUsers($searchTerm, $users));
424
	}
425
426
	/**
427
	 * @NoAdminRequired
428
	 * @NoCSRFRequired
429
	 * @param string $searchTerm
430
	 * @param string $groups
431
	 * @return array
432
	 */
433
	public function searchForGroups($searchTerm, $groups) {
434
		$selectedGroups = json_decode($groups);
435
		$groups = $this->groupManager->search($searchTerm);
436
		$gids = array();
437
		$sgids = array();
438
		foreach ($selectedGroups as $sg) {
439
			$sgids[] = str_replace('group_', '', $sg);
440
		}
441
		foreach ($groups as $g) {
442
			$gids[] = $g->getGID();
443
		}
444
		$diffGids = array_diff($gids, $sgids);
445
		$gids = array();
446
		foreach ($diffGids as $g) {
447
			$gids[] = ['gid' => $g, 'isGroup' => true];
448
		}
449
		return $gids;
450
	}
451
452
	/**
453
	 * @NoAdminRequired
454
	 * @NoCSRFRequired
455
	 * @param string $searchTerm
456
	 * @param string $users
457
	 * @return array
458
	 */
459
	public function searchForUsers($searchTerm, $users) {
460
		$selectedUsers = json_decode($users);
461
		Util::writeLog('polls', print_r($selectedUsers, true), Util::ERROR);
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\Util::ERROR has been deprecated: 14.0.0 use \OCP\ILogger::ERROR ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

461
		Util::writeLog('polls', print_r($selectedUsers, true), /** @scrutinizer ignore-deprecated */ Util::ERROR);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
Deprecated Code introduced by
The function OCP\Util::writeLog() has been deprecated: 13.0.0 use log of \OCP\ILogger ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

461
		/** @scrutinizer ignore-deprecated */ Util::writeLog('polls', print_r($selectedUsers, true), Util::ERROR);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
462
		$userNames = $this->userMgr->searchDisplayName($searchTerm);
463
		$users = array();
464
		$sUsers = array();
465
		foreach ($selectedUsers as $su) {
466
			$sUsers[] = str_replace('user_', '', $su);
467
		}
468
		foreach ($userNames as $u) {
469
			$allreadyAdded = false;
470
			foreach ($sUsers as &$su) {
471
				if ($su === $u->getUID()) {
472
					unset($su);
473
					$allreadyAdded = true;
474
					break;
475
				}
476
			}
477
			if (!$allreadyAdded) {
478
				$users[] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false);
479
			} else {
480
				continue;
481
			}
482
		}
483
		return $users;
484
	}
485
486
	/**
487
	 * @NoAdminRequired
488
	 * @NoCSRFRequired
489
	 * @param string $username
490
	 * @return string
491
	 */
492
	public function getDisplayName($username) {
493
		return $this->userMgr->get($username)->getDisplayName();
494
	}
495
496
	/**
497
	 * @return \OCP\IGroup[]
498
	 */
499
	private function getGroups() {
500
		if (class_exists('\OC_Group')) {
501
			// Nextcloud <= 11, ownCloud
502
			return \OC_Group::getUserGroups($this->userId);
0 ignored issues
show
Bug introduced by
The type OC_Group was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
503
		}
504
		// Nextcloud >= 12
505
		$groups = $this->groupManager->getUserGroups(\OC::$server->getUserSession()->getUser());
506
		return array_map(function($group) {
507
			return $group->getGID();
508
		}, $groups);
509
	}
510
511
	/**
512
	 * Check if user has access to this poll
513
	 *
514
	 * @param Event $poll
515
	 * @return bool
516
	 */
517
	private function hasUserAccess($poll) {
518
		$access = $poll->getAccess();
519
		$owner = $poll->getOwner();
520
		if ($access === 'public' || $access === 'hidden') {
521
			return true;
522
		}
523
		if ($this->userId === null) {
524
			return false;
525
		}
526
		if ($access === 'registered') {
527
			return true;
528
		}
529
		if ($owner === $this->userId) {
530
			return true;
531
		}
532
		Util::writeLog('polls', $this->userId, Util::ERROR);
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\Util::ERROR has been deprecated: 14.0.0 use \OCP\ILogger::ERROR ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

532
		Util::writeLog('polls', $this->userId, /** @scrutinizer ignore-deprecated */ Util::ERROR);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
Deprecated Code introduced by
The function OCP\Util::writeLog() has been deprecated: 13.0.0 use log of \OCP\ILogger ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

532
		/** @scrutinizer ignore-deprecated */ Util::writeLog('polls', $this->userId, Util::ERROR);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
533
		$userGroups = $this->getGroups();
534
		$arr = explode(';', $access);
535
		foreach ($arr as $item) {
536
			if (strpos($item, 'group_') === 0) {
537
				$grp = substr($item, 6);
538
				foreach ($userGroups as $userGroup) {
539
					if ($userGroup === $grp) {
540
						return true;
541
					}
542
				}
543
			} else {
544
				if (strpos($item, 'user_') === 0) {
545
					$usr = substr($item, 5);
546
					if ($usr === $this->userId) {
547
						return true;
548
					}
549
				}
550
			}
551
		}
552
		return false;
553
	}
554
	/**
555
	 * Check if user is owner of this poll
556
	 *
557
	 * @param Event $poll
558
	 * @return bool
559
	 */
560
561
	private function userIsOwner($poll) {
562
		$owner = $poll->getOwner();
563
564
		if ($owner === $this->userId) {
565
			return true;
566
		}
567
		Util::writeLog('polls', $this->userId, Util::ERROR);
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\Util::ERROR has been deprecated: 14.0.0 use \OCP\ILogger::ERROR ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

567
		Util::writeLog('polls', $this->userId, /** @scrutinizer ignore-deprecated */ Util::ERROR);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
Deprecated Code introduced by
The function OCP\Util::writeLog() has been deprecated: 13.0.0 use log of \OCP\ILogger ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

567
		/** @scrutinizer ignore-deprecated */ Util::writeLog('polls', $this->userId, Util::ERROR);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
568
		return false;
569
	}
570
}
571