Skip to content

Commit e881224

Browse files
committed
WIP move to SSP UI
1 parent 5e2abff commit e881224

File tree

15 files changed

+203
-22
lines changed

15 files changed

+203
-22
lines changed

bin/install.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
$database = Database::getInstance();
2323
$databaseMigration = new DatabaseMigration($database);
2424

25-
if ($databaseMigration->isUpdated()) {
25+
if ($databaseMigration->isMigrated()) {
2626
echo 'Database is up to date, skipping.' . PHP_EOL;
2727
return 0;
2828
}

hooks/hook_federationpage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function oidc_hook_federationpage(Template $template): void
2727
$href = Module::getModuleURL('oidc/admin-clients/index.php');
2828
$text = Translate::noop('OpenID Connect Registry');
2929

30-
if (! (new DatabaseMigration())->isUpdated()) {
30+
if (! (new DatabaseMigration())->isMigrated()) {
3131
$href = Module::getModuleURL('oidc/install.php');
3232
$text = Translate::noop('OpenID Connect Installation');
3333
}

public/assets/css/src/default.css

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,23 @@ h4 {
6565
/* Style for the content area */
6666
.content {
6767
flex-grow: 1;
68-
padding: 20px;
68+
padding-left: 20px;
6969
max-width: inherit;
7070
background-color: #fff;
7171
}
72+
73+
ul.config {
74+
list-style: disc outside none;
75+
}
76+
77+
/* Text colors */
78+
.black-text { color: black; }
79+
.red-text { color: red; }
80+
.lightcoral-text { color: lightcoral; }
81+
.green-text { color: green; }
82+
.yellow-text { color: yellow; }
83+
.blue-text { color: blue; }
84+
.magenta-text { color: magenta; }
85+
.cyan-text { color: cyan; }
86+
.lightcyan-text { color: lightcyan; }
87+
.white-text { color: white; }

routing/routes/routes.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
*/
2626
$routes->add(RoutesEnum::AdminConfigOverview->name, RoutesEnum::AdminConfigOverview->value)
2727
->controller([AdminController::class, 'configOverview']);
28+
$routes->add(RoutesEnum::AdminRunMigrations->name, RoutesEnum::AdminRunMigrations->value)
29+
->controller([AdminController::class, 'runMigrations'])
30+
->methods([HttpMethodsEnum::POST->value]);
2831

2932
/**
3033
* OpenID Connect Discovery routes.

src/Codebooks/RoutesEnum.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ enum RoutesEnum: string
88
{
99
// Admin area
1010
case AdminConfigOverview = 'admin/config-overview';
11+
case AdminRunMigrations = 'admin/run-migrations';
12+
case AdminClients = 'admin/clients';
1113

1214
// Protocols
1315
case Authorization = 'authorization';

src/Controller/AdminController.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
namespace SimpleSAML\Module\oidc\Controller;
66

7+
use SimpleSAML\Locale\Translate;
78
use SimpleSAML\Module\oidc\Admin\Authorization;
89
use SimpleSAML\Module\oidc\Codebooks\RoutesEnum;
910
use SimpleSAML\Module\oidc\Factories\TemplateFactory;
1011
use SimpleSAML\Module\oidc\ModuleConfig;
12+
use SimpleSAML\Module\oidc\Services\DatabaseMigration;
13+
use SimpleSAML\Module\oidc\Services\SessionMessagesService;
14+
use Symfony\Component\HttpFoundation\RedirectResponse;
1115
use Symfony\Component\HttpFoundation\Response;
1216

1317
class AdminController
@@ -16,6 +20,8 @@ public function __construct(
1620
protected readonly ModuleConfig $moduleConfig,
1721
protected readonly TemplateFactory $templateFactory,
1822
protected readonly Authorization $authorization,
23+
protected readonly DatabaseMigration $databaseMigration,
24+
protected readonly SessionMessagesService $sessionMessagesService,
1925
) {
2026
$this->authorization->requireSspAdmin(true);
2127
}
@@ -24,8 +30,26 @@ public function configOverview(): Response
2430
{
2531
return $this->templateFactory->build(
2632
'oidc:config/overview.twig',
27-
['moduleConfig' => $this->moduleConfig],
33+
[
34+
'moduleConfig' => $this->moduleConfig,
35+
'databaseMigration' => $this->databaseMigration,
36+
],
2837
RoutesEnum::AdminConfigOverview->value,
2938
);
3039
}
40+
41+
public function runMigrations(): Response
42+
{
43+
if ($this->databaseMigration->isMigrated()) {
44+
$message = Translate::noop('Database is already migrated.');
45+
$this->sessionMessagesService->addMessage($message);
46+
return new RedirectResponse($this->moduleConfig->getModuleUrl(RoutesEnum::AdminConfigOverview->value));
47+
}
48+
49+
$this->databaseMigration->migrate();
50+
$message = Translate::noop('Database migrated successfully.');
51+
$this->sessionMessagesService->addMessage($message);
52+
53+
return new RedirectResponse($this->moduleConfig->getModuleUrl(RoutesEnum::AdminConfigOverview->value));
54+
}
3155
}

src/Controller/InstallerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(
4242
*/
4343
public function __invoke(ServerRequest $request): Template|RedirectResponse
4444
{
45-
if ($this->databaseMigration->isUpdated()) {
45+
if ($this->databaseMigration->isMigrated()) {
4646
return new RedirectResponse((new HTTP())->addURLParameters('admin-clients/index.php', []));
4747
}
4848

src/Factories/AuthSimpleFactory.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function build(ClientEntityInterface $clientEntity): Simple
4444
*/
4545
public function getDefaultAuthSource(): Simple
4646
{
47-
return new Simple($this->getDefaultAuthSourceId());
47+
return new Simple($this->moduleConfig->getDefaultAuthSourceId());
4848
}
4949

5050
/**
@@ -54,14 +54,6 @@ public function getDefaultAuthSource(): Simple
5454
*/
5555
public function resolveAuthSourceId(ClientEntityInterface $client): string
5656
{
57-
return $client->getAuthSourceId() ?? $this->getDefaultAuthSourceId();
58-
}
59-
60-
/**
61-
* @throws \Exception
62-
*/
63-
public function getDefaultAuthSourceId(): string
64-
{
65-
return $this->moduleConfig->config()->getString(ModuleConfig::OPTION_AUTH_SOURCE);
57+
return $client->getAuthSourceId() ?? $this->moduleConfig->getDefaultAuthSourceId();
6658
}
6759
}

src/Factories/TemplateFactory.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use SimpleSAML\Module\oidc\Bridges\SspBridge;
2323
use SimpleSAML\Module\oidc\Codebooks\RoutesEnum;
2424
use SimpleSAML\Module\oidc\ModuleConfig;
25+
use SimpleSAML\Module\oidc\Services\SessionMessagesService;
2526
use SimpleSAML\XHTML\Template;
2627

2728
class TemplateFactory
@@ -34,6 +35,7 @@ public function __construct(
3435
protected readonly ModuleConfig $moduleConfig,
3536
protected readonly Menu $oidcMenu,
3637
protected readonly SspBridge $sspBridge,
38+
protected readonly SessionMessagesService $sessionMessagesService,
3739
) {
3840
}
3941

@@ -60,6 +62,7 @@ public function build(
6062
'moduleConfiguration' => $this->moduleConfig,
6163
'oidcMenu' => $this->oidcMenu,
6264
'showMenu' => $this->showMenu,
65+
'sessionMessages' => $this->sessionMessagesService->getMessages(),
6366
];
6467

6568
if ($this->sspBridge->module()->isModuleEnabled('admin')) {
@@ -87,6 +90,13 @@ protected function includeDefaultMenuItems(): void
8790
\SimpleSAML\Locale\Translate::noop('Config Overview '),
8891
),
8992
);
93+
94+
$this->oidcMenu->addItem(
95+
$this->oidcMenu->buildItem(
96+
$this->moduleConfig->getModuleUrl(RoutesEnum::AdminClients->value),
97+
\SimpleSAML\Locale\Translate::noop('Clients '),
98+
),
99+
);
90100
}
91101

92102
public function setShowMenu(bool $showMenu): TemplateFactory

src/ModuleConfig.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ public function getIssuer(): string
161161
return $issuer;
162162
}
163163

164+
/**
165+
* @throws \Exception
166+
*/
167+
public function getDefaultAuthSourceId(): string
168+
{
169+
return $this->config()->getString(self::OPTION_AUTH_SOURCE);
170+
}
171+
164172
public function getModuleUrl(string $path = null): string
165173
{
166174
$base = $this->sspBridge->module()->getModuleURL(self::MODULE_NAME);

0 commit comments

Comments
 (0)