show a table of user classes, see #921

This commit is contained in:
Shish
2023-06-24 12:09:21 +00:00
parent c39a340092
commit e51c6bed20
3 changed files with 54 additions and 6 deletions

View File

@@ -159,7 +159,7 @@ class UserPage extends Extension
public function onPageRequest(PageRequestEvent $event) public function onPageRequest(PageRequestEvent $event)
{ {
global $config, $database, $page, $user; global $config, $database, $page, $user, $_shm_user_classes;
$this->show_user_info(); $this->show_user_info();
@@ -189,6 +189,12 @@ class UserPage extends Extension
array_splice($t->columns, 2, 0, [$col]); array_splice($t->columns, 2, 0, [$col]);
} }
$this->theme->display_user_list($page, $t->table($t->query()), $t->paginator()); $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") { } elseif ($event->get_arg(0) == "logout") {
$this->page_logout(); $this->page_logout();
} }
@@ -399,7 +405,10 @@ class UserPage extends Extension
global $user; global $user;
$event->add_link("My Profile", make_link("user")); $event->add_link("My Profile", make_link("user"));
if ($user->can(Permissions::EDIT_USER_PASSWORD)) { 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); $event->add_link("Log Out", make_link("user_admin/logout"), 99);
} }

View File

@@ -37,12 +37,20 @@ class UserPageTest extends ShimmiePHPUnitTestCase
// FIXME: check class // FIXME: check class
//$this->assert_text("Admin:"); //$this->assert_text("Admin:");
$this->log_out(); $this->log_out();
}
# FIXME: test user creation # FIXME: test user creation
# FIXME: test adminifying # FIXME: test adminifying
# FIXME: test password reset # FIXME: test password reset
public function testUserList()
{
$this->get_page('user_admin/list'); $this->get_page('user_admin/list');
$this->assert_text("demo"); $this->assert_text("demo");
} }
public function testUserClasses()
{
$this->get_page('user_admin/classes');
$this->assert_text("admin");
}
} }

View File

@@ -345,4 +345,35 @@ class UserPageTheme extends Themelet
} }
return $output; 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));
}
} }