Skip to content

Resolve "Unable to disable all restricted visibility levels"

What does this MR do?

Allows admin to disable all restricted visibility levels

Are there points in the code the reviewer needs to double check?

The problem was that when we disabled all radio buttons the param was not sent to the controller so the application settings did not know they had to update the resricted_visibility_levels attribute.

I tried using collection_radio_buttons but failed to do so because the second parameter expects a single value and restricted_visibility_levels is a collection (Array).

I also tried to replicate the same behaviour as the collection_radio_buttons by adding a hidden_field with an empty value when the radio_button was unchecked but it failed as well since using both '' and nil would result in the restricted_visibility_levels being updated to [0, 0, 0] and 0 is a valid visibility level which would result in always having that option checked.

I then ended up adding a default value to that parameter inside ApplicationSetting::UpdateService so that if the parameter is not specified it will be updated to []. Although I am not entirely confident in this solution and will gladly take opinions on this.

Why was this MR needed?

The form was not letting admins disable all visibility levels at once and was forcing one visibility level being forced at all times.

Does this MR meet the acceptance criteria?

What are the relevant issue numbers?

Closes #32408 (closed)

Edited by Douwe Maan

Merge request reports

Loading