diff --git a/etc/social_login.php b/etc/social_login.php index f268001a..74b0c224 100644 --- a/etc/social_login.php +++ b/etc/social_login.php @@ -28,7 +28,7 @@ 'profile_handler' => \Lyrasoft\Luna\Auth\Profile\GoogleProfileHandler::class ], 'LINE' => [ - 'enabled' => true, + 'enabled' => false, 'adapter' => \Lyrasoft\Luna\Auth\Provider\LineSocialProvider::class, 'keys' => [ 'id' => env('LINE_SOCIAL_ID'), diff --git a/src/Access/AccessService.php b/src/Access/AccessService.php index 5adcbca8..dc88befc 100644 --- a/src/Access/AccessService.php +++ b/src/Access/AccessService.php @@ -168,7 +168,7 @@ public function checkRoleAllowForRules(UserRole $role, array $rules): ?bool * * @return array */ - public function getUserRoles(mixed $user): array + public function getUserRoles(mixed $user = null): array { $user = $this->getUser($user); @@ -202,7 +202,7 @@ function () use ($id) { * * @return array */ - public function addRoleMapsToUser(mixed $user, mixed $roleMaps): array + public function addRoleMapsToUser(mixed $user = null, mixed $roleMaps = []): array { $currentRoleIds = collect($this->getUserRoles($user)) ->map(fn(UserRole $map) => $map->getId()) @@ -243,7 +243,7 @@ public function addRoleMapsToUser(mixed $user, mixed $roleMaps): array * @return array * @throws \ReflectionException */ - public function addRolesToUser(mixed $user, mixed $roles, array $extra = []): array + public function addRolesToUser(mixed $user = null, mixed $roles = [], array $extra = []): array { $currentRoleIds = collect($this->getUserRoles($user)) ->map(fn(UserRole $map) => $map->getId()) @@ -278,7 +278,7 @@ public function addRolesToUser(mixed $user, mixed $roles, array $extra = []): ar return $maps; } - public function removeRoleFromUser(mixed $user, mixed $roles): void + public function removeRoleFromUser(mixed $user = null, mixed $roles = []): void { $user = $this->getUser($user); @@ -301,8 +301,9 @@ public function removeRoleFromUser(mixed $user, mixed $roles): void ); } - public function userIsRole(mixed $user, string|int|UserRole $role): bool + public function userIsRole(mixed $user = null, mixed $role = null): bool { + $user ??= $this->getUser(); $roleId = $this->unwrapRole($role); $roles = $this->getUserRoles($user); @@ -316,6 +317,23 @@ public function userIsRole(mixed $user, string|int|UserRole $role): bool return false; } + public function userInRoles(mixed $user = null, mixed $roles = []): bool + { + $user ??= $this->getUser(); + + if (!is_array($roles)) { + $roles = [$roles]; + } + + foreach ($roles as $role) { + if ($this->userIsRole($user, $role)) { + return true; + } + } + + return false; + } + public function isSuperUser(mixed $user = null): bool { return $this->check(static::SUPERUSER_ACTION, $user); @@ -394,8 +412,9 @@ public function isChildRole(UserRole|string|int $targetRole, UserRole|string|int * * @return array */ - public function getAllowedRolesForUser(mixed $user): array + public function getAllowedRolesForUser(mixed $user = null): array { + $user ??= $this->getUser(); $roles = $this->getRoles(); $userRoles = $this->getUserRoles($user); $allowed = [];