From 6cbc12e427157c313ea5aaf856c9998782d375f2 Mon Sep 17 00:00:00 2001 From: Luana Date: Wed, 14 Jun 2023 04:48:38 -0300 Subject: [PATCH] Approval bypass --- core/permissions.php | 1 + core/userclass.php | 1 + ext/approval/main.php | 10 ++++++++++ ext/approval/theme.php | 1 + 4 files changed, 13 insertions(+) diff --git a/core/permissions.php b/core/permissions.php index 0cf1d9c4..0b4bff89 100644 --- a/core/permissions.php +++ b/core/permissions.php @@ -110,6 +110,7 @@ abstract class Permissions public const CRON_ADMIN = "cron_admin"; public const APPROVE_IMAGE = "approve_image"; public const APPROVE_COMMENT = "approve_comment"; + public const BYPASS_IMAGE_APPROVAL = "bypass_image_approval"; public const SET_PRIVATE_IMAGE = "set_private_image"; public const SET_OTHERS_PRIVATE_IMAGES = "set_others_private_images"; diff --git a/core/userclass.php b/core/userclass.php index 22d2f698..8677cc78 100644 --- a/core/userclass.php +++ b/core/userclass.php @@ -217,6 +217,7 @@ new UserClass("admin", "base", [ Permissions::APPROVE_IMAGE => true, Permissions::APPROVE_COMMENT => true, + Permissions::BYPASS_IMAGE_APPROVAL => true, Permissions::CRON_RUN =>true, diff --git a/ext/approval/main.php b/ext/approval/main.php index 90158ff8..b022c98e 100644 --- a/ext/approval/main.php +++ b/ext/approval/main.php @@ -9,6 +9,7 @@ abstract class ApprovalConfig public const VERSION = "ext_approval_version"; public const IMAGES = "approve_images"; public const COMMENTS = "approve_comments"; + public const BYPASS = "approval_bypass"; } class Approval extends Extension @@ -22,10 +23,19 @@ class Approval extends Extension $config->set_default_bool(ApprovalConfig::IMAGES, false); $config->set_default_bool(ApprovalConfig::COMMENTS, false); + $config->set_default_bool(ApprovalConfig::BYPASS, false); Image::$bool_props[] = "approved"; } + public function onImageAddition(ImageAdditionEvent $event) { + global $user, $config; + + if ($config->get_bool(ApprovalConfig::IMAGES) && $config->get_bool(ApprovalConfig::BYPASS) && $user->can(Permissions::BYPASS_IMAGE_APPROVAL)) { + self::approve_image($event->image->id); + } + } + public function onPageRequest(PageRequestEvent $event) { global $page, $user; diff --git a/ext/approval/theme.php b/ext/approval/theme.php index a9dde60d..1db1141d 100644 --- a/ext/approval/theme.php +++ b/ext/approval/theme.php @@ -47,6 +47,7 @@ class ApprovalTheme extends Themelet { $sb = $event->panel->create_new_block("Approval"); $sb->add_bool_option(ApprovalConfig::IMAGES, "Posts: "); + $sb->add_bool_option(ApprovalConfig::BYPASS, "
Enable Bypass (if user has permission): "); } public function display_admin_form()