|
|
|
class Issue < ApplicationRecord
|
|
|
|
belongs_to :project
|
|
|
|
belongs_to :tracker
|
|
|
|
belongs_to :issue_tag, foreign_key: :priority_id
|
|
|
|
belongs_to :version, foreign_key: :fixed_version_id,optional: true
|
|
|
|
belongs_to :user,optional: true, foreign_key: :author_id
|
|
|
|
belongs_to :issue_status, foreign_key: :status_id,optional: true
|
|
|
|
has_many :commit_issues
|
|
|
|
has_many :attachments, as: :container, dependent: :destroy
|
|
|
|
has_many :memos
|
|
|
|
has_many :journals
|
|
|
|
has_many :journal_details, through: :journals
|
|
|
|
|
|
|
|
scope :issue_includes, ->{includes(:user)}
|
|
|
|
|
|
|
|
|
|
|
|
def get_assign_user
|
|
|
|
User.select(:login, :lastname,:firstname, :nickname)&.find_by_id(self.assigned_to_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_journal_detail(change_files, issue_files, issue_file_ids)
|
|
|
|
journal = Journal.where(journalized_id: self.id, journalized_type: "Issue", user_id: self.author_id, notes: [nil,""])
|
|
|
|
if journal.present?
|
|
|
|
journal.update_all(created_on: Time.now)
|
|
|
|
journal = journal.last
|
|
|
|
else
|
|
|
|
journal_params = {
|
|
|
|
journalized_id: self.id, journalized_type: "Issue", user_id: self.author_id
|
|
|
|
}
|
|
|
|
journal = Journal.new journal_params
|
|
|
|
journal.save
|
|
|
|
end
|
|
|
|
if change_files
|
|
|
|
journal.journal_details.create(property: "attachment", prop_key: "#{issue_files.size}", old_value: issue_file_ids, value: issue_files)
|
|
|
|
end
|
|
|
|
|
|
|
|
change_values = %w(subject description is_private assigned_to_id tracker_id status_id priority_id fixed_version_id start_date due_date estimated_hours done_ratio)
|
|
|
|
change_values.each do |at|
|
|
|
|
if self.send("saved_change_to_#{at}?")
|
|
|
|
journal.journal_details.create(property: "attr", prop_key: "#{at}", old_value: self.send("#{at}_before_last_save"), value: self.send(at))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|