From 0ef6812709fa36ed8ae79da144ba114fcdc02fe6 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 Jan 2024 22:07:42 -0700 Subject: [PATCH] Update UserRoleService, add useDefaultFallback parameter --- app/Services/UserRoleService.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/Services/UserRoleService.php b/app/Services/UserRoleService.php index fef5356c..500a4666 100644 --- a/app/Services/UserRoleService.php +++ b/app/Services/UserRoleService.php @@ -6,12 +6,19 @@ use App\Models\UserRoles; class UserRoleService { - public static function can($action, $id) + public static function can($action, $id, $useDefaultFallback = true) { + $default = self::defaultRoles(); $roles = self::get($id); - - return in_array($action, $roles) ? $roles[$action] : null; - } + return + in_array($action, array_keys($roles)) ? + $roles[$action] : + ( + $useDefaultFallback ? + $default[$action] : + false + ); + } public static function get($id) { @@ -36,6 +43,7 @@ class UserRoleService 'can-view-public-feed' => true, 'can-view-network-feed' => true, 'can-view-discover' => true, + 'can-view-hashtag-feed' => false, 'can-post' => true, 'can-comment' => true,