From e51c6bed20468dcd35d37b312d4085a0b473928f Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 24 Jun 2023 12:09:21 +0000 Subject: [PATCH] show a table of user classes, see #921 --- ext/user/main.php | 13 +++++++++++-- ext/user/test.php | 16 ++++++++++++---- ext/user/theme.php | 31 +++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/ext/user/main.php b/ext/user/main.php index 6bfb7451..6b445a0f 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -159,7 +159,7 @@ class UserPage extends Extension public function onPageRequest(PageRequestEvent $event) { - global $config, $database, $page, $user; + global $config, $database, $page, $user, $_shm_user_classes; $this->show_user_info(); @@ -189,6 +189,12 @@ class UserPage extends Extension array_splice($t->columns, 2, 0, [$col]); } $this->theme->display_user_list($page, $t->table($t->query()), $t->paginator()); + } elseif ($event->get_arg(0) == "classes") { + $this->theme->display_user_classes( + $page, + $_shm_user_classes, + (new \ReflectionClass('\Shimmie2\Permissions'))->getConstants() + ); } elseif ($event->get_arg(0) == "logout") { $this->page_logout(); } @@ -399,7 +405,10 @@ class UserPage extends Extension global $user; $event->add_link("My Profile", make_link("user")); if ($user->can(Permissions::EDIT_USER_PASSWORD)) { - $event->add_link("User List", make_link("user_admin/list"), 98); + $event->add_link("User List", make_link("user_admin/list"), 97); + } + if ($user->can(Permissions::EDIT_USER_CLASS)) { + $event->add_link("User Classes", make_link("user_admin/classes"), 98); } $event->add_link("Log Out", make_link("user_admin/logout"), 99); } diff --git a/ext/user/test.php b/ext/user/test.php index 1479b720..1aa90f2a 100644 --- a/ext/user/test.php +++ b/ext/user/test.php @@ -37,12 +37,20 @@ class UserPageTest extends ShimmiePHPUnitTestCase // FIXME: check class //$this->assert_text("Admin:"); $this->log_out(); + } - # FIXME: test user creation - # FIXME: test adminifying - # FIXME: test password reset - + # FIXME: test user creation + # FIXME: test adminifying + # FIXME: test password reset + public function testUserList() + { $this->get_page('user_admin/list'); $this->assert_text("demo"); } + + public function testUserClasses() + { + $this->get_page('user_admin/classes'); + $this->assert_text("admin"); + } } diff --git a/ext/user/theme.php b/ext/user/theme.php index 2a400765..4e4c2069 100644 --- a/ext/user/theme.php +++ b/ext/user/theme.php @@ -345,4 +345,35 @@ class UserPageTheme extends Themelet } return $output; } + + public function display_user_classes(Page $page, array $classes, array $permissions): void { + $table = TABLE(); + + $row = TR(); + $row->appendChild(TH("")); + foreach ($classes as $class) { + $row->appendChild(TH($class->name)); + } + $table->appendChild($row); + + foreach ($permissions as $k => $perm) { + $row = TR(); + $row->appendChild(TH($perm)); + foreach ($classes as $class) { + if($class->can($perm)) { + $cell = TD(["style"=>"color: green;"], "✔"); + } + else { + $cell = TD(["style"=>"color: red;"], "✘"); + } + $row->appendChild($cell); + } + $table->appendChild($row); + } + + $page->set_title("User Classes"); + $page->set_heading("User Classes"); + $page->add_block(new NavBlock()); + $page->add_block(new Block("Classes", $table, "main", 10)); + } }