Update UserRoleService, add useDefaultFallback parameter

This commit is contained in:
Daniel Supernault 2024-01-02 22:07:42 -07:00
parent cbe75ce871
commit 0ef6812709
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -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,