Skip to content

Commit 3b5d9ea

Browse files
committed
#11021 Change the authorization code for the RoleInvitation API
1 parent bef3c9c commit 3b5d9ea

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

classes/invitation/invitations/userRoleAssignment/handlers/api/UserRoleAssignmentReceiveController.php

+16-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use APP\facades\Repo;
1818
use Carbon\Carbon;
1919
use Core;
20+
use Illuminate\Auth\Access\AuthorizationException;
2021
use Illuminate\Http\JsonResponse;
2122
use Illuminate\Http\Request;
2223
use Illuminate\Http\Response;
@@ -28,6 +29,7 @@
2829
use PKP\invitation\invitations\userRoleAssignment\resources\UserRoleAssignmentInviteResource;
2930
use PKP\invitation\invitations\userRoleAssignment\UserRoleAssignmentInvite;
3031
use PKP\security\authorization\AnonymousUserPolicy;
32+
use PKP\security\authorization\AuthorizationPolicy;
3133
use PKP\security\authorization\UserRequiredPolicy;
3234
use PKP\userGroup\relationships\enums\UserUserGroupMastheadStatus;
3335
use PKPRequest;
@@ -46,13 +48,24 @@ public function authorize(PKPBaseController $controller, PKPRequest $request, ar
4648
{
4749
$this->invitation->changeInvitationUserIdUsingUserEmail();
4850

51+
$loggedInUser = $request->getUser();
52+
4953
$user = $this->invitation->getExistingUser();
5054
if (!isset($user)) {
5155
$controller->addPolicy(new AnonymousUserPolicy($request));
5256
} else {
53-
// Register the user object in the session
54-
$reason = null;
55-
Validation::registerUserSession($user, $reason);
57+
// if there is noone logged-in, the user that the invitation is for, can login automatically
58+
if (!isset($loggedInUser)) {
59+
// Register the user object in the session
60+
$reason = null;
61+
Validation::registerUserSession($user, $reason);
62+
}
63+
64+
// if there is a logged-in user and the user is not the invitation's user, then the user should not be allowed
65+
// to perform the action
66+
if (isset($loggedInUser) && ($loggedInUser->getId() != $user->getId())) {
67+
$controller->addPolicy(new AuthorizationPolicy());
68+
}
5669

5770
$controller->addPolicy(new UserRequiredPolicy($request));
5871
}

0 commit comments

Comments
 (0)