diff options
author | Felipe Artur <felipefac@gmail.com> | 2019-03-27 21:19:12 +0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2019-03-27 21:19:12 +0300 |
commit | 16a3fea3998e813b95d7d09ea31f6a88dc908102 (patch) | |
tree | f896b456433d21ab5d8b3dd24625348175ac06a6 /app/models/concerns/issuable.rb | |
parent | 294c5c41beaac1fbc60c67df2c8745f7583544a1 (diff) | |
parent | 97f8d4e96870324c4ce6534022397d33c4bf5dbc (diff) |
Merge master
Diffstat (limited to 'app/models/concerns/issuable.rb')
-rw-r--r-- | app/models/concerns/issuable.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 83bd8cc6478..51a8395c013 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -24,11 +24,12 @@ module Issuable include CreatedAtFilterable include UpdatedAtFilterable include IssuableStates + include ClosedAtFilterable # This object is used to gather issuable meta data for displaying # upvotes, downvotes, notes and closing merge requests count for issues and merge requests # lists avoiding n+1 queries and improving performance. - IssuableMeta = Struct.new(:upvotes, :downvotes, :notes_count, :merge_requests_count) + IssuableMeta = Struct.new(:upvotes, :downvotes, :user_notes_count, :merge_requests_count) included do cache_markdown_field :title, pipeline: :single_line @@ -36,8 +37,8 @@ module Issuable redact_field :description - belongs_to :author, class_name: "User" - belongs_to :updated_by, class_name: "User" + belongs_to :author, class_name: 'User' + belongs_to :updated_by, class_name: 'User' belongs_to :last_edited_by, class_name: 'User' belongs_to :milestone @@ -75,6 +76,7 @@ module Issuable validates :author, presence: true validates :title, presence: true, length: { maximum: 255 } + validate :milestone_is_valid scope :authored, ->(user) { where(author_id: user) } scope :recent, -> { reorder(id: :desc) } @@ -118,6 +120,16 @@ module Issuable def has_multiple_assignees? assignees.count > 1 end + + def milestone_available? + project_id == milestone&.project_id || project.ancestors_upto.compact.include?(milestone&.group) + end + + private + + def milestone_is_valid + errors.add(:milestone_id, message: "is invalid") if milestone_id.present? && !milestone_available? + end end class_methods do |