Skip to content

Commit

Permalink
add user object into steps
Browse files Browse the repository at this point in the history
  • Loading branch information
ipula committed Oct 28, 2024
1 parent b6a29ab commit 8beae7b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PKP\invitation\core\InvitationActionRedirectController;
use PKP\invitation\invitations\userRoleAssignment\UserRoleAssignmentInvite;
use PKP\invitation\stepTypes\AcceptInvitationStep;
use APP\facades\Repo;

class UserRoleAssignmentInviteRedirectController extends InvitationActionRedirectController
{
Expand All @@ -35,8 +36,10 @@ public function acceptHandle(Request $request): void
$templateMgr->assign('invitation', $this->invitation);
$context = $request->getContext();
$steps = new AcceptInvitationStep();
$invitationModel = $this->invitation->invitationModel->toArray();
$user = $invitationModel['userId'] ?Repo::user()->get($invitationModel['userId']) : null;
$templateMgr->setState([
'steps' => $steps->getSteps($this->invitation, $context),
'steps' => $steps->getSteps($this->invitation, $context,$user),
'primaryLocale' => $context->getData('primaryLocale'),
'pageTitle' => __('invitation.wizard.pageTitle'),
'invitationId' => (int)$request->getUserVar('id') ?: null,
Expand Down
6 changes: 3 additions & 3 deletions classes/invitation/stepTypes/AcceptInvitationStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use PKP\invitation\sections\Form;
use PKP\invitation\sections\Sections;
use PKP\invitation\steps\Step;
use PKP\user\User;

class AcceptInvitationStep extends InvitationStepTypes
{
Expand All @@ -27,13 +28,12 @@ class AcceptInvitationStep extends InvitationStepTypes
*
* @throws \Exception
*/
public function getSteps(?Invitation $invitation, Context $context): array
public function getSteps(?Invitation $invitation, Context $context, ?User $user): array
{
$steps = [];

switch ($invitation->invitationModel->userId) {
switch ($user) {
case !null:
$user = Repo::user()->get($invitation->invitationModel->userId);
if(!$user->getData('orcidAccessToken')) {
$steps[] = $this->verifyOrcidStep();
$steps[] = $this->acceptInvitationReviewStep($context);
Expand Down
3 changes: 2 additions & 1 deletion classes/invitation/stepTypes/InvitationStepTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
use PKP\context\Context;
use PKP\invitation\core\Invitation;
use PKP\invitation\invitations\userRoleAssignment\UserRoleAssignmentInvite;
use PKP\user\User;

abstract class InvitationStepTypes
{
/**
* Get the invitation steps
* use of the built-in UI for making the invitation
*/
abstract public function getSteps(?Invitation $invitation, Context $context);
abstract public function getSteps(?Invitation $invitation, Context $context, ?User $user): array;

/** fake invitation for email template
*/
Expand Down
5 changes: 3 additions & 2 deletions classes/invitation/stepTypes/SendInvitationStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use PKP\invitation\sections\Sections;
use PKP\invitation\steps\Step;
use PKP\mail\mailables\UserRoleAssignmentInvitationNotify;
use PKP\user\User;
use stdClass;

class SendInvitationStep extends InvitationStepTypes
Expand All @@ -32,10 +33,10 @@ class SendInvitationStep extends InvitationStepTypes
*
* @throws Exception
*/
public function getSteps(?Invitation $invitation, Context $context): array
public function getSteps(?Invitation $invitation, Context $context,?User $user): array
{
$steps = [];
if(!$invitation) {
if(!$invitation && !$user) {
$steps[] = $this->invitationSearchUser();
}
$steps[] = $this->invitationDetailsForm($context);
Expand Down
2 changes: 1 addition & 1 deletion pages/invitation/InvitationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function invite($args, $request): void
];
$steps = new SendInvitationStep();
$templateMgr->setState([
'steps' => $steps->getSteps($invitation, $context),
'steps' => $steps->getSteps($invitation, $context,$user),
'emailTemplatesApiUrl' => $request
->getDispatcher()
->url(
Expand Down

0 comments on commit 8beae7b

Please sign in to comment.