Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Only show the wizard when any slides are configured (this is the default) #1106

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 15 additions & 28 deletions lib/Controller/WizardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,35 @@

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\AppFramework\Services\IAppConfig;
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 Defaults $theming
* Array of enabled slides - allows an administrator to adjust what is shown
* @var string[]
*/
public function __construct($appName, IRequest $request, IConfig $config, $userId, Defaults $theming, IGroupManager $groupManager) {
protected array $slides;

public function __construct(
string $appName,
IRequest $request,
protected string $userId,
protected IConfig $config,
protected IAppConfig $appConfig,
protected Defaults $theming,
protected IGroupManager $groupManager,
) {
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'));
$this->slides = $this->appConfig->getAppValueArray('slides', ['video', 'values', 'apps' ,'clients', 'final']);
}

/**
Expand Down
48 changes: 13 additions & 35 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 @@ -40,43 +41,16 @@
use OCP\Util;

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;
$this->appHint = $appHint;
$this->jobList = $jobList;
$this->initialState = $initialState;
$this->theming = $theming;
}

public function handle(Event $event): void {
Expand All @@ -89,9 +63,13 @@ public function handle(Event $event): void {
return;
}

// Skip if no slides are defined, but the app is still active (e.g. the admin just wants the "Mobile & desktop" settings section)
if (empty($this->appConfig->getAppValueArray('slides', ['video', 'values', 'apps' ,'clients', 'final']))) {
return;
}

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()]);
}

Expand Down
10 changes: 7 additions & 3 deletions tests/Controller/WizardControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
use OCA\FirstRunWizard\Controller\WizardController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Defaults;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IRequest;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

/**
Expand All @@ -40,13 +42,14 @@
* @group DB
*/
class WizardControllerTest extends TestCase {
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
protected $config;
private IConfig|MockObject $config;
private IAppConfig|MockObject $appConfig;
private $groupManager;

protected function setUp(): void {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->groupManager = $this->createMock(IGroupManager::class);
}

Expand All @@ -58,8 +61,9 @@ protected function getController($user = 'test') {
return new WizardController(
'firstrunwizard',
$this->createMock(IRequest::class),
$this->config,
$user,
$this->config,
$this->appConfig,
\OC::$server->query(Defaults::class),
$this->groupManager
);
Expand Down
Loading