Skip to content

Commit c6e06bc

Browse files
committed
chore: moved menu item registration
1 parent e326b3a commit c6e06bc

File tree

5 files changed

+165
-126
lines changed

5 files changed

+165
-126
lines changed

classes/ColdTrick/SAMLSSO/Menus.php

Lines changed: 0 additions & 108 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace ColdTrick\SAMLSSO\Menus;
4+
5+
use Elgg\Menu\MenuItems;
6+
7+
/**
8+
* Add menu items to the admin_header menu
9+
*/
10+
class AdminHeader {
11+
12+
/**
13+
* Register menu items on the admin pages
14+
*
15+
* @param \Elgg\Event $event 'register', 'menu:admin_header'
16+
*
17+
* @return null|MenuItems
18+
*/
19+
public static function register(\Elgg\Event $event): ?MenuItems {
20+
if (!elgg_is_admin_logged_in() || !elgg_in_context('admin')) {
21+
return null;
22+
}
23+
24+
/* @var $return MenuItems */
25+
$return = $event->getValue();
26+
27+
$return[] = \ElggMenuItem::factory([
28+
'name' => 'manage_idps',
29+
'text' => elgg_echo('admin:configure_utilities:manage_idps'),
30+
'href' => 'admin/configure_utilities/manage_idps',
31+
'parent_name' => 'configure_utilities',
32+
]);
33+
34+
return $return;
35+
}
36+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace ColdTrick\SAMLSSO\Menus;
4+
5+
use Elgg\Menu\MenuItems;
6+
7+
/**
8+
* Add menu items to the entity menu
9+
*/
10+
class Entity {
11+
12+
/**
13+
* Register menu items to the IDP entity
14+
*
15+
* @param \Elgg\Event $event 'register', 'menu:entity'
16+
*
17+
* @return null|MenuItems
18+
*/
19+
public static function registerIDPEdit(\Elgg\Event $event): ?MenuItems {
20+
$entity = $event->getEntityParam();
21+
if (!$entity instanceof \SAMLIDP) {
22+
return null;
23+
}
24+
25+
/* @var $return MenuItems */
26+
$return = $event->getValue();
27+
28+
$return[] = \ElggMenuItem::factory([
29+
'name' => 'edit',
30+
'icon' => 'edit',
31+
'text' => elgg_echo('edit'),
32+
'href' => elgg_http_add_url_query_elements('ajax/form/saml_sso/edit_idp', [
33+
'guid' => $entity->guid,
34+
]),
35+
'link_class' => 'elgg-lightbox',
36+
]);
37+
38+
$return[] = \ElggMenuItem::factory([
39+
'name' => 'force_authentication',
40+
'icon' => 'user-lock',
41+
'text' => elgg_echo('saml_sso:force_authentication:enable'),
42+
'href' => elgg_generate_action_url('saml_sso/force_authentication', [
43+
'guid' => $entity->guid,
44+
]),
45+
'item_class' => $entity->force_authentication ? 'hidden' : null,
46+
'data-toggle' => 'unforce_authentication',
47+
]);
48+
49+
$return[] = \ElggMenuItem::factory([
50+
'name' => 'unforce_authentication',
51+
'icon' => 'user-lock',
52+
'text' => elgg_echo('saml_sso:force_authentication:disable'),
53+
'href' => elgg_generate_action_url('saml_sso/force_authentication', [
54+
'guid' => $entity->guid,
55+
]),
56+
'item_class' => $entity->force_authentication ? null : 'hidden',
57+
'data-toggle' => 'force_authentication',
58+
]);
59+
60+
return $return;
61+
}
62+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace ColdTrick\SAMLSSO\Menus;
4+
5+
use Elgg\Menu\MenuItems;
6+
7+
/**
8+
* Add menu items to the login menu
9+
*/
10+
class Login {
11+
12+
/**
13+
* Register menu items to the IDP entity
14+
*
15+
* @param \Elgg\Event $event 'register', 'menu:login'
16+
*
17+
* @return null|MenuItems
18+
*/
19+
public static function register(\Elgg\Event $event): ?MenuItems {
20+
$entities = elgg_get_entities([
21+
'type' => 'object',
22+
'subtype' => \SAMLIDP::SUBTYPE,
23+
'limit' => false,
24+
]);
25+
26+
if (empty($entities)) {
27+
return null;
28+
}
29+
30+
/* @var $return MenuItems */
31+
$return = $event->getValue();
32+
33+
/* @var $entity \SAMLIDP */
34+
foreach ($entities as $entity) {
35+
if (!$entity->showOnLoginForm()) {
36+
continue;
37+
}
38+
39+
$id = $entity->getIDPID();
40+
$return[] = \ElggMenuItem::factory([
41+
'name' => "login_{$id}",
42+
'text' => elgg_echo('login') . " ({$entity->getDisplayName()})",
43+
'href' => elgg_generate_entity_url($entity, 'login'),
44+
]);
45+
}
46+
47+
return $return;
48+
}
49+
}

elgg-plugin.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,54 @@
1818
'class' => \SAMLIDP::class,
1919
],
2020
],
21+
'actions' => [
22+
'saml_sso/add_idp_from_xml' => [
23+
'access' => 'admin',
24+
],
25+
'saml_sso/edit_idp' => [
26+
'access' => 'admin',
27+
],
28+
'saml_sso/force_authentication' => [
29+
'access' => 'admin',
30+
],
31+
],
2132
'routes' => [
2233
'login:object:saml_idp' => [
2334
'path' => 'saml_idp/login/{guid}',
24-
'controller' => ColdTrick\SAMLSSO\Controller\SSO::class,
35+
'controller' => \ColdTrick\SAMLSSO\Controller\SSO::class,
2536
'middleware' => [
2637
LoggedOutGatekeeper::class,
2738
],
2839
'walled' => false,
2940
],
3041
'acs:object:saml_idp' => [
3142
'path' => 'saml_idp/acs/{guid}',
32-
'controller' => ColdTrick\SAMLSSO\Controller\ACS::class,
43+
'controller' => \ColdTrick\SAMLSSO\Controller\ACS::class,
3344
'walled' => false,
3445
],
3546
'logout:object:saml_idp' => [
3647
'path' => 'saml_idp/logout/{guid}',
37-
'controller' => ColdTrick\SAMLSSO\Controller\SLO::class,
48+
'controller' => \ColdTrick\SAMLSSO\Controller\SLO::class,
3849
'middleware' => [
3950
Gatekeeper::class,
4051
],
4152
],
4253
'metadata:object:saml_idp' => [
4354
'path' => 'saml_idp/metadata/{guid}',
44-
'controller' => ColdTrick\SAMLSSO\Controller\Metadata::class,
55+
'controller' => \ColdTrick\SAMLSSO\Controller\Metadata::class,
4556
'walled' => false,
4657
],
4758
],
4859
'events' => [
4960
'register' => [
5061
'menu:entity' => [
51-
'\ColdTrick\SAMLSSO\Menus::registerIDPEdit' => [],
62+
'\ColdTrick\SAMLSSO\Menus\Entity::registerIDPEdit' => [],
5263
],
5364
'menu:login' => [
54-
'\ColdTrick\SAMLSSO\Menus::registerLoginMenu' => [],
65+
'\ColdTrick\SAMLSSO\Menus\Login::register' => [],
5566
],
5667
'menu:admin_header' => [
57-
'\ColdTrick\SAMLSSO\Menus::registerAdminPageMenu' => [],
68+
'\ColdTrick\SAMLSSO\Menus\AdminHeader::register' => [],
5869
],
5970
],
6071
'response' => [
@@ -63,17 +74,6 @@
6374
],
6475
],
6576
],
66-
'actions' => [
67-
'saml_sso/add_idp_from_xml' => [
68-
'access' => 'admin',
69-
],
70-
'saml_sso/edit_idp' => [
71-
'access' => 'admin',
72-
],
73-
'saml_sso/force_authentication' => [
74-
'access' => 'admin',
75-
],
76-
],
7777
'view_extensions' => [
7878
'page/default' => [
7979
'saml_sso/force_authentication' => ['priority' => 200],

0 commit comments

Comments
 (0)