Skip to content

Commit

Permalink
fix bugs in user edit and invitation workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ipula committed Feb 25, 2025
1 parent a2b977d commit c2f9b5e
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 29 deletions.
4 changes: 2 additions & 2 deletions api/v1/users/PKPUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public function endRole(Request $request): JsonResponse
{
// Ensure user exists
$userId = $request->route('userId');
$user = Repo::user()->get($userId);
$user = Repo::user()->get($userId, true);
if (!$user) {
return response()->json([
'error' => __('api.404.resourceNotFound')
Expand Down Expand Up @@ -331,7 +331,7 @@ public function endRole(Request $request): JsonResponse
Mail::send($mailable);

// Return updated user model
$user = Repo::user()->get($userId);
$user = Repo::user()->get($userId, true);
return response()->json(Repo::user()->getSchemaMap()->map($user), Response::HTTP_OK);
}

Expand Down
2 changes: 1 addition & 1 deletion classes/mail/mailables/UserRoleEndNotify.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function setData(?string $locale = null): void
$targetPath = Core::getBaseDir() . '/lib/pkp/styles/mailables/style.css';
$emailTemplateStyle = file_get_contents($targetPath);

$role = $this->userGroup->getName($locale);
$role = $this->userGroup->getLocalizedData('name');

// Set view data for the template
$this->viewData = array_merge(
Expand Down
9 changes: 5 additions & 4 deletions classes/user/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ protected function mapByProperties(array $props, User $user, array $auxiliaryDat
$userGroups = UserGroup::query()
->withContextIds($this->context->getId())
->whereHas('userUserGroups', function ($query) use ($user) {
$query->withUserId($user->getId())
->withActive();
$query->withUserId($user->getId());
})
->get();

Expand All @@ -186,9 +185,11 @@ protected function mapByProperties(array $props, User $user, array $auxiliaryDat
'permitMetadataEdit' => (bool) $userGroup->permitMetadataEdit,
'recommendOnly' => (bool) $userGroup->recommendOnly,
'dateStart' => UserUserGroup::withUserId($user->getId())
->withActive()
->withUserGroupIds([$userGroup->id])
->pluck('date_start')->first()
->pluck('date_start')->first(),
'dateEnd' => UserUserGroup::withUserId($user->getId())
->withUserGroupIds([$userGroup->id])
->pluck('date_end')->first(),
];
}
}
Expand Down
8 changes: 8 additions & 0 deletions classes/userGroup/relationships/UserUserGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,12 @@ public function scopeSortBy(Builder $query, string $column, ?string $direction =
{
return $query->orderBy('user_user_groups.' . $column, $direction);
}

public function scopeWithActiveInFuture(Builder $query): Builder
{
$currentDateTime = Core::getCurrentDate();
return $query->whereNotNull('user_user_groups.date_start')
->where('user_user_groups.date_start', '>', $currentDateTime)
->orderBy('user_user_groups.date_start', 'asc');
}
}
2 changes: 1 addition & 1 deletion controllers/grid/settings/user/UserGridHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public function removeUser($args, $request)
->whereHas('userGroup', function ($query) use ($context) {
$query->withContextIds($context->getId());
})
->update(['dateEnd' => now()]);
->update(['date_end' => now()]);

return \PKP\db\DAO::getDataChangedEvent($userId);
}
Expand Down
18 changes: 16 additions & 2 deletions locale/en/grid.po
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,10 @@ msgid "grid.user.email"
msgstr "Email"

msgid "grid.user.enable"
msgstr "Enable"
msgstr "Enable User"

msgid "grid.user.disable"
msgstr "Disable"
msgstr "Disable User"

msgid "grid.user.disableReason"
msgstr "Reason for disabling user"
Expand Down Expand Up @@ -716,3 +716,17 @@ msgstr "In Browse Lists"

msgid "grid.action.editContributor"
msgstr "Edit Contributor"

msgid "grid.user.remove"
msgstr "Remove User"

msgid "grid.user.logInAs"
msgstr "Login As"

msgid "grid.user.enableReasonDescription"
msgstr "Once the user is enabled, they will regain access to the site, and you'll be able to invite them to roles as needed."

msgid "grid.user.disableReasonDescription"
msgstr "Please note that once a user is disabled, you won't be able to add them to any roles until the user is enabled again."


23 changes: 14 additions & 9 deletions locale/en/invitation.po
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,10 @@ msgid "userInvitation.searchUser.nextButtonLabel"
msgstr "Search User"

msgid "userInvitation.searchUser.stepDescription"
msgstr "Search for the user using their email address, username or ORCID ID. Enter at least one details to get started. If the user does not exist, you can invite them to take up roles and be a part of your journal. If the user already exist in the system, you can view user information and invite to take a additional roles."
msgstr "If the user does not exist, you can invite them to take on roles. If the user already exists in the system, you can view their information and invite them to take on additional roles."

msgid "userInvitation.emailField.description"
msgstr "e.g. aeinstein@example.com"

msgid "userInvitation.usernameField.description"
msgstr "e.g. mickeymouse"

msgid "userInvitation.orcidField.description"
msgstr "e.g. 0000-0000-0000-0000"
msgid "userInvitation.searchField.description"
msgstr "e.g. aeinstein@example.com or aeinstein or 0000-0002-1825-0097"

msgid "userInvitation.enterDetails.stepName"
msgstr "Enter details"
Expand Down Expand Up @@ -372,3 +366,14 @@ msgstr "Invitation not accepted. You're logged in as a different user."

msgid "acceptInvitation.authorization.message"
msgstr "Please log out and sign in with the correct account to accept this invitation."

msgid "userInvitation.searchField"
msgstr "Search for a user by email address, username, or ORCID iD. Enter only one to get started!"

msgid "userInvitation.user.disableTitle"
msgstr "The user is currently disabled."

msgid "userInvitation.user.disableMessage"
msgstr "The user was disabled. You cannot assign them a role while they are disabled. Please enable the user first to invite them to a role."


15 changes: 15 additions & 0 deletions locale/en/user.po
Original file line number Diff line number Diff line change
Expand Up @@ -853,3 +853,18 @@ msgstr "This ORCID has not been verified. Please remove this unverified ORCID an

msgid "user.removeRole.message"
msgstr "Are you sure want remove this role permanently?"

msgid "user.futureRole.notification.message"
msgstr "Your role is scheduled to begin on {$roleStartDate}"

msgid "user.futureRole.notification.description"
msgstr "Until then, you can review and update your profile. If you believe this is an error, please contact the administrator."

msgid "user.disabledModal.description"
msgstr "Current Roles : {$roles}"

msgid "user.disabledModal.title"
msgstr "Disable {$fullName}"

msgid "user.enabledModal.title"
msgstr "Enable {$fullName}"
17 changes: 11 additions & 6 deletions pages/invitation/InvitationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function invite(array $args, Request $request): void
'givenName' => '',
'familyName' => '',
'orcidValidation' => false,
'disabled' => false,
'userGroupsToAdd' => [
[
'userGroupId' => null,
Expand Down Expand Up @@ -169,6 +170,7 @@ public function invite(array $args, Request $request): void
'emailBody' => $payload['emailBody'],
'emailSubject' => $payload['emailSubject'],
];
$invitationPayload['disabled'] = false;
}
$templateMgr = TemplateManager::getManager($request);
$breadcrumbs = $templateMgr->getTemplateVars('breadcrumbs');
Expand All @@ -181,10 +183,11 @@ public function invite(array $args, Request $request): void
->getDispatcher()
->url(
$request,
PKPApplication::ROUTE_PAGE,
$request->getContext()->getPath(),
Application::ROUTE_PAGE,
null,
'management',
'settings',
['access']
)
];
$breadcrumbs[] = [
Expand Down Expand Up @@ -239,8 +242,8 @@ public function editUser($args, $request): void
$invitation = null;
$invitationPayload =[];
if(!empty($args)) {
$invitationMode = 'edit';
$user = Repo::user()->get($args[0]);
$invitationMode = 'editUser';
$user = Repo::user()->get($args[0],true);
$invitationPayload['userId'] = $args[0];
$invitationPayload['inviteeEmail'] = $user->getEmail();
$invitationPayload['orcid'] = $user->getData('orcid');
Expand All @@ -250,6 +253,7 @@ public function editUser($args, $request): void
$invitationPayload['country'] = $user->getCountry();
$invitationPayload['biography'] = $user->getBiography(null);
$invitationPayload['phone'] = $user->getPhone();
$invitationPayload['disabled'] = $user->getData('disabled');
$invitationPayload['userGroupsToAdd'] = [];
$invitationPayload['currentUserGroups'] = $this->getUserUserGroups($args[0],$request->getContext());
$invitationPayload['userGroupsToRemove'] = [];
Expand All @@ -268,10 +272,11 @@ public function editUser($args, $request): void
->getDispatcher()
->url(
$request,
PKPApplication::ROUTE_PAGE,
$request->getContext()->getPath(),
Application::ROUTE_PAGE,
null,
'management',
'settings',
['access']
)
];
$breadcrumbs[] = [
Expand Down
13 changes: 12 additions & 1 deletion pages/user/ProfileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PKP\core\PKPRequest;
use PKP\security\authorization\PKPSiteAccessPolicy;
use PKP\security\authorization\UserRequiredPolicy;
use PKP\userGroup\relationships\UserUserGroup;

class ProfileHandler extends UserHandler
{
Expand Down Expand Up @@ -58,8 +59,9 @@ public function authorize($request, &$args, $roleAssignments)
public function profile($args, $request)
{
$context = $request->getContext();
$user = $request->getUser();
$date_start = null;
if (!$context) {
$user = $request->getUser();
$contextDao = Application::getContextDAO();
$workingContexts = $contextDao->getAvailable($user ? $user->getId() : null);
[$firstContext, $secondContext] = [$workingContexts->next(), $workingContexts->next()];
Expand All @@ -74,11 +76,20 @@ public function profile($args, $request)
$request->redirect(null, null, null, null, null, $anchor);
}

if(count($user->getRoles($context->getId())) === 0){
$userFutureRoleStartDate = UserUserGroup::withUserId($user->getId())
->withActiveInFuture()
->pluck('date_start')
->first();
$date_start = new \DateTime($userFutureRoleStartDate);
}

$this->setupTemplate($request);

$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign([
'pageTitle' => __('user.profile'),
'userFutureRoleStartDate'=> $date_start?->format('Y-m-d'),
]);
$templateMgr->display('user/profile.tpl');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

{if $enable}
{fbvFormSection title="grid.user.enableReason" for="disableReason"}
<p class="mb-4">{translate key ="grid.user.enableReasonDescription"}</p>
{fbvElement type="textarea" id="disableReason" value=$disableReason size=$fbvStyles.size.LARGE}
{/fbvFormSection}
{else}
{fbvFormSection title="grid.user.disableReason" for="disableReason"}
<p class="mb-4">{translate key ="grid.user.disableReasonDescription"}</p>
{fbvElement type="textarea" id="disableReason" value=$disableReason size=$fbvStyles.size.LARGE}
{/fbvFormSection}
{/if}
Expand Down
8 changes: 5 additions & 3 deletions templates/layouts/backend.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
{/if}
></initials-avatar>
{if $isUserLoggedInAs}
<initials-avatar
<initials-avatar
class="absolute right-2 top-2 rounded-full h-5 w-5"
:is-warnable="true"
:shrink="true"
Expand Down Expand Up @@ -154,8 +154,10 @@

<div class="app__body">
{block name="menu"}
<pkp-side-nav :links="menu" aria-label="{translate key="common.navigation.site"}">
</pkp-side-nav>
{if isset($currentContext) && isset($currentUser) && $currentUser->getRoles($currentContext->getId())|count > 0}
<pkp-side-nav :links="menu" aria-label="{translate key="common.navigation.site"}">
</pkp-side-nav>
{/if}
{/block}
<main class="app__main">
<div class="app__page width{if $pageWidth} width--{$pageWidth}{/if}">
Expand Down
6 changes: 6 additions & 0 deletions templates/user/profile.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
{extends file="layouts/backend.tpl"}

{block name="page"}
{if $userFutureRoleStartDate}
<Notification>
<h2 class="text-3xl-bold text-heading"> {translate key="user.futureRole.notification.message" roleStartDate=$userFutureRoleStartDate}</h2>
<p> {translate key="user.futureRole.notification.description"}</p>
</Notification>
{/if}
<h1 class="app__pageHeading">
{translate key="user.profile"}
</h1>
Expand Down

0 comments on commit c2f9b5e

Please sign in to comment.