Skip to content

Commit

Permalink
pkp/pkp-lib#10290 ensure user cannot log in as those who have roles i…
Browse files Browse the repository at this point in the history
…n contexts they do not manage.
  • Loading branch information
Hafsa-Naeem committed Jan 22, 2025
1 parent 63c6795 commit 6898e56
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/managers/ParticipantManager/ParticipantManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</div>
<div>
<DropdownActions
:actions="participantManagerStore.itemActions"
:actions="participantManagerStore.itemActions(participant)"
:label="`${participant.fullName} ${t('common.moreActions')}`"
:display-as-ellipsis="true"
@action="
Expand Down
10 changes: 7 additions & 3 deletions src/managers/ParticipantManager/participantManagerStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const useParticipantManagerStore = defineComponentStore(
const submissionId = ref(props.submission.id);

const relativeUrl = computed(() => {
return `submissions/${encodeURIComponent(submissionId.value)}/participants/${props.submissionStageId}`;
return `submissions/${encodeURIComponent(submissionId.value)}/participants/${props.submissionStageId}?includeCanLoginAs=1&includeGossip=1`;
});

const {apiUrl: participantApiUrl} = useUrl(relativeUrl);
Expand Down Expand Up @@ -50,7 +50,8 @@ export const useParticipantManagerStore = defineComponentStore(
roleId: stageAssignment.stageAssignmentUserGroup.roleId,
userGroupId: stageAssignment.stageAssignmentUserGroup.id,
recommendOnly: stageAssignment.recommendOnly,
displayInitials: participant.displayInitials,
canLoginAs: participant.canLoginAs,
canGossip: participant.canGossip,
});
});
});
Expand All @@ -74,7 +75,10 @@ export const useParticipantManagerStore = defineComponentStore(

const _actionFns = useParticipantManagerActions();

const itemActions = computed(() => _actionFns.getItemActions({}));
const itemActions = (participant) => {
return _actionFns.getItemActions(participant);
};


function enrichActionArg(args) {
return {
Expand Down
21 changes: 13 additions & 8 deletions src/managers/ParticipantManager/useParticipantManagerActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,16 @@ export function useParticipantManagerActions() {
});
}

function getItemActions() {
// take participant as a parameter
function getItemActions(participant) {
const {t} = useLocalize();

const actions = [];
console.log('Participant ID:', participant.id, 'canLoginAs:', participant.canLoginAs, 'Type:', typeof participant.canLoginAs);


// [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_SUB_EDITOR],
const {hasCurrentUserAtLeastOneRole} = useCurrentUser();

const canAdminister = hasCurrentUserAtLeastOneRole([
pkp.const.ROLE_ID_MANAGER,
pkp.const.ROLE_ID_SITE_ADMIN,
Expand All @@ -197,12 +199,15 @@ export function useParticipantManagerActions() {
icon: 'Email',
});

// TODO https://github.com/pkp/pkp-lib/issues/10290
actions.push({
label: t('grid.action.logInAs'),
name: Actions.PARTICIPANT_LOGIN_AS,
icon: 'LoginAs',
});
// show "Login As" if participant.canLoginAs is true
if (
participant.canLoginAs === true) {
actions.push({
label: t('grid.action.logInAs'),
name: Actions.PARTICIPANT_LOGIN_AS,
icon: 'LoginAs',
});
}

if (canAdminister) {
actions.push({
Expand Down
12 changes: 7 additions & 5 deletions src/managers/ReviewerManager/useReviewerManagerActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,13 @@ export function useReviewerManagerActions() {
});

// Login as TODO condition
actions.push({
label: t('grid.action.logInAs'),
name: Actions.REVIEWER_LOGIN_AS,
icon: 'LoginAs',
});
if (reviewAssignment.canLoginAs) {
actions.push({
label: t('grid.action.logInAs'),
name: Actions.REVIEWER_LOGIN_AS,
icon: 'LoginAs',
});
}

// Gossip TODO condition
actions.push({
Expand Down

0 comments on commit 6898e56

Please sign in to comment.