-
Notifications
You must be signed in to change notification settings - Fork 447
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
Conversation
bb5ffca
to
01ef9fe
Compare
// 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know!
classes/user/maps/Schema.php
Outdated
'name' => $userGroup->getName(null), | ||
'abbrev' => $userGroup->getAbbrev(null), | ||
'roleId' => (int) $userGroup->getRoleId(), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
0a5bcb4
to
e0670ce
Compare
…missions/{id}/participants endpoint
e0670ce
to
dabfb02
Compare
For #10280