Skip to content

Commit

Permalink
LDAP: Use UI table when listing LDAP servers
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansenDatabay committed Feb 14, 2025
1 parent cd1a812 commit 8ed58f2
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class ilLDAPRoleAssignmentRule
private int $rule_id;

private int $server_id = 0;
private bool$add_on_update = false;
private bool$remove_on_update = false;
private bool $add_on_update = false;
private bool $remove_on_update = false;
private int $plugin_id = 0;
private string $attribute_value = '';
private string $attribute_name = '';
Expand Down
5 changes: 2 additions & 3 deletions components/ILIAS/LDAP/classes/class.ilLDAPServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,15 @@ public static function getServerIds(): array

/**
* Get list of all configured servers
*
* @return int[] list of server
* @return list<array<string, string|int|float|null>> list of server
*/
public static function _getAllServer(): array
{
global $DIC;

$ilDB = $DIC['ilDB'];

$query = "SELECT * FROM ldap_server_settings ORDER BY name";
$query = 'SELECT * FROM ldap_server_settings ORDER BY name';

$server = [];

Expand Down
122 changes: 0 additions & 122 deletions components/ILIAS/LDAP/classes/class.ilLDAPServerTableGUI.php

This file was deleted.

74 changes: 65 additions & 9 deletions components/ILIAS/LDAP/classes/class.ilLDAPSettingsGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class ilLDAPSettingsGUI
private ?string $role_bind_pass = null;
private bool $role_sync_active = false;
private array $attribute_mappings = [];
private readonly \ILIAS\UI\Factory $ui_factory;
private readonly \ILIAS\UI\Renderer $ui_renderer;
private readonly \ILIAS\HTTP\GlobalHttpState $http;
private readonly \ILIAS\Refinery\Factory $refinery;

/**
* @throws ilCtrlException
Expand All @@ -73,13 +77,18 @@ public function __construct(int $a_auth_ref_id)
$this->tabs_gui = $DIC->tabs();
$this->lng = $DIC->language();
$this->lng->loadLanguageModule('ldap');
$this->lng->loadLanguageModule('ui');
$this->ilErr = $DIC['ilErr'];
$this->ilAccess = $DIC->access();
$this->component_repository = $DIC["component.repository"];
$this->rbacReview = $DIC->rbac()->review();
$this->rbacSystem = $DIC->rbac()->system();
$this->toolbar = $DIC->toolbar();
$this->main_tpl = $DIC->ui()->mainTemplate();
$this->http = $DIC->http();
$this->ui_factory = $DIC->ui()->factory();
$this->ui_renderer = $DIC->ui()->renderer();
$this->refinery = $DIC->refinery();

$this->tpl = $DIC->ui()->mainTemplate();

Expand All @@ -96,12 +105,30 @@ public function __construct(int $a_auth_ref_id)
$refinery->kindlyTo()->int()
);
}
if ($http_wrapper->query()->has("ldap_server_id")) {

if ($http_wrapper->query()->has('ldap_server_id')) {
$this->ldap_server_id = $http_wrapper->query()->retrieve(
"ldap_server_id",
'ldap_server_id',
$refinery->kindlyTo()->int()
);
} elseif ($http_wrapper->query()->has('ldap_servers_server_id')) {
$this->ldap_server_id = $http_wrapper->query()->retrieve(
'ldap_servers_server_id',
$this->refinery->in()->series([
$refinery->kindlyTo()->listOf(
$refinery->kindlyTo()->int()
),
$this->refinery->custom()->constraint(
fn($value): bool => count($value) === 1,
$this->lng->txt('select_one')
),
$this->refinery->custom()->transformation(
fn($value): int => $value[0]
)
])
);
}

if ($http_wrapper->query()->has("mapping_id")) {
$this->mapping_id = $http_wrapper->query()->retrieve(
"mapping_id",
Expand Down Expand Up @@ -674,26 +701,55 @@ public function saveMapping(): void
$this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
}

public function serverList(): void
private function handleServerTableActions(): void
{
$action = $this->http->wrapper()->query()->retrieve(
'ldap_servers_table_action',
$this->refinery->byTrying([
$this->refinery->kindlyTo()->string(),
$this->refinery->always('')
])
);
match ($action) {
'editServerSettings' => $this->editServerSettings(),
'activateServer' => $this->activateServer(),
'deactivateServer' => $this->deactivateServer(),
'confirmDeleteServerSettings' => $this->confirmDeleteServerSettings(),
default => $this->ctrl->redirect($this, 'serverList'),
};
}

private function serverList(): void
{
if (!$this->rbacSystem->checkAccess("visible,read", $this->ref_id)) {
if (!$this->rbacSystem->checkAccess('visible,read', $this->ref_id)) {
$this->ilErr->raiseError($this->lng->txt('msg_no_perm_read'), $this->ilErr->WARNING);
}

if (!ilLDAPServer::checkLDAPLib() && $this->server->isActive()) {
$this->main_tpl->setOnScreenMessage('failure', 'Missing LDAP libraries. Please ensure that the PHP LDAP module is installed on your server.');
}

if ($this->rbacSystem->checkAccess("write", $this->ref_id)) {
if ($this->rbacSystem->checkAccess('write', $this->ref_id)) {
$this->toolbar->addButton(
$this->lng->txt("add_ldap_server"),
$this->ctrl->getLinkTarget($this, "addServerSettings")
$this->lng->txt('add_ldap_server'),
$this->ctrl->getLinkTarget($this, 'addServerSettings')
);
}

$table = new ilLDAPServerTableGUI($this, "serverList");
$table = new \ILIAS\LDAP\Server\UI\ServerTable(
ilLDAPServer::_getAllServer(),
$this,
$this->ui_factory,
$this->ui_renderer,
$this->lng,
$this->ctrl,
$this->http->request(),
new \ILIAS\Data\Factory(),
'handleServerTableActions',
$this->rbacSystem->checkAccess('write', $this->ref_id)
);

$this->tpl->setContent($table->getHTML());
$this->tpl->setContent($this->ui_renderer->render($table->getComponent()));
}

public function setServerFormValues(): void
Expand Down
Loading

0 comments on commit 8ed58f2

Please sign in to comment.