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 f1479b56b71bef63517b90fcde99e6508e9c54af Mon Sep 17 00:00:00 2001 From: Jeroen van Baarsen Date: Mon, 9 May 2016 18:00:28 +0200 Subject: Remove the annotate gem and delete old annotations In 8278b763d96ef10c6494409b18b7eb541463af29 the default behaviour of annotation has changes, which was causing a lot of noise in diffs. We decided in #17382 that it is better to get rid of the whole annotate gem, and instead let people look at schema.rb for the columns in a table. Fixes: #17382 --- app/models/note.rb | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index deee2b9e885..f26aa1bf63f 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -1,24 +1,3 @@ -# == Schema Information -# -# Table name: notes -# -# id :integer not null, primary key -# note :text -# noteable_type :string -# author_id :integer -# created_at :datetime -# updated_at :datetime -# project_id :integer -# attachment :string -# line_code :string -# commit_id :string -# noteable_id :integer -# system :boolean default(FALSE), not null -# st_diff :text -# updated_by_id :integer -# is_award :boolean default(FALSE), not null -# - require 'carrierwave/orm/activerecord' class Note < ActiveRecord::Base -- 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 99d3e21f19ffb5cccb58fdfeac4fb6174e7e65e2 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 10 May 2016 17:41:46 -0500 Subject: Extract LegacyDiffNote out of Note --- app/models/note.rb | 214 ++++++++--------------------------------------------- 1 file changed, 30 insertions(+), 184 deletions(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index f26aa1bf63f..3bc55870704 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -1,6 +1,5 @@ -require 'carrierwave/orm/activerecord' - class Note < ActiveRecord::Base + extend ActiveModel::Naming include Gitlab::CurrentSettings include Participable include Mentionable @@ -22,12 +21,10 @@ class Note < ActiveRecord::Base 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 } @@ -41,8 +38,6 @@ class Note < ActiveRecord::Base 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) } scope :system, ->{ where(system: true) } scope :user, ->{ where(system: false) } scope :common, ->{ where(noteable_type: ["", nil]) } @@ -50,38 +45,31 @@ class Note < ActiveRecord::Base scope :inc_author_project, ->{ includes(:project, :author) } scope :inc_author, ->{ includes(:author) } + scope :legacy_diff_notes, ->{ where(type: 'LegacyDiffNote') } + scope :non_diff_notes, ->{ where(type: ['Note', nil]) } + scope :with_associations, -> do includes(:author, :noteable, :updated_by, project: [:project_members, { group: [:group_members] }]) end - serialize :st_diff - before_create :set_diff, if: ->(n) { n.line_code.present? } + before_validation :clear_blank_line_code! class << self - def discussions_from_notes(notes) - discussion_ids = [] - discussions = [] - - notes.each do |note| - next if discussion_ids.include?(note.discussion_id) - - # don't group notes for the main target - if !note.for_diff_line? && note.for_merge_request? - discussions << [note] - else - discussions << notes.select do |other_note| - note.discussion_id == other_note.discussion_id - end - discussion_ids << note.discussion_id - end - end + def model_name + ActiveModel::Name.new(self, nil, 'note') + end + + def build_discussion_id(noteable_type, noteable_id) + [:discussion, noteable_type.try(:underscore), noteable_id].join("-") + end - discussions + def discussions + all.group_by(&:discussion_id).values end - def build_discussion_id(type, id, line_code) - [:discussion, type.try(:underscore), id, line_code].join("-").to_sym + def grouped_diff_notes + legacy_diff_notes.select(&:active?).sort_by(&:created_at).group_by(&:line_code) end # Searches for notes matching the given query. @@ -116,167 +104,35 @@ class Note < ActiveRecord::Base system && SystemNoteService.cross_reference?(note) end - def max_attachment_size - current_application_settings.max_attachment_size.megabytes.to_i - end - - def find_diff - return nil unless noteable - return @diff if defined?(@diff) - - # Don't use ||= because nil is a valid value for @diff - @diff = noteable.diffs(Commit.max_diff_options).find do |d| - Digest::SHA1.hexdigest(d.new_path) == diff_file_index if d.new_path - end - end - - def hook_attrs - attributes - end - - def set_diff - # First lets find notes with same diff - # before iterating over all mr diffs - diff = diff_for_line_code unless for_merge_request? - diff ||= find_diff - - self.st_diff = diff.to_hash if diff - end - - def diff - @diff ||= Gitlab::Git::Diff.new(st_diff) if st_diff.respond_to?(:map) - end - - def diff_for_line_code - Note.where(noteable_id: noteable_id, noteable_type: noteable_type, line_code: line_code).last.try(:diff) - end - - # Check if this note is part of an "active" discussion - # - # This will always return true for anything except MergeRequest noteables, - # which have special logic. - # - # If the note's current diff cannot be matched in the MergeRequest's current - # diff, it's considered inactive. - def active? - return true unless self.diff - return false unless noteable - return @active if defined?(@active) - - noteable_diff = find_noteable_diff - - if noteable_diff - parsed_lines = Gitlab::Diff::Parser.new.parse(noteable_diff.diff.each_line) - - @active = parsed_lines.any? { |line_obj| line_obj.text == diff_line } - else - @active = false - end - - @active + def diff_note? + false end - def diff_file_index - line_code.split('_')[0] if line_code - end - - def diff_file_name - diff.new_path if diff - end - - def file_path - if diff.new_path.present? - diff.new_path - elsif diff.old_path.present? - diff.old_path - end + def legacy_diff_note? + false end - def diff_old_line - line_code.split('_')[1].to_i if line_code - end - - def diff_new_line - line_code.split('_')[2].to_i if line_code - end - - def generate_line_code(line) - Gitlab::Diff::LineCode.generate(file_path, line.new_pos, line.old_pos) - end - - def diff_line - return @diff_line if @diff_line - - if diff - diff_lines.each do |line| - if generate_line_code(line) == self.line_code - @diff_line = line.text - end - end - end - - @diff_line - end - - def diff_line_type - return @diff_line_type if @diff_line_type - - if diff - diff_lines.each do |line| - if generate_line_code(line) == self.line_code - @diff_line_type = line.type - end - end - end - - @diff_line_type - end - - def truncated_diff_lines - max_number_of_lines = 16 - prev_match_line = nil - prev_lines = [] - - highlighted_diff_lines.each do |line| - if line.type == "match" - prev_lines.clear - prev_match_line = line + def discussion_id + @discussion_id ||= + if for_merge_request? + [:discussion, :note, id].join("-") else - prev_lines << line - - break if generate_line_code(line) == self.line_code - - prev_lines.shift if prev_lines.length >= max_number_of_lines + self.class.build_discussion_id(noteable_type, noteable_id || commit_id) end - end - - prev_lines - end - - def diff_lines - @diff_lines ||= Gitlab::Diff::Parser.new.parse(diff.diff.each_line) end - def highlighted_diff_lines - Gitlab::Diff::Highlight.new(diff_lines).highlight + def max_attachment_size + current_application_settings.max_attachment_size.megabytes.to_i end - def discussion_id - @discussion_id ||= Note.build_discussion_id(noteable_type, noteable_id || commit_id, line_code) + def hook_attrs + attributes end def for_commit? noteable_type == "Commit" end - def for_commit_diff_line? - for_commit? && for_diff_line? - end - - def for_diff_line? - line_code.present? - end - def for_issue? noteable_type == "Issue" end @@ -285,10 +141,6 @@ class Note < ActiveRecord::Base noteable_type == "MergeRequest" end - def for_merge_request_diff_line? - for_merge_request? && for_diff_line? - end - def for_snippet? noteable_type == "Snippet" end @@ -361,14 +213,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 awards_supported? - (for_issue? || for_merge_request?) && !for_diff_line? + (for_issue? || for_merge_request?) && !diff_note? end def contains_emoji_only? -- cgit v1.2.1 From 7848d54f5b0024f58d8ce2b0259347816be5bdbc Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 13 May 2016 14:53:31 -0500 Subject: Clean up LegacyDiffNote somewhat --- app/models/note.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index 3bc55870704..7e5bdc09a84 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -112,6 +112,10 @@ class Note < ActiveRecord::Base false end + def active? + true + end + def discussion_id @discussion_id ||= if for_merge_request? -- cgit v1.2.1 From 6286b28bbc9b62af729c45c45f953f5426f5bf52 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sun, 8 May 2016 14:05:45 -0400 Subject: Add an Event's target's title to its reference link Given an activity feed entry like: > Douwe Maan commented on [issue #123] at [gitlab-org/gitlab-ce] ...the `issue #123` link will now have a `title` attribute. --- app/models/note.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index 7e5bdc09a84..55b98557244 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -19,6 +19,7 @@ class Note < ActiveRecord::Base delegate :gfm_reference, :local_reference, to: :noteable delegate :name, to: :project, prefix: true delegate :name, :email, to: :author, prefix: true + delegate :title, to: :noteable, allow_nil: true before_validation :set_award! -- 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 c31a296c94c48d865ce3171ccea9c48aa691466c Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 25 Apr 2016 14:28:23 +0200 Subject: Make note invalid if noteable project is different Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/15577 --- app/models/note.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index 55b98557244..8743b5eb472 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -33,6 +33,12 @@ class Note < ActiveRecord::Base validates :commit_id, presence: true, if: ->(n) { n.noteable_type == 'Commit' } validates :author, presence: true + validate do |note| + unless note.noteable.project == project + errors.add(:invalid_project, 'Note and noteable project mismatch') + end + end + mount_uploader :attachment, AttachmentUploader # Scopes -- cgit v1.2.1 From 87c44b0e91959439014fb8c923f3febc039d1cd0 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 26 Apr 2016 09:35:03 +0200 Subject: Improve note validation for project mismatch --- app/models/note.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index 8743b5eb472..02a98a37117 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -29,13 +29,15 @@ class Note < ActiveRecord::Base # Attachments are deprecated and are handled by Markdown uploader validates :attachment, file_size: { maximum: :max_attachment_size } - validates :noteable_id, presence: true, if: ->(n) { n.noteable_type.present? && n.noteable_type != 'Commit' } - validates :commit_id, presence: true, if: ->(n) { n.noteable_type == 'Commit' } + validates :noteable_id, presence: true, unless: :for_commit? + validates :commit_id, presence: true, if: :for_commit? validates :author, presence: true - validate do |note| - unless note.noteable.project == project - errors.add(:invalid_project, 'Note and noteable project mismatch') + with_options unless: :for_commit? do + validate do |note| + unless note.noteable.try(:project) == project + errors.add(:invalid_project, 'Note and noteable project mismatch') + end end end -- cgit v1.2.1 From 57b551a19f18d8da78175b4de6098d5517cde49f Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 26 Apr 2016 11:36:50 +0200 Subject: Remove redundant `with_options` from note validators --- app/models/note.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index 02a98a37117..f10446ca45f 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -33,11 +33,9 @@ class Note < ActiveRecord::Base validates :commit_id, presence: true, if: :for_commit? validates :author, presence: true - with_options unless: :for_commit? do - validate do |note| - unless note.noteable.try(:project) == project - errors.add(:invalid_project, 'Note and noteable project mismatch') - end + validate unless: :for_commit? do |note| + unless note.noteable.try(:project) == project + errors.add(:invalid_project, 'Note and noteable project mismatch') end end -- cgit v1.2.1 From 21d0cddd456c03e776a8b30e4695ede94c400792 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 26 Apr 2016 13:50:48 +0200 Subject: Do not override foreign attributes in note factory --- 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 f10446ca45f..e3e522a8d0f 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -34,7 +34,7 @@ class Note < ActiveRecord::Base validates :author, presence: true validate unless: :for_commit? do |note| - unless note.noteable.try(:project) == project + unless note.noteable.try(:project) == note.project errors.add(:invalid_project, 'Note and noteable project mismatch') end end -- cgit v1.2.1 From 99ef3a84b558e7b51bce7cbb11a6e235a6cc310b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 29 Apr 2016 12:16:18 +0200 Subject: Validate presence of noteable_type in note model --- app/models/note.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index e3e522a8d0f..5f669c02e8b 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -29,6 +29,7 @@ class Note < ActiveRecord::Base # Attachments are deprecated and are handled by Markdown uploader validates :attachment, file_size: { maximum: :max_attachment_size } + validates :noteable_type, presence: true validates :noteable_id, presence: true, unless: :for_commit? validates :commit_id, presence: true, if: :for_commit? validates :author, presence: true -- cgit v1.2.1 From 9154586ce5c46dfac83a1ed1e4beac1940913f16 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Thu, 26 May 2016 14:12:43 +0300 Subject: Confidential notes data leak --- app/models/note.rb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index 55b98557244..29f38539116 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -77,14 +77,30 @@ class Note < ActiveRecord::Base # # This method uses ILIKE on PostgreSQL and LIKE on MySQL. # - # query - The search query as a String. + # query - The search query as a String. + # as_user - Limit results to those viewable by a specific user # # Returns an ActiveRecord::Relation. - def search(query) + def search(query, as_user: nil) table = arel_table pattern = "%#{query}%" - where(table[:note].matches(pattern)) + found_notes = joins('LEFT JOIN issues ON issues.id = noteable_id'). + where(table[:note].matches(pattern)) + + if as_user + found_notes.where(' + issues.confidential IS NULL + OR issues.confidential IS FALSE + OR (issues.confidential IS TRUE + AND (issues.author_id = :user_id + OR issues.assignee_id = :user_id + OR issues.project_id IN(:project_ids)))', + user_id: as_user.id, + project_ids: as_user.authorized_projects.select(:id)) + else + found_notes.where('issues.confidential IS NULL OR issues.confidential IS FALSE') + end end def grouped_awards -- 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 From 580d250166d97bd5c2b0526be737d02806e577c2 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 26 May 2016 13:38:28 +0200 Subject: Refactor Participable There are several changes to this module: 1. The use of an explicit stack in Participable#participants 2. Proc behaviour has been changed 3. Batch permissions checking == Explicit Stack Participable#participants no longer uses recursion to process "self" and all child objects, instead it uses an Array and processes objects in breadth-first order. This allows us to for example create a single Gitlab::ReferenceExtractor instance and pass this to any Procs. Re-using a ReferenceExtractor removes the need for running potentially many SQL queries every time a Proc is called on a new object. == Proc Behaviour Changed Previously a Proc in Participable was expected to return an Array of User instances. This has been changed and instead it's now expected that a Proc modifies the Gitlab::ReferenceExtractor passed to it. The return value of the Proc is ignored. == Permissions Checking The method Participable#participants uses Ability.users_that_can_read_project to check if the returned users have access to the project of "self" _without_ running multiple SQL queries for every user. --- 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 55b98557244..35e5258fe3f 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -6,7 +6,7 @@ class Note < ActiveRecord::Base default_value_for :system, false - attr_mentionable :note, cache: true, pipeline: :note + attr_mentionable :note, pipeline: :note participant :author belongs_to :project -- cgit v1.2.1 From 2f9c2149a38e8a4067cb50c1cd1bbb1e72c263b3 Mon Sep 17 00:00:00 2001 From: ZJ van de Weg Date: Wed, 25 May 2016 21:07:36 +0200 Subject: Backend awardables on comments --- app/models/note.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index 46c3f6e24af..585d8c4ad84 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -3,6 +3,7 @@ class Note < ActiveRecord::Base include Gitlab::CurrentSettings include Participable include Mentionable + include Awardable default_value_for :system, false -- cgit v1.2.1