Skip to content

Commit 45630b9

Browse files
fix pr
1 parent c441f4f commit 45630b9

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

app/controllers/application_controller/buttons.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,14 @@ def group_update
105105

106106
def button_visibility_box_edit
107107
typ_changed = params[:visibility_typ].present?
108-
@edit[:new][:visibility_typ] = VISIBILITY_TYPES[params[:visibility_typ]] if typ_changed
108+
if typ_changed
109+
@edit[:new][:visibility_typ] = VISIBILITY_TYPES[params[:visibility_typ]] if typ_changed
110+
visibility_typ = @edit[:new][:visibility_typ]
111+
else
112+
visibility_typ = @edit[:current][:visibility_typ]
113+
end
109114

110-
visibility_typ = @edit[:new][:visibility_typ]
111-
if %w[role].include?(visibility_typ)
115+
if visibility_typ.to_s == "role"
112116
plural = visibility_typ.pluralize
113117
key = plural.to_sym
114118
prefix = "#{plural}_"
@@ -178,20 +182,19 @@ def automate_button_field_changed
178182
end
179183
unless params[:target_class]
180184
@changed = session[:changed] = false
181-
182185
# This block checks if any of the fields have changed
183186
# Broken into different branches for specific fields
184187
# If no fields are changed it will not set @changed or session[:changed] to true
185188
@edit[:new].each_key do |key|
186189
if @edit[:new][key] != @edit[:current][key]
187-
if @edit[:new][key] == "" && @edit[:current][key].nil? # check empty string / nil case
190+
if @edit[:new][key].blank? && @edit[:current][key].blank? # check empty string / nil case
188191
next
189192
elsif @edit[:new][key] == @edit[:current][key].to_s # check string / integer case
190193
next
191194
elsif key == :roles # check role values
192195
if (@edit[:new][key] == ["_ALL_"] || @edit[:new][key] == []) && (@edit[:current][key].nil? || @edit[:current][key] == ["all"] || @edit[:current][key] == ["_ALL_"]) # if visibility is set to "To All"
193196
next
194-
elsif @edit[:new][key].sort == @edit[:current][key].sort # check if new roles array and current roles array are equal after sorting the ids
197+
elsif @edit[:new][key].collect(&:to_i).sort == @edit[:current][key].collect(&:to_i).sort # check if new roles array and current roles array are equal after sorting the ids
195198
next
196199
else # if new roles array and current roles array are not equal
197200
@changed = session[:changed] = true
@@ -214,8 +217,6 @@ def automate_button_field_changed
214217
elsif key == :visibility_typ # check visibility type
215218
if @edit[:new][key] == "all" && @edit[:current][key].nil? # if visibility is set to "To All"
216219
next
217-
elsif @edit[:new][key] == "role" && @edit[:new][:roles] == [] # if visibility type is set to "To Role" and no roles are selected
218-
next
219220
else # if new visibility type value and current visibility type value are not equal
220221
@changed = session[:changed] = true
221222
break

0 commit comments

Comments
 (0)