summaryrefslogtreecommitdiff
path: root/app/models/milestone.rb
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-05-18 23:40:33 -0500
committerRémy Coutable <remy@rymai.me>2016-05-18 23:40:33 -0500
commitf29d8b64e4bbea0dce64b4dfbae14422d64899c9 (patch)
treeeb2e0ebc962bfcc8bb04c21af274bd537e649959 /app/models/milestone.rb
parent715959e58190eca661ea377b949af3515d8da913 (diff)
parent4607323e130fe5b04e830f7a6de8083b070808f1 (diff)
downloadgitlab-ce-f29d8b64e4bbea0dce64b4dfbae14422d64899c9.tar.gz
Merge remote-tracking branch 'origin/master' into eReGeBe/gitlab-ce-feature/milestone-md
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'app/models/milestone.rb')
-rw-r--r--app/models/milestone.rb33
1 files changed, 16 insertions, 17 deletions
diff --git a/app/models/milestone.rb b/app/models/milestone.rb
index 92c07fd20da..31a54f44453 100644
--- a/app/models/milestone.rb
+++ b/app/models/milestone.rb
@@ -1,18 +1,3 @@
-# == Schema Information
-#
-# Table name: milestones
-#
-# id :integer not null, primary key
-# title :string(255) not null
-# project_id :integer not null
-# description :text
-# due_date :date
-# created_at :datetime
-# updated_at :datetime
-# state :string(255)
-# iid :integer
-#
-
class Milestone < ActiveRecord::Base
# Represents a "No Milestone" state used for filtering Issues and Merge
# Requests that have no milestone assigned.
@@ -101,8 +86,18 @@ class Milestone < ActiveRecord::Base
@link_reference_pattern ||= super("milestones", /(?<milestone>\d+)/)
end
- def self.upcoming
- self.where('due_date > ?', Time.now).reorder(due_date: :asc).first
+ def self.upcoming_ids_by_projects(projects)
+ rel = unscoped.of_projects(projects).active.where('due_date > ?', Time.now)
+
+ if Gitlab::Database.postgresql?
+ rel.order(:project_id, :due_date).select('DISTINCT ON (project_id) id')
+ else
+ rel.
+ group(:project_id).
+ having('due_date = MIN(due_date)').
+ pluck(:id, :project_id, :due_date).
+ map(&:first)
+ end
end
##
@@ -161,6 +156,10 @@ class Milestone < ActiveRecord::Base
nil
end
+ def title=(value)
+ write_attribute(:title, Sanitize.clean(value.to_s)) if value.present?
+ end
+
# Sorts the issues for the given IDs.
#
# This method runs a single SQL query using a CASE statement to update the