forked from nextcloud/polls
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminController.php
More file actions
98 lines (88 loc) · 2.79 KB
/
AdminController.php
File metadata and controls
98 lines (88 loc) · 2.79 KB
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
<?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\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\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Util;
/**
* @psalm-api
*/
class AdminController extends BaseController {
public function __construct(
string $appName,
IRequest $request,
private IURLGenerator $urlGenerator,
private PollService $pollService,
private IEventDispatcher $eventDispatcher,
private AutoReminderCron $autoReminderCron,
private JanitorCron $janitorCron,
private NotificationCron $notificationCron,
) {
parent::__construct($appName, $request);
}
/**
* Load admin page
*/
#[NoCSRFRequired]
#[OpenAPI(OpenAPI::SCOPE_IGNORE)]
#[FrontpageRoute(verb: 'GET', url: '/administration')]
public function index(): TemplateResponse {
Util::addScript(AppConstants::APP_ID, 'polls-main');
$this->eventDispatcher->dispatchTyped(new LoadAdditionalScriptsEvent());
return new TemplateResponse(AppConstants::APP_ID, 'main', ['urlGenerator' => $this->urlGenerator]);
}
/**
* Get list of polls for administrative purposes
*/
#[FrontpageRoute(verb: 'GET', url: '/administration/polls')]
public function list(): JSONResponse {
return $this->response(fn () => $this->pollService->listForAdmin());
}
/**
* Takeover ownership of a poll
* @param int $pollId PollId to take over
*/
#[FrontpageRoute(verb: 'PUT', url: '/administration/poll/{pollId}/takeover')]
public function takeover(int $pollId): JSONResponse {
return $this->response(fn () => [
'poll' => $this->pollService->takeover($pollId)
]);
}
/**
* Run auto reminder job
*/
#[FrontpageRoute(verb: 'GET', url: '/administration/autoReminder/run')]
public function runAutoReminderJob(): JSONResponse {
return $this->response(fn () => $this->autoReminderCron->manuallyRun());
}
/**
* Run janitor job
*/
#[FrontpageRoute(verb: 'GET', url: '/administration/janitor/run')]
public function runJanitorJob(): JSONResponse {
return $this->response(fn () => $this->janitorCron->manuallyRun());
}
/**
* Run notification job
*/
#[FrontpageRoute(verb: 'GET', url: '/administration/notification/run')]
public function runNotificationJob(): JSONResponse {
return $this->response(fn () => $this->notificationCron->manuallyRun());
}
}