diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-17 16:34:22 -0200 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-19 14:58:27 -0200 |
commit | 530aae9080942646b130510e970d9d82c009d8e5 (patch) | |
tree | 149a06878ac9f335ead5db39af4328413bdc8ab1 /app/models/label.rb | |
parent | 074c964913218e99c42f0d8b5855c4ad2ad93267 (diff) | |
download | gitlab-ce-530aae9080942646b130510e970d9d82c009d8e5.tar.gz |
Abstract LabelPriority away into methods on Label model
Diffstat (limited to 'app/models/label.rb')
-rw-r--r-- | app/models/label.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/app/models/label.rb b/app/models/label.rb index 6fd45d251a8..ae07e8f60e1 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -97,6 +97,20 @@ class Label < ActiveRecord::Base merge_requests_count(user, project_id: project.try(:id) || project_id, state: 'opened') end + def prioritize!(project, value) + label_priority = priorities.find_or_initialize_by(project_id: project.id) + label_priority.priority = value + label_priority.save! + end + + def unprioritize!(project) + priorities.where(project: project).delete_all + end + + def priority(project) + priorities.find_by(project: project).try(:priority) + end + def template? template end @@ -135,7 +149,7 @@ class Label < ActiveRecord::Base def as_json(options = {}) super(options).tap do |json| - json[:priority] = priorities.find_by(project: options[:project]).try(:priority) if options.has_key?(:project) + json[:priority] = priority(options[:project]) if options.has_key?(:project) end end |