Skip to content
Merged
20 changes: 13 additions & 7 deletions app/controllers/close_reasons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ def edit; end

def update
before = @close_reason.attributes.map { |k, v| "#{k}: #{v}" }.join(' ')
@close_reason.update close_reason_params
after = @close_reason.attributes.map { |k, v| "#{k}: #{v}" }.join(' ')
AuditLog.moderator_audit(event_type: 'close_reason_update', related: @close_reason, user: current_user,
comment: "from <<CloseReason #{before}>>\nto <<CloseReason #{after}>>")
if @close_reason.update(close_reason_params)
after = @close_reason.attributes.map { |k, v| "#{k}: #{v}" }.join(' ')

if @close_reason.community.nil?
redirect_to close_reasons_path(global: 1)
AuditLog.moderator_audit(event_type: 'close_reason_update',
related: @close_reason,
user: current_user,
comment: "from <<CloseReason #{before}>>\nto <<CloseReason #{after}>>")

if @close_reason.community.nil?
redirect_to close_reasons_path(global: 1)
else
redirect_to close_reasons_path
end
else
redirect_to close_reasons_path
render :edit
end
end

Expand Down
4 changes: 3 additions & 1 deletion app/models/close_reason.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ class CloseReason < ApplicationRecord

scope :active, -> { where(active: true) }

validates :name, uniqueness: { scope: [:community_id], case_sensitive: false }
validates :name, length: { maximum: 255 },
presence: true,
uniqueness: { scope: [:community_id], case_sensitive: false }
end