From 638f4af9c8862b44c0d1d47b7584cf8a0e131f84 Mon Sep 17 00:00:00 2001 From: Nate Wright Date: Thu, 24 Aug 2023 11:44:19 +0100 Subject: [PATCH] pkp/pkp-lib#9253 Hide site announcements behind feature flag --- api/v1/announcements/PKPAnnouncementHandler.php | 5 +++++ pages/admin/AdminHandler.php | 7 +++++++ pages/announcement/AnnouncementHandler.php | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/api/v1/announcements/PKPAnnouncementHandler.php b/api/v1/announcements/PKPAnnouncementHandler.php index d0f2a48a3e1..7e835274545 100644 --- a/api/v1/announcements/PKPAnnouncementHandler.php +++ b/api/v1/announcements/PKPAnnouncementHandler.php @@ -22,6 +22,7 @@ use APP\facades\Repo; use Exception; use Illuminate\Support\Facades\Bus; +use PKP\config\Config; use PKP\context\Context; use PKP\db\DAORegistry; use PKP\facades\Locale; @@ -94,6 +95,10 @@ public function __construct() */ public function authorize($request, &$args, $roleAssignments) { + if (!Config::getVar('features', 'site_announcements') && !$request->getContext()) { + return false; + } + if (!$request->getContext()) { $roleAssignments = $this->getSiteRoleAssignments($roleAssignments); } diff --git a/pages/admin/AdminHandler.php b/pages/admin/AdminHandler.php index 49e44852e11..98066ec30b6 100644 --- a/pages/admin/AdminHandler.php +++ b/pages/admin/AdminHandler.php @@ -269,6 +269,13 @@ private function siteSettingsAvailability($request) 'announcements', ]; + if (!Config::getVar('features', 'site_announcements')) { + $tabs = array_filter( + $tabs, + function($tab) { return $tab !== 'announcements'; } + ); + } + $singleContextSite = (Services::get('context')->getCount() == 1); $tabsAvailability = []; diff --git a/pages/announcement/AnnouncementHandler.php b/pages/announcement/AnnouncementHandler.php index 564bd3e7cbb..5b2ff2f28e1 100644 --- a/pages/announcement/AnnouncementHandler.php +++ b/pages/announcement/AnnouncementHandler.php @@ -21,6 +21,7 @@ use APP\facades\Repo; use APP\handler\Handler; use APP\template\TemplateManager; +use PKP\config\Config; use PKP\core\PKPRequest; use PKP\security\authorization\ContextRequiredPolicy; @@ -100,6 +101,10 @@ protected function getContextId(Request $request): int protected function isAnnouncementsEnabled(Request $request): bool { + if (!Config::getVar('features', 'site_announcements') && !$request->getContext()) { + return false; + } + $contextOrSite = $request->getContext() ?? $request->getSite(); return $contextOrSite->getData('enableAnnouncements'); }