Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Http/Actions/Roles/SetModeratorAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Seatplus\Auth\Services\Roles\BaseRoleService;
use Seatplus\Auth\Services\Roles\ManualRoleService;
use Seatplus\Auth\Services\Roles\OnRequestRoleService;
use Seatplus\Auth\Services\Roles\OptInRoleService;

class SetModeratorAction
{
Expand All @@ -19,7 +20,7 @@ public function execute(int $role_id, int $user_id, bool $can_moderate): void
$this->baseRoleService->for($role_id);
$this->checkPermission();

/** @var OnRequestRoleService|ManualRoleService $roleService */
/** @var OnRequestRoleService|ManualRoleService|OptInRoleService $roleService */
$roleService = $this->baseRoleService->getTypeService();

$this->validateRoleType($roleService);
Expand All @@ -45,7 +46,7 @@ private function checkPermission(): void

private function validateRoleType(AbstractRoleService $roleService): void
{
if (! $roleService instanceof ManualRoleService && ! $roleService instanceof OnRequestRoleService) {
if (! $roleService instanceof ManualRoleService && ! $roleService instanceof OnRequestRoleService && ! $roleService instanceof OptInRoleService) {
abort(403, 'This action is not allowed');
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Http/Controllers/Auth/RedirectSSOController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public function __construct(
*/
public function __invoke(Socialite $socialite): RedirectResponse
{
throw_if($this->authenticationService->isUserAuthenticated(), \Exception::class, 'You are already authenticated');
if ($this->authenticationService->isUserAuthenticated()) {
return redirect('/');
}

$scopes = $this->getScopes();

Expand Down
9 changes: 9 additions & 0 deletions src/Services/Roles/OptInRoleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public function leaveRole(User $user): void
$this->removeRoleMembership($user);
}

public function setModerator(User $user, bool $can_moderate = true): void
{
$this->setRoleMembership(
entity_id: $user->id,
entity_type: User::class,
can_moderate: $can_moderate
);
}

public function syncMembers(): void
{
// remove all members that are not within the criteria
Expand Down
6 changes: 4 additions & 2 deletions tests/Unit/Controllers/RedirectSSOControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
expect($response->getTargetUrl())->toBe('http://example.com/redirect');
});

it('throws exception when user is already authenticated', function () {
it('redirects home when user is already authenticated', function () {
$this->authenticationServiceMock->shouldReceive('isUserAuthenticated')->andReturn(true);

expect(fn () => $this->controller->__invoke($this->socialiteMock))->toThrow(Exception::class, 'You are already authenticated');
$response = $this->controller->__invoke($this->socialiteMock);

expect($response)->toBeInstanceOf(RedirectResponse::class);
});
Loading