debian-mirror-gitlab/app/models/timelog.rb

42 lines
1,006 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2019-07-07 11:18:12 +05:30
class Timelog < ApplicationRecord
2017-08-17 22:00:37 +05:30
validates :time_spent, :user, presence: true
validate :issuable_id_is_present
2018-11-08 19:23:39 +05:30
belongs_to :issue, touch: true
belongs_to :merge_request, touch: true
2017-08-17 22:00:37 +05:30
belongs_to :user
2020-01-01 13:55:28 +05:30
scope :for_issues_in_group, -> (group) do
joins(:issue).where(
'EXISTS (?)',
Project.select(1).where(namespace: group.self_and_descendants)
.where('issues.project_id = projects.id')
)
end
scope :between_dates, -> (start_date, end_date) do
where('spent_at BETWEEN ? AND ?', start_date, end_date)
end
2017-08-17 22:00:37 +05:30
def issuable
issue || merge_request
end
private
def issuable_id_is_present
if issue_id && merge_request_id
2020-04-08 14:13:33 +05:30
errors.add(:base, _('Only Issue ID or Merge Request ID is required'))
2017-08-17 22:00:37 +05:30
elsif issuable.nil?
2020-04-08 14:13:33 +05:30
errors.add(:base, _('Issue or Merge Request ID is required'))
2017-08-17 22:00:37 +05:30
end
end
2018-11-08 19:23:39 +05:30
# Rails5 defaults to :touch_later, overwrite for normal touch
def belongs_to_touch_method
:touch
end
2017-08-17 22:00:37 +05:30
end