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

currentUserAssignedRoles not accurate in submission API #10411

Closed
jardakotesovec opened this issue Sep 13, 2024 · 4 comments
Closed

currentUserAssignedRoles not accurate in submission API #10411

jardakotesovec opened this issue Sep 13, 2024 · 4 comments
Assignees
Labels
Bug:2:Moderate A bug that is causing problems for a substantial minority of users.
Milestone

Comments

@jardakotesovec
Copy link
Contributor

jardakotesovec commented Sep 13, 2024

Describe the bug
In response from API .../api/v1/submissions/20,
there is field currentUserAssignedRoles, which is present in every stage (other fields deducted) as follows:

"stages": [
{
  "id": 1,
  "label": "Submission",
  "isActiveStage": true,
  "currentUserAssignedRoles": [
     4097
   ],
}
},
{
  "id": 3,
  "label": "Review",
  "isActiveStage": false,
  "currentUserAssignedRoles": [
    4097
  ],
},
{
  "id": 4,
  "label": "Copyediting",
  "isActiveStage": false,
  "currentUserAssignedRoles": [
    4097
  ],
},
{
  "id": 5,
  "label": "Production",
  "isActiveStage": false,
  "currentUserAssignedRoles": [
    4097
  ],
}

In this case it telling me that for this submission I do have ROLE_ID_ASSISTANT permission on every stage. But thats not accurate as in User&Roles -> Roles settings I selected only to be assigned to Submission&Copyediting stage.

Screenshot 2024-09-13 at 10 02 23

The behaviour is same in 3.4, but I don't think its impactful - as 3.4 listing cares about assignment to any stage - https://github.com/pkp/ui-library/blob/main/src/components/ListPanel/submissions/SubmissionsListItem.vue#L574, not individual ones.

But for 3.5 I would like to use this information to decide which stages user has access to, similarly like we do in 3.4

Screenshot 2024-09-13 at 10 08 07

What application are you using?
OJS, OMP or OPS version 3.4, 3.5

@jardakotesovec jardakotesovec added the Bug:2:Moderate A bug that is causing problems for a substantial minority of users. label Sep 13, 2024
@jardakotesovec jardakotesovec added this to the 3.5.0 LTS milestone Sep 13, 2024
@jardakotesovec
Copy link
Contributor Author

jardakotesovec commented Sep 18, 2024

Reason is that in https://github.com/pkp/pkp-lib/blame/main/classes/submission/maps/Schema.php#L390
There is very similar code twice:

So first it finds stage assignments without stageId, and second time with stageId and its using both results. Therefore result of this is not stage specific, which I would suspect is by mistake, because currentUserAssignedRoles is created per stage.

I think just deleting the first part would solve this.

Additionally I would use it as excuse to sneak in the recommendOnly and canChangeMetadata booleans, since the stage assignments are already loaded there. Instead of just returning boolean.

            $currentUserAssignedRoles = [];
            if ($currentUser) {
                // Replaces StageAssignmentDAO::getBySubmissionAndUserIdAndStageId
                $stageAssignments = StageAssignment::withSubmissionIds([$submission->getId()])
                    ->withUserId($currentUser->getId() ?? 0)
                    ->get();

                foreach ($stageAssignments as $stageAssignment) {
                    $userGroup = $this->getUserGroup($stageAssignment->userGroupId);
                    if ($userGroup) {
                        $currentUserAssignedRoles[] = $userGroup->getRoleId();
                    }
                }

                // Replaces StageAssignmentDAO::getBySubmissionAndUserIdAndStageId
                $stageAssignments = StageAssignment::withSubmissionIds([$submission->getId()])
                    ->withUserId($currentUser->getId())
                    ->withStageIds([$stageId])
                    ->get();


                foreach ($stageAssignments as $stageAssignment) {
                    $userGroup = Repo::userGroup()->get($stageAssignment->userGroupId);
                    $currentUserAssignedRoles[] = (int) $userGroup->getRoleId();
                }
            }
            $stage['currentUserAssignedRoles'] = array_values(array_unique($currentUserAssignedRoles));

@Vitaliy-1
Copy link
Collaborator

@jardakotesovec, this sounds reasonable!

@jardakotesovec
Copy link
Contributor Author

@Vitaliy-1 Before jumping on PR.

I think it make sense to solve this along with the #10360 , can you provide your thought on the suggestions there?

@jardakotesovec
Copy link
Contributor Author

Closing this one in favour of #10480

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug:2:Moderate A bug that is causing problems for a substantial minority of users.
Projects
None yet
Development

No branches or pull requests

4 participants