Block supporting org editors from locking themselves out [WHIT - 3458]#11455
Open
GDSNewt wants to merge 1 commit into
Open
Block supporting org editors from locking themselves out [WHIT - 3458]#11455GDSNewt wants to merge 1 commit into
GDSNewt wants to merge 1 commit into
Conversation
TonyGDS
reviewed
May 15, 2026
| end | ||
| if edition_params[:supporting_organisation_ids] | ||
| edition_params[:supporting_organisation_ids] = edition_params[:supporting_organisation_ids].reject(&:blank?) | ||
| elsif edition_params.key?(:lead_organisation_ids) |
Contributor
There was a problem hiding this comment.
It's not clear reading the code why we are doing this. We could create a separate method to describe it e.g.
if editions_form_cleared_supporting_orgs?
edition_params[:supporting_organisation_ids] = []
elsif edition_params[:supporting_organisation_ids]
edition_params[:supporting_organisation_ids] = edition_params[:supporting_organisation_ids].reject(&:blank?)
end
def editions_form_cleared_supporting_orgs?
edition_params.key?(:lead_organisation_ids) &&
!edition_params.key?(:supporting_organisation_ids)
end
Contributor
There was a problem hiding this comment.
Can we also add a corresponding test?
TonyGDS
reviewed
May 15, 2026
|
|
||
| def update | ||
| @edition.assign_attributes(edition_params) | ||
| saved = ApplicationRecord.transaction do |
Contributor
There was a problem hiding this comment.
DraftEditionUpdater has a method access_limit_excludes_current_user? could we not do something similar here with the input params rather than wrapping the action in a transaction? Reading the code it's unclear why we need to do it. If we call access_limit_excludes_current_user? before @edition.assign_attributes(edition_params) we wouldn't have to roll anything back.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a bug where users could unintentionally remove their own organisation’s access to a draft without receiving a warning, due to how empty multi-select fields are handled in HTML forms.
Problem
While working on support, I encountered the following scenario:
An Org B user creates a draft publication with:
The user later edits the draft and:
Due to HTML behavior:
<select multiple>fields submit nothing when emptysupporting_organisation_idsis missing from the payload entirelyRoot Cause
In the controller:
delete_absent_edition_organisationsdetects the missing keyedition_organisationsIn
DraftEditionUpdater:The save is allowed:
access_limited = trueResult
Fix
Handle missing multi-select params explicitly
supporting_organisation_idsas "clear all values", not "no change"Wrap update flow in a transaction
assign_attributesandsavecan_perform?returns false, all changes are rolled back, including side effects from attribute assignmentJIRA