2021-07-30 19:51:33 +03:00
# frozen_string_literal: true
class AdditionalsJournalsController < ApplicationController
before_action :find_journal , only : % i [ edit update diff ]
2022-06-16 10:45:35 +03:00
before_action :find_entry , only : % i [ create ]
before_action :authorize , only : % i [ create edit update ]
2021-07-30 19:51:33 +03:00
helper :custom_fields
helper :journals
helper :additionals_journals
def edit
return render_403 unless @journal . editable_by? User . current
respond_to do | format |
# TODO: implement non-JS journal update
format . js
end
end
2022-10-22 14:12:09 +03:00
def create ; end
2021-07-30 19:51:33 +03:00
def update
return render_403 unless @journal . editable_by? User . current
2023-01-23 17:28:30 +03:00
journal_attributes = params [ :journal ]
journal_attributes [ :updated_by ] = User . current
@journal . safe_attributes = journal_attributes
2021-07-30 19:51:33 +03:00
@journal . save
@journal . destroy if @journal . details . empty? && @journal . notes . blank?
respond_to do | format |
format . html { redirect_after_update }
format . js
end
end
2022-10-22 14:12:09 +03:00
def diff
@entry = @journal . journalized
@detail =
if params [ :detail_id ] . present?
@journal . details . find_by id : params [ :detail_id ]
else
@journal . details . detect { | d | d . property == 'attr' && d . prop_key == 'description' }
end
unless @entry && @detail
render_404
return false
end
raise :: Unauthorized if @detail . property == 'cf' && ! @detail . custom_field & . visible_by? ( @entry . project , User . current )
@diff = Redmine :: Helpers :: Diff . new @detail . value , @detail . old_value
end
2021-07-30 19:51:33 +03:00
private
def redirect_after_update
2022-10-24 18:41:22 +03:00
redirect_to @journal . journalized
2021-07-30 19:51:33 +03:00
end
def find_journal
raise 'overwrite it'
end
end