|
21 | 21 |
|
22 | 22 | namespace OCA\FirstRunWizard\Controller; |
23 | 23 |
|
24 | | -use OCA\FirstRunWizard\AppInfo\Application; |
25 | 24 | use OCP\AppFramework\Controller; |
26 | 25 | use OCP\AppFramework\Http\DataResponse; |
27 | | -use OCP\AppFramework\Http\JSONResponse; |
28 | | -use OCP\Defaults; |
29 | 26 | use OCP\IConfig; |
30 | | -use OCP\IGroupManager; |
31 | 27 | use OCP\IRequest; |
32 | 28 |
|
33 | 29 | class WizardController extends Controller { |
34 | 30 |
|
35 | | - /** @var IConfig */ |
36 | | - protected $config; |
37 | | - |
38 | | - /** @var string */ |
39 | | - protected $userId; |
40 | | - |
41 | | - /** @var Defaults */ |
42 | | - protected $theming; |
43 | | - |
44 | | - /** @var IGroupManager */ |
45 | | - protected $groupManager; |
46 | | - |
47 | | - /** @var array|false|string[] */ |
48 | | - protected $slides = []; |
49 | | - |
50 | 31 | /** |
51 | 32 | * @param string $appName |
52 | 33 | * @param IRequest $request |
53 | 34 | * @param IConfig $config |
54 | | - * @param string $userId |
55 | | - * @param Defaults $theming |
| 35 | + * @param string|null $userId |
56 | 36 | */ |
57 | | - public function __construct($appName, IRequest $request, IConfig $config, $userId, Defaults $theming, IGroupManager $groupManager) { |
| 37 | + public function __construct( |
| 38 | + $appName, |
| 39 | + IRequest $request, |
| 40 | + private IConfig $config, |
| 41 | + private ?string $userId, |
| 42 | + ) { |
58 | 43 | parent::__construct($appName, $request); |
59 | | - |
60 | | - $this->config = $config; |
61 | | - $this->userId = $userId; |
62 | | - $this->theming = $theming; |
63 | | - $this->groupManager = $groupManager; |
64 | | - |
65 | | - $this->slides = explode(',', $this->config->getAppValue(Application::APP_ID, 'slides', 'video,values,apps,clients,final')); |
66 | 44 | } |
67 | 45 |
|
68 | 46 | /** |
69 | 47 | * @NoAdminRequired |
70 | 48 | * @return DataResponse |
71 | 49 | */ |
72 | 50 | public function disable() { |
| 51 | + \assert($this->userId !== null); |
73 | 52 | $this->config->setUserValue($this->userId, 'firstrunwizard', 'show', 0); |
74 | 53 | return new DataResponse(); |
75 | 54 | } |
76 | | - |
77 | | - /** |
78 | | - * @NoAdminRequired |
79 | | - * @return JsonResponse |
80 | | - */ |
81 | | - public function show() { |
82 | | - $appStore = $this->config->getSystemValue('appstoreenabled', true); |
83 | | - |
84 | | - $data = [ |
85 | | - 'desktop' => $this->config->getSystemValue('customclient_desktop', $this->theming->getSyncClientUrl()), |
86 | | - 'android' => $this->config->getSystemValue('customclient_android', $this->theming->getAndroidClientUrl()), |
87 | | - 'fdroid' => $this->config->getSystemValue('customclient_fdroid', $this->theming->getFDroidClientUrl()), |
88 | | - 'ios' => $this->config->getSystemValue('customclient_ios', $this->theming->getiOSClientUrl()), |
89 | | - 'appStore' => $appStore, |
90 | | - 'useTLS' => $this->request->getServerProtocol() === 'https', |
91 | | - 'macOSProfile' => \OCP\Util::linkToRemote('dav') . 'provisioning/apple-provisioning.mobileconfig', |
92 | | - ]; |
93 | | - |
94 | | - $slides = []; |
95 | | - |
96 | | - $slides[] = $this->staticSlide('page.values', $data); |
97 | | - if ($appStore && $this->groupManager->isAdmin($this->userId)) { |
98 | | - $slides[] = $this->staticSlide('page.apps', $data); |
99 | | - } |
100 | | - $slides[] = $this->staticSlide('page.clients', $data); |
101 | | - $slides[] = $this->staticSlide('page.final', $data); |
102 | | - |
103 | | - return new JSONResponse([ |
104 | | - 'hasVideo' => in_array('video', $this->slides, true), |
105 | | - 'slides' => array_values(array_filter($slides, function ($slide) { |
106 | | - return $slide !== null; |
107 | | - })) |
108 | | - ]); |
109 | | - } |
110 | | - |
111 | | - public function staticSlide($name, $params) { |
112 | | - if (!in_array(substr($name, 5), $this->slides, true)) { |
113 | | - return null; |
114 | | - } |
115 | | - |
116 | | - $template = new \OCP\Template($this->appName, $name, false); |
117 | | - |
118 | | - foreach ($params as $key => $value) { |
119 | | - $template->assign($key, $value); |
120 | | - } |
121 | | - |
122 | | - return [ |
123 | | - 'type' => 'inline', |
124 | | - 'content' => $template->fetchPage($params) |
125 | | - ]; |
126 | | - } |
127 | 55 | } |
0 commit comments