From 3bdc57f0a710b3769381ecad7ea4098223ecff56 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Sat, 16 Apr 2016 21:09:08 +0200 Subject: Create table for award emoji --- app/models/note.rb | 53 +++++++++++------------------------------------------ 1 file changed, 11 insertions(+), 42 deletions(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index 87ced65c650..b992b2e76f0 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -16,7 +16,6 @@ # system :boolean default(FALSE), not null # st_diff :text # updated_by_id :integer -# is_award :boolean default(FALSE), not null # require 'carrierwave/orm/activerecord' @@ -43,12 +42,9 @@ class Note < ActiveRecord::Base delegate :name, to: :project, prefix: true delegate :name, :email, to: :author, prefix: true - before_validation :set_award! before_validation :clear_blank_line_code! validates :note, :project, presence: true - validates :note, uniqueness: { scope: [:author, :noteable_type, :noteable_id] }, if: ->(n) { n.is_award } - validates :note, inclusion: { in: Emoji.emojis_names }, if: ->(n) { n.is_award } validates :line_code, line_code: true, allow_blank: true # Attachments are deprecated and are handled by Markdown uploader validates :attachment, file_size: { maximum: :max_attachment_size } @@ -60,8 +56,6 @@ class Note < ActiveRecord::Base mount_uploader :attachment, AttachmentUploader # Scopes - scope :awards, ->{ where(is_award: true) } - scope :nonawards, ->{ where(is_award: false) } scope :for_commit_id, ->(commit_id) { where(noteable_type: "Commit", commit_id: commit_id) } scope :inline, ->{ where("line_code IS NOT NULL") } scope :not_inline, ->{ where(line_code: nil) } @@ -119,19 +113,6 @@ class Note < ActiveRecord::Base where(table[:note].matches(pattern)) end - - def grouped_awards - notes = {} - - awards.select(:note).distinct.map do |note| - notes[note.note] = where(note: note.note) - end - - notes["thumbsup"] ||= Note.none - notes["thumbsdown"] ||= Note.none - - notes - end end def cross_reference? @@ -347,37 +328,25 @@ class Note < ActiveRecord::Base Event.reset_event_cache_for(self) end - def downvote? - is_award && note == "thumbsdown" - end - - def upvote? - is_award && note == "thumbsup" + def system? + read_attribute(:system) end def editable? - !system? && !is_award + !system? end def cross_reference_not_visible_for?(user) cross_reference? && referenced_mentionables(user).empty? end - # Checks if note is an award added as a comment - # - # If note is an award, this method sets is_award to true - # and changes content of the note to award name. - # - # Method is executed as a before_validation callback. - # - def set_award! - return unless awards_supported? && contains_emoji_only? - - self.is_award = true - self.note = award_emoji_name + def award_emoji? + award_emoji_supported? && contains_emoji_only? end - private + def create_award_emoji + self.noteable.award_emoji(award_emoji_name, author) + end def clear_blank_line_code! self.line_code = nil if self.line_code.blank? @@ -389,8 +358,8 @@ class Note < ActiveRecord::Base diffs.find { |d| d.new_path == self.diff.new_path } end - def awards_supported? - (for_issue? || for_merge_request?) && !for_diff_line? + def award_emoji_supported? + noteable.is_a?(Awardable) && !for_diff_line? end def contains_emoji_only? @@ -399,6 +368,6 @@ class Note < ActiveRecord::Base def award_emoji_name original_name = note.match(Banzai::Filter::EmojiFilter.emoji_pattern)[1] - AwardEmoji.normilize_emoji_name(original_name) + Gitlab::AwardEmoji.normilize_emoji_name(original_name) end end -- cgit v1.2.1 From 4558b5b9fe9f648903ad0dc01089e6118fe0af34 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Wed, 11 May 2016 22:43:58 +0200 Subject: Incorporate feedback --- app/models/note.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index 0b038edb47b..f9040f9f364 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -323,10 +323,6 @@ class Note < ActiveRecord::Base award_emoji_supported? && contains_emoji_only? end - def create_award_emoji - self.noteable.award_emoji(award_emoji_name, author) - end - def clear_blank_line_code! self.line_code = nil if self.line_code.blank? end -- cgit v1.2.1 From 7a4e7ad04e1fc96953d9159e8e1a2208990d34f7 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Thu, 12 May 2016 09:23:21 +0200 Subject: Fix tests and wrong choices during merge --- app/models/note.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index f9040f9f364..7235274770d 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -343,6 +343,6 @@ class Note < ActiveRecord::Base def award_emoji_name original_name = note.match(Banzai::Filter::EmojiFilter.emoji_pattern)[1] - Gitlab::AwardEmoji.normilize_emoji_name(original_name) + Gitlab::AwardEmoji.normalize_emoji_name(original_name) end end -- cgit v1.2.1 From 4d6c51e2282c6416a8766fdf580a19fd08670609 Mon Sep 17 00:00:00 2001 From: ZJ van de Weg Date: Thu, 19 May 2016 15:00:50 -0500 Subject: Fix backend merge mistakes [ci skip] --- app/models/note.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index e9bef4fb9fe..2b1a3f90697 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -193,7 +193,7 @@ class Note < ActiveRecord::Base end def award_emoji_supported? - noteable.is_a?(Awardable) && !for_diff_line? + noteable.is_a?(Awardable) && !line_code.present? end def contains_emoji_only? -- cgit v1.2.1 From 91a7b9333b660abc866e52e1a614151cb529413d Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Wed, 1 Jun 2016 11:23:09 +0200 Subject: Incorportate feedback --- app/models/note.rb | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index bbe5545dc80..f99d327a5b8 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -21,10 +21,8 @@ class Note < ActiveRecord::Base delegate :name, :email, to: :author, prefix: true delegate :title, to: :noteable, allow_nil: true - before_validation :clear_blank_line_code! - validates :note, :project, presence: true - validates :line_code, line_code: true, allow_blank: true + # Attachments are deprecated and are handled by Markdown uploader validates :attachment, file_size: { maximum: :max_attachment_size } @@ -173,10 +171,6 @@ class Note < ActiveRecord::Base Event.reset_event_cache_for(self) end - def system? - read_attribute(:system) - end - def editable? !system? end @@ -193,14 +187,8 @@ class Note < ActiveRecord::Base self.line_code = nil if self.line_code.blank? end - # Find the diff on noteable that matches our own - def find_noteable_diff - diffs = noteable.diffs(Commit.max_diff_options) - diffs.find { |d| d.new_path == self.diff.new_path } - end - def award_emoji_supported? - noteable.is_a?(Awardable) && !line_code.present? + noteable.is_a?(Awardable) end def contains_emoji_only? -- cgit v1.2.1