diff options
author | micael.bergeron <micael.bergeron@solutionstlm.com> | 2017-08-02 10:06:28 -0400 |
---|---|---|
committer | micael.bergeron <micael.bergeron@solutionstlm.com> | 2017-09-06 09:00:57 -0400 |
commit | 45b83ed99afc5cfe24a8d84869894124d93d5b51 (patch) | |
tree | d632a83e4b953d627855440defbc3300b1285967 /app | |
parent | 966b1128d884a318dad4277e23368334fe67e836 (diff) | |
download | gitlab-ce-45b83ed99afc5cfe24a8d84869894124d93d5b51.tar.gz |
round of fixes after code review
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/concerns/renders_notes.rb | 7 | ||||
-rw-r--r-- | app/models/concerns/issuable.rb | 1 | ||||
-rw-r--r-- | app/models/note.rb | 14 | ||||
-rw-r--r-- | app/views/projects/notes/_actions.html.haml | 4 |
4 files changed, 19 insertions, 7 deletions
diff --git a/app/controllers/concerns/renders_notes.rb b/app/controllers/concerns/renders_notes.rb index cdcfefd90c9..b6cf366c05c 100644 --- a/app/controllers/concerns/renders_notes.rb +++ b/app/controllers/concerns/renders_notes.rb @@ -1,5 +1,5 @@ module RendersNotes - def prepare_notes_for_rendering(notes, noteable=nil) + def prepare_notes_for_rendering(notes, noteable = nil) preload_noteable_for_regular_notes(notes) preload_max_access_for_authors(notes, @project) preload_first_time_contribution_for_authors(noteable, notes) if noteable.is_a?(Issuable) @@ -23,7 +23,10 @@ module RendersNotes def preload_first_time_contribution_for_authors(issuable, notes) return unless issuable.first_contribution? + same_author = lambda {|n| n.author_id == issuable.author_id} - notes.select(&same_author).each {|note| note.special_role = :first_time_contributor} + notes.each do |note| + note.specialize!(Note::SpecialRole::FIRST_TIME_CONTRIBUTOR, &same_author) + end end end diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 7b1c4e7a2d5..0cc60dddc69 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -337,6 +337,7 @@ module Issuable def first_contribution? return false if project.team.max_member_access(author_id) > Gitlab::Access::GUEST + project.merge_requests.merged.where(author_id: author_id).empty? end end diff --git a/app/models/note.rb b/app/models/note.rb index d04bccc6e81..28cd54bd81c 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -26,7 +26,6 @@ class Note < ActiveRecord::Base end ignore_column :original_discussion_id - ignore_column :special_role cache_markdown_field :note, pipeline: :note, issuable_state_filter_enabled: true @@ -155,6 +154,10 @@ class Note < ActiveRecord::Base .group(:noteable_id) .where(noteable_type: type, noteable_id: ids) end + + def has_special_role?(role, note) + note.special_role == role + end end def cross_reference? @@ -221,14 +224,19 @@ class Note < ActiveRecord::Base end def special_role=(role) - raise "Role is undefined, #{role} not found in #{SpecialRole.values}" unless SpecialRole.values.include? role + raise "Role is undefined, #{role} not found in #{SpecialRole.values}" unless SpecialRole.values.include?(role) + @special_role = role end def has_special_role?(role) - return @special_role == role + self.class.has_special_role?(role, self) end + def specialize!(role) + self.special_role = role if !block_given? || yield(self) + end + def editable? !system? end diff --git a/app/views/projects/notes/_actions.html.haml b/app/views/projects/notes/_actions.html.haml index 926ceff3ee2..cf634faccfc 100644 --- a/app/views/projects/notes/_actions.html.haml +++ b/app/views/projects/notes/_actions.html.haml @@ -1,7 +1,7 @@ -- if note.has_special_role? :first_time_contributor +- if note.has_special_role?(Note::SpecialRole::FIRST_TIME_CONTRIBUTOR) %span.note-role.has-tooltip{ title: _("This user hasn't yet contributed code to this project. Handle with care.")} = _('First-time contributor') -- elsif access = access = note_max_access_for_user(note) +- elsif access = note_max_access_for_user(note) %span.note-role= Gitlab::Access.human_access(access) - if note.resolvable? |