Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#9658 user access table #10576

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions js/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import ListPanel from '@/components/ListPanel/ListPanel.vue';

// Manager components
import UserInvitationManager from '@/managers/UserInvitationManager/UserInvitationManager.vue';
import UserAccessManager from '@/managers/UserAccessManager/UserAccessManager.vue';

// Helper for initializing and tracking Vue controllers
import VueRegistry from './classes/VueRegistry.js';
Expand Down Expand Up @@ -228,6 +229,8 @@ VueRegistry.registerComponent('PkpListPanel', ListPanel);

// Register Invitation Manager
VueRegistry.registerComponent('UserInvitationManager', UserInvitationManager);
// Register User Access Manager
VueRegistry.registerComponent('UserAccessManager', UserAccessManager);

const pinia = createPinia();

Expand Down
8 changes: 8 additions & 0 deletions locale/en/userAccess.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
msgid "userAccess.tableHeader.startDate"
msgstr "Start Date"

msgid "userAccess.tableHeader.name"
msgstr "Name"

msgid "userAccess.search"
msgstr "Search User"
109 changes: 106 additions & 3 deletions pages/invitation/InvitationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
use APP\facades\Repo;
use APP\handler\Handler;
use APP\template\TemplateManager;
use PKP\context\Context;
use PKP\core\PKPApplication;
use PKP\facades\Locale;
use PKP\invitation\core\enums\InvitationAction;
use PKP\invitation\core\Invitation;
use PKP\invitation\stepTypes\SendInvitationStep;
use PKP\userGroup\relationships\UserUserGroup;

class InvitationHandler extends Handler
{
Expand Down Expand Up @@ -161,7 +163,7 @@ public function invite(array $args, Request $request): void
$invitationPayload['affiliation'] = $user ? $user->getAffiliation(null) : $payload['affiliation'];
$invitationPayload['country'] = $user ? $user->getCountry() : $payload['userCountry'];
$invitationPayload['userGroupsToAdd'] = $payload['userGroupsToAdd'];
$invitationPayload['currentUserGroups'] = !$invitationModel['userId'] ? [] : $this->getUserUserGroups($invitationModel['userId']);
$invitationPayload['currentUserGroups'] = !$invitationModel['userId'] ? [] : $this->getUserUserGroups($invitationModel['userId'],$request->getContext());
$invitationPayload['userGroupsToRemove'] = !$payload['userGroupsToRemove'] ? null : $payload['userGroupsToRemove'];
$invitationPayload['emailComposer'] = [
'emailBody' => $payload['emailBody'],
Expand Down Expand Up @@ -225,11 +227,112 @@ public function invite(array $args, Request $request): void
$templateMgr->display('/invitation/userInvitation.tpl');
}

/**
* Edit user using user access table action
* @param $args
* @param $request
* @return void
* @throws \Exception
*/
public function editUser($args, $request): void
{
$invitation = null;
$invitationPayload =[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if you can use the already existing UserRoleAssignmentInvitePayload object here, in order to avoid the many key strings.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked but some values are different. For example I need orcid but in UserRoleAssignmentInvitePayload has userOrcid also same with the country.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@defstat , if you are ok with @ipula s explanation, I think we can mark it as ready for merge.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@withanage, @ipula if we can't change those variable names in the front-end, we could go forward with merging it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@defstat Issue like we are using same user invitation components. I have to change the code that already QA and merged

if(!empty($args)) {
$invitationMode = 'edit';
$user = Repo::user()->get($args[0]);
$invitationPayload['userId'] = $args[0];
$invitationPayload['inviteeEmail'] = $user->getEmail();
$invitationPayload['orcid'] = $user->getData('orcid');
$invitationPayload['givenName'] = $user->getGivenName(null);
$invitationPayload['familyName'] = $user->getFamilyName(null);
$invitationPayload['affiliation'] = $user->getAffiliation(null);
$invitationPayload['country'] = $user->getCountry();
$invitationPayload['biography'] = $user->getBiography(null);
$invitationPayload['phone'] = $user->getPhone();
$invitationPayload['userGroupsToAdd'] = [];
$invitationPayload['currentUserGroups'] = $this->getUserUserGroups($args[0],$request->getContext());
$invitationPayload['userGroupsToRemove'] = [];
$invitationPayload['emailComposer'] = [
'emailBody' => '',
'emailSubject' => '',
];
$templateMgr = TemplateManager::getManager($request);
$breadcrumbs = $templateMgr->getTemplateVars('breadcrumbs');
$this->setupTemplate($request);
$context = $request->getContext();
$breadcrumbs[] = [
'id' => 'contexts',
'name' => __('navigation.access'),
'url' => $request
->getDispatcher()
->url(
$request,
PKPApplication::ROUTE_PAGE,
$request->getContext()->getPath(),
'management',
'settings',
)
];
$breadcrumbs[] = [
'id' => 'invitationWizard',
'name' => __('invitation.wizard.pageTitle'),
];
$steps = new SendInvitationStep();
$templateMgr->setState([
'steps' => $steps->getSteps($invitation, $context,$user),
'emailTemplatesApiUrl' => $request
->getDispatcher()
->url(
$request,
Application::ROUTE_API,
$context->getData('urlPath'),
'emailTemplates'
),
'primaryLocale' => $context->getData('primaryLocale'),
'invitationType' => 'userRoleAssignment',
'invitationPayload' => $invitationPayload,
'invitationMode' => $invitationMode,
'pageTitle' =>
$invitationPayload['givenName'][Locale::getLocale()] . ' '
. $invitationPayload['familyName'][Locale::getLocale()],
'pageTitleDescription' =>
__(
'invitation.wizard.viewPageTitleDescription',
['name' => $invitationPayload['givenName'][Locale::getLocale()]]
),
]);
$templateMgr->assign([
'pageComponent' => 'Page',
'breadcrumbs' => $breadcrumbs,
'pageWidth' => TemplateManager::PAGE_WIDTH_FULL,
]);
$templateMgr->display('/invitation/userInvitation.tpl');
} else {
$request->getDispatcher()->handle404();
}
}

/**
* Get current user user groups
* @param Context $context
* @param int $id
*/
private function getUserUserGroups(int $id): array
private function getUserUserGroups(int $id , Context $context): array
{
return Repo::userGroup()->userUserGroups($id)->toArray();
$userGroups = [];
$userUserGroups = UserUserGroup::query()
->withUserId($id)
->withContextId($context->getId())
->get()
->toArray();
foreach ($userUserGroups as $key => $userUserGroup) {
$userGroups[$key] = $userUserGroup;
$userGroups[$key]['masthead'] = $userUserGroup['masthead'] === 1;
$userGroups[$key]['name'] = Repo::userGroup()
->get($userUserGroup['userGroupId'])
->toArray()['name'][Locale::getLocale()];
}
return $userGroups;
}
}
1 change: 1 addition & 0 deletions pages/invitation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
case 'decline':
case 'accept':
case 'invite':
case 'editUser':
return new PKP\pages\invitation\InvitationHandler();
}
3 changes: 1 addition & 2 deletions templates/management/accessUsers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
{* Help Link *}
{help file="users-and-roles" class="pkp_help_tab"}

{capture assign=usersUrl}{url router=PKP\core\PKPApplication::ROUTE_COMPONENT component="grid.settings.user.UserGridHandler" op="fetchGrid" oldUserId=$oldUserId escape=false}{/capture}
{load_url_in_div id="userGridContainer" url=$usersUrl}
<user-access-manager></user-access-manager>