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#10280 Additional data for submissions/{ID}/participants API #10383

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

taslangraham
Copy link
Contributor

For #10280

@taslangraham taslangraham force-pushed the i10280-main branch 6 times, most recently from bb5ffca to 01ef9fe Compare September 11, 2024 03:49
@taslangraham taslangraham marked this pull request as ready for review September 11, 2024 12:09
// Get User's stage assignments for submission.
// Note:
// - A User can potentially have multiple assignments for a submission.
// - A User can potentially have multiple assignments for a stage of a submission.
Copy link
Collaborator

Choose a reason for hiding this comment

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

@asmecher, I realized I've been a bit confused about this so I wanted to confirm before this is merged: could you confirm these two assumptions noted? I thought these were the case but I'm less sure after our recent discussion.

Copy link
Member

Choose a reason for hiding this comment

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

Let's say (using our default user groups) a user is assigned to a submission as both Section Editor and Layout Editor. Then they'll have a row in stage_assignments for each assignment. By default both the Section Editor and Layout Editor user groups are both active in the Production stage (per user_group_stage). So with the stage filter, this code should get the stage assignments for both Section Editor and Layout Editor. Does that clarify?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@asmecher, yes, thanks!

@@ -90,7 +90,7 @@ public function scopeWithStageIds(Builder $query, ?array $stageIds): Builder
public function scopeWithSubmissionIds(Builder $query, ?array $submissionIds): Builder
{
return $query->when($submissionIds !== null, function ($query) use ($submissionIds) {
return $query->whereIn('submission_id', $submissionIds);
return $query->whereIn('stage_assignments.submission_id', $submissionIds);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The additional stage_assignments table name shouldn't be necessary here. Were you running into any issues with it?

Copy link
Contributor Author

@taslangraham taslangraham Sep 13, 2024

Choose a reason for hiding this comment

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

When using the scopeWithSubmissionIds filter in combination with another filter, such as scopeWithContextId, which performs joins with tables containing a column named submission_id, you'll encounter an ambiguous column error because the column name submission_id exists in multiple tables in the query.

So for example the following query would throw the error below

$stageAssignments = StageAssignment::withSubmissionIds([$submission->getId()])
     ->withStageIds($stageId ? [$stageId] : [])
     ->withUserId($user->getId())
     ->withContextId($this->context->getId()) // joins submissions table which also has a submission_id column
     ->get();

Error

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'submission_id' in where clause is ambiguous (Connection: mysql, SQL: select * from `stage_assignments` inner join `submissions` on `stage_assignments`.`submission_id` = `submissions`.`submission_id` where `submission_id` in (9) and exists (select * from `user_group_stage` where `stage_assignments`.`user_group_id` = `user_group_stage`.`user_group_id` and `stage_id` in (5)) and `user_id` = 3 and `submissions`.`context_id` = 1)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good to know!

'name' => $userGroup->getName(null),
'abbrev' => $userGroup->getAbbrev(null),
'roleId' => (int) $userGroup->getRoleId(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this our PHP CS fixer rules removing the spaces or is it your IDE? If it's not our CS fixer rules doing so, I'd leave the space for now to keep things consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to have been the IDE. There were also a couple of other unintended formatting changes that I have corrected

@taslangraham taslangraham force-pushed the i10280-main branch 5 times, most recently from 0a5bcb4 to e0670ce Compare September 18, 2024 17:50
@taslangraham taslangraham merged commit 214b2cf into pkp:main Sep 19, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants