Skip to content

Commit

Permalink
fix: Drop outdated code and add option to disable the wizard
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Feb 27, 2024
1 parent c9afec5 commit 6988c44
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 124 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ A first run wizard that explains the usage of Nextcloud to new users

![](https://user-images.githubusercontent.com/3404133/51537050-bcc73e00-1e4d-11e9-8de0-29e6951c2b29.png)

## Configuration

No configuration is needed, but it is possible to prevent the wizard from opening for users by default.
When disabled users can only open it from manually clicking "About" in the user menu.

This can be done by setting an app setting value:

```
occ config:app:set --value false firstrunwizard wizard_enabled
```

## Development setup

Expand Down
85 changes: 7 additions & 78 deletions lib/Controller/WizardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,28 @@

namespace OCA\FirstRunWizard\Controller;

use OCA\FirstRunWizard\AppInfo\Application;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Defaults;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IRequest;

class WizardController extends Controller {

/** @var IConfig */
protected $config;

/** @var string */
protected $userId;

/** @var Defaults */
protected $theming;

/** @var IGroupManager */
protected $groupManager;

/** @var array|false|string[] */
protected $slides = [];

/**
* @param string $appName
* @param IRequest $request
* @param IConfig $config
* @param string $userId
* @param
* @param Defaults $theming
*/
public function __construct($appName, IRequest $request, IConfig $config, $userId, Defaults $theming, IGroupManager $groupManager) {
public function __construct(
string $appName,
IRequest $request,
private string $userId,
private IConfig $config,
) {
parent::__construct($appName, $request);

$this->config = $config;
$this->userId = $userId;
$this->theming = $theming;
$this->groupManager = $groupManager;

$this->slides = explode(',', $this->config->getAppValue(Application::APP_ID, 'slides', 'video,values,apps,clients,final'));
}

/**
Expand All @@ -73,55 +53,4 @@ public function disable() {
$this->config->setUserValue($this->userId, 'firstrunwizard', 'show', '0');
return new DataResponse();
}

/**
* @NoAdminRequired
* @return JsonResponse
*/
public function show() {
$appStore = $this->config->getSystemValue('appstoreenabled', true);

$data = [
'desktop' => $this->config->getSystemValue('customclient_desktop', $this->theming->getSyncClientUrl()),
'android' => $this->config->getSystemValue('customclient_android', $this->theming->getAndroidClientUrl()),
'fdroid' => $this->config->getSystemValue('customclient_fdroid', $this->theming->getFDroidClientUrl()),
'ios' => $this->config->getSystemValue('customclient_ios', $this->theming->getiOSClientUrl()),
'appStore' => $appStore,
'useTLS' => $this->request->getServerProtocol() === 'https',
'macOSProfile' => \OCP\Util::linkToRemote('dav') . 'provisioning/apple-provisioning.mobileconfig',
];

$slides = [];

$slides[] = $this->staticSlide('page.values', $data);
if ($appStore && $this->groupManager->isAdmin($this->userId)) {
$slides[] = $this->staticSlide('page.apps', $data);
}
$slides[] = $this->staticSlide('page.clients', $data);
$slides[] = $this->staticSlide('page.final', $data);

return new JSONResponse([
'hasVideo' => in_array('video', $this->slides, true),
'slides' => array_values(array_filter($slides, function ($slide) {
return $slide !== null;
}))
]);
}

public function staticSlide($name, $params) {
if (!in_array(substr($name, 5), $this->slides, true)) {
return null;
}

$template = new \OCP\Template($this->appName, $name, '');

foreach ($params as $key => $value) {
$template->assign($key, $value);
}

return [
'type' => 'inline',
'content' => $template->fetchPage($params)
];
}
}
50 changes: 16 additions & 34 deletions lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCA\FirstRunWizard\AppInfo\Application;
use OCA\FirstRunWizard\Notification\AppHint;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\BackgroundJob\IJobList;
use OCP\Defaults;
Expand All @@ -43,36 +44,15 @@
* @template-implements IEventListener<BeforeTemplateRenderedEvent>
*/
class BeforeTemplateRenderedListener implements IEventListener {
/**
* @var IUserSession
*/
private $userSession;
/**
* @var IConfig
*/
private $config;
/**
* @var AppHint
*/
private $appHint;
/**
* @var IJobList
*/
private $jobList;

/** @var IInitialState */
protected $initialState;

/** @var Defaults */
protected $theming;

public function __construct(
IConfig $config,
IUserSession $userSession,
IJobList $jobList,
AppHint $appHint,
IInitialState $initialState,
Defaults $theming,
private IConfig $config,
private IAppConfig $appConfig,
private IUserSession $userSession,
private IJobList $jobList,
private AppHint $appHint,
private IInitialState $initialState,
private Defaults $theming,
) {
$this->userSession = $userSession;
$this->config = $config;
Expand All @@ -92,14 +72,16 @@ public function handle(Event $event): void {
return;
}

if ($this->config->getUserValue($user->getUID(), Application::APP_ID, 'show', '1') !== '0') {
Util::addScript(Application::APP_ID, 'activate');
if ($this->appConfig->getAppValueBool('wizard_enabled', true)) {
if ($this->config->getUserValue($user->getUID(), Application::APP_ID, 'show', '1') !== '0') {
Util::addScript(Application::APP_ID, 'activate');

$this->jobList->add('OCA\FirstRunWizard\Notification\BackgroundJob', ['uid' => $this->userSession->getUser()->getUID()]);
}
$this->jobList->add('OCA\FirstRunWizard\Notification\BackgroundJob', ['uid' => $this->userSession->getUser()->getUID()]);
}

if ($this->config->getSystemValueBool('appstoreenabled', true)) {
$this->appHint->sendAppHintNotifications();
if ($this->config->getSystemValueBool('appstoreenabled', true)) {
$this->appHint->sendAppHintNotifications();
}
}

Util::addScript(Application::APP_ID, 'about');
Expand Down
13 changes: 1 addition & 12 deletions tests/Controller/WizardControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use OCA\FirstRunWizard\Controller\WizardController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\Defaults;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IRequest;
Expand All @@ -42,7 +41,6 @@
class WizardControllerTest extends TestCase {
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
protected $config;
private $groupManager;

protected function setUp(): void {
parent::setUp();
Expand All @@ -58,10 +56,8 @@ protected function getController($user = 'test') {
return new WizardController(
'firstrunwizard',
$this->createMock(IRequest::class),
$this->config,
$user,
\OC::$server->query(Defaults::class),
$this->groupManager
$this->config,
);
}

Expand Down Expand Up @@ -93,11 +89,4 @@ public function testDisable($user) {
$this->assertInstanceOf(DataResponse::class, $response);
$this->assertSame(Http::STATUS_OK, $response->getStatus());
}

public function dataShowAdmin(): array {
return [
'app store enabled' => [true, 4],
'app store disabled' => [false, 3]
];
}
}

0 comments on commit 6988c44

Please sign in to comment.