Skip to content

Commit

Permalink
fix: Remove old unused code
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Feb 27, 2024
1 parent c9afec5 commit f04c86a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 103 deletions.
91 changes: 6 additions & 85 deletions lib/Controller/WizardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,20 @@

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 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 +45,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)
];
}
}
19 changes: 1 addition & 18 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,12 +41,10 @@
class WizardControllerTest extends TestCase {
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
protected $config;
private $groupManager;

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

/**
Expand All @@ -58,10 +55,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 All @@ -77,11 +72,6 @@ public function dataDisable() {
* @param string $user
*/
public function testDisable($user) {
$this->config->expects($this->once())
->method('getAppValue')
->with(Application::APP_ID, 'slides', 'video,values,apps,clients,final')
->willReturnArgument(2);

$controller = $this->getController($user);

$this->config->expects($this->once())
Expand All @@ -93,11 +83,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 f04c86a

Please sign in to comment.