Block supporting org editors from locking themselves out [WHIT - 3458]#11455
Block supporting org editors from locking themselves out [WHIT - 3458]#11455GDSNewt wants to merge 2 commits into
Conversation
| 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) |
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
There was a problem hiding this comment.
Can we also add a corresponding test?
|
|
||
| def update | ||
| @edition.assign_attributes(edition_params) | ||
| saved = ApplicationRecord.transaction do |
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.
8ecb5cc to
2c4d005
Compare
- Write a unit test that exercises the behaviour we're seeing in the bug - Figure out if there is an impact to always sending lead/supporting org arrays even on editions that don't support them - Consider if an integration test is needed for this scenario (perhaps covered by the wider A&P test audit). NB: I tried adding this to editions_controller_test, but there is no `update` route on Edition - only on concrete STI descendents of Edition. I tried adding the test to generic_editions_controller_test but the 'generic' edition doesn't support organisation associations. So all things considered, I've put this test in the Standard Editions Controller tests, even though the impact of the change is more far-reaching than StandardEdition alone.
2c4d005 to
2dee8cd
Compare
|
UPDATE: This PR was superseded by #11476. But through pairing with Alex, we've found separate bugs that affect post-document-creation access limiting: First:
Second:
Same root cause: dirty data on the 'update' path. We're trying to assess whether a user will be locked out based on edition attributes some of which are from the DB and some of which are overwritten in memory by form inputs. We're having a wider think about what to do with this. |

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