From 5cbbe5e1b3e1e8bb466a5775a5b0918c34060463 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 4 May 2024 15:43:29 +0100 Subject: [PATCH] [core] remove is_logged_in This was only used in a couple of places, and user classes are more useful --- core/user.php | 6 ------ ext/bulk_actions/main.php | 20 +++++++++----------- ext/pools/main.php | 12 +++++++----- ext/transcode/main.php | 3 +-- ext/user/main.php | 5 ++++- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/core/user.php b/core/user.php index ebfc85a3..d415b48a 100644 --- a/core/user.php +++ b/core/user.php @@ -171,12 +171,6 @@ class User return ($this->id === $config->get_int('anon_id')); } - public function is_logged_in(): bool - { - global $config; - return ($this->id !== $config->get_int('anon_id')); - } - public function set_class(string $class): void { global $database; diff --git a/ext/bulk_actions/main.php b/ext/bulk_actions/main.php index 11b68faf..7d298664 100644 --- a/ext/bulk_actions/main.php +++ b/ext/bulk_actions/main.php @@ -68,20 +68,18 @@ class BulkActions extends Extension { global $page, $user; - if ($user->is_logged_in()) { - $babbe = new BulkActionBlockBuildingEvent(); - $babbe->search_terms = $event->search_terms; + $babbe = new BulkActionBlockBuildingEvent(); + $babbe->search_terms = $event->search_terms; - send_event($babbe); + send_event($babbe); - if (sizeof($babbe->actions) == 0) { - return; - } - - usort($babbe->actions, [$this, "sort_blocks"]); - - $this->theme->display_selector($page, $babbe->actions, Tag::implode($event->search_terms)); + if (sizeof($babbe->actions) == 0) { + return; } + + usort($babbe->actions, [$this, "sort_blocks"]); + + $this->theme->display_selector($page, $babbe->actions, Tag::implode($event->search_terms)); } public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event): void diff --git a/ext/pools/main.php b/ext/pools/main.php index 6ff10135..9bad4294 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -551,13 +551,15 @@ class Pools extends Extension public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event): void { - global $database; + global $database, $user; - $options = $database->get_pairs("SELECT id,title FROM pools ORDER BY title"); + if(!$user->can(Permissions::POOLS_UPDATE)) { + $options = $database->get_pairs("SELECT id,title FROM pools ORDER BY title"); - // TODO: Don't cast into strings, make BABBE accept HTMLElement instead. - $event->add_action("bulk_pool_add_existing", "Add To (P)ool", "p", "", (string) $this->theme->get_bulk_pool_selector($options)); - $event->add_action("bulk_pool_add_new", "Create Pool", "", "", (string) $this->theme->get_bulk_pool_input($event->search_terms)); + // TODO: Don't cast into strings, make BABBE accept HTMLElement instead. + $event->add_action("bulk_pool_add_existing", "Add To (P)ool", "p", "", (string) $this->theme->get_bulk_pool_selector($options)); + $event->add_action("bulk_pool_add_new", "Create Pool", "", "", (string) $this->theme->get_bulk_pool_input($event->search_terms)); + } } public function onBulkAction(BulkActionEvent $event): void diff --git a/ext/transcode/main.php b/ext/transcode/main.php index 068aa983..025f58f8 100644 --- a/ext/transcode/main.php +++ b/ext/transcode/main.php @@ -260,9 +260,8 @@ class TranscodeImage extends Extension { global $user, $config; - $engine = $config->get_string(TranscodeConfig::ENGINE); - if ($user->can(Permissions::EDIT_FILES)) { + $engine = $config->get_string(TranscodeConfig::ENGINE); $event->add_action(self::ACTION_BULK_TRANSCODE, "Transcode Image", null, "", $this->theme->get_transcode_picker_html($this->get_supported_output_mimes($engine))); } } diff --git a/ext/user/main.php b/ext/user/main.php index ec67f8fd..eff8d1c5 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -393,7 +393,10 @@ class UserPage extends Extension $this->theme->display_user_links($page, $user, $ubbe->get_parts()); } if ( - ($user->can(Permissions::VIEW_IP) || ($user->is_logged_in() && $user->id == $event->display_user->id)) && # admin or self-user + ( + $user->can(Permissions::VIEW_IP) || # user can view all IPS + ($user->id == $event->display_user->id) # or user is viewing themselves + ) && ($event->display_user->id != $config->get_int('anon_id')) # don't show anon's IP list, it is le huge ) { $this->theme->display_ip_list(