Commit b44a1bcd authored by micael.bergeron's avatar micael.bergeron

rework the contributor badge

 - only show in merge-requests
 - show as a little glyph
parent 45b83ed9
...@@ -620,15 +620,26 @@ ul.notes { ...@@ -620,15 +620,26 @@ ul.notes {
.note-role { .note-role {
position: relative; position: relative;
padding: 0 7px; display: inline-block;
color: $notes-role-color; color: $notes-role-color;
font-size: 12px; font-size: 12px;
line-height: 20px; line-height: 20px;
border: 1px solid $border-color;
border-radius: $label-border-radius; &.note-role-access {
top: -2px;
padding: 0 7px;
border: 1px solid $border-color;
border-radius: $label-border-radius;
}
&.note-role-special {
top: -3px;
text-shadow: 0 0 15px white;
}
} }
/** /**
* Line note button on the side of diffs * Line note button on the side of diffs
*/ */
......
...@@ -2,7 +2,7 @@ module RendersNotes ...@@ -2,7 +2,7 @@ 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_noteable_for_regular_notes(notes)
preload_max_access_for_authors(notes, @project) preload_max_access_for_authors(notes, @project)
preload_first_time_contribution_for_authors(noteable, notes) if noteable.is_a?(Issuable) preload_first_time_contribution_for_authors(noteable, notes)
Banzai::NoteRenderer.render(notes, @project, current_user) Banzai::NoteRenderer.render(notes, @project, current_user)
notes notes
...@@ -21,12 +21,9 @@ module RendersNotes ...@@ -21,12 +21,9 @@ module RendersNotes
ActiveRecord::Associations::Preloader.new.preload(notes.reject(&:for_commit?), :noteable) ActiveRecord::Associations::Preloader.new.preload(notes.reject(&:for_commit?), :noteable)
end end
def preload_first_time_contribution_for_authors(issuable, notes) def preload_first_time_contribution_for_authors(noteable, notes)
return unless issuable.first_contribution? return unless noteable.is_a?(Issuable) && noteable.first_contribution?
same_author = lambda {|n| n.author_id == issuable.author_id} notes.each {|n| n.specialize_for_first_contribution!(noteable)}
notes.each do |note|
note.specialize!(Note::SpecialRole::FIRST_TIME_CONTRIBUTOR, &same_author)
end
end end
end end
...@@ -138,7 +138,7 @@ module IssuablesHelper ...@@ -138,7 +138,7 @@ module IssuablesHelper
end end
output << "&ensp;".html_safe output << "&ensp;".html_safe
output << issuable_first_contribution_icon if issuable.first_contribution? output << content_tag(:span, (issuable_first_contribution_icon if issuable.first_contribution?), class: 'has-tooltip', title: _('1st contribution!'))
output << content_tag(:span, (issuable.task_status if issuable.tasks?), id: "task_status", class: "hidden-xs hidden-sm") output << content_tag(:span, (issuable.task_status if issuable.tasks?), id: "task_status", class: "hidden-xs hidden-sm")
output << content_tag(:span, (issuable.task_status_short if issuable.tasks?), id: "task_status_short", class: "hidden-md hidden-lg") output << content_tag(:span, (issuable.task_status_short if issuable.tasks?), id: "task_status_short", class: "hidden-md hidden-lg")
...@@ -176,7 +176,7 @@ module IssuablesHelper ...@@ -176,7 +176,7 @@ module IssuablesHelper
end end
def issuable_first_contribution_icon def issuable_first_contribution_icon
content_tag(:span, class: 'fa-stack has-tooltip', title: _('1st contribution!')) do content_tag(:span, class: 'fa-stack') do
concat(icon('certificate', class: "fa-stack-2x")) concat(icon('certificate', class: "fa-stack-2x"))
concat(content_tag(:strong, '1', class: 'fa-inverse fa-stack-1x')) concat(content_tag(:strong, '1', class: 'fa-inverse fa-stack-1x'))
end end
......
...@@ -335,9 +335,10 @@ module Issuable ...@@ -335,9 +335,10 @@ module Issuable
metrics.record! metrics.record!
end end
def first_contribution? ##
return false if project.team.max_member_access(author_id) > Gitlab::Access::GUEST # Override in issuable specialization
#
project.merge_requests.merged.where(author_id: author_id).empty? def first_contribution?(*)
false
end end
end end
...@@ -960,6 +960,11 @@ class MergeRequest < ActiveRecord::Base ...@@ -960,6 +960,11 @@ class MergeRequest < ActiveRecord::Base
Projects::OpenMergeRequestsCountService.new(target_project).refresh_cache Projects::OpenMergeRequestsCountService.new(target_project).refresh_cache
end end
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
private private
def write_ref def write_ref
......
...@@ -236,6 +236,11 @@ class Note < ActiveRecord::Base ...@@ -236,6 +236,11 @@ class Note < ActiveRecord::Base
def specialize!(role) def specialize!(role)
self.special_role = role if !block_given? || yield(self) self.special_role = role if !block_given? || yield(self)
end end
def specialize_for_first_contribution!(noteable)
return unless noteable.author_id == self.author_id
specialize!(Note::SpecialRole::FIRST_TIME_CONTRIBUTOR)
end
def editable? def editable?
!system? !system?
......
- if note.has_special_role?(Note::SpecialRole::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.")} %span.note-role.note-role-special.has-tooltip{ title: _("This user hasn't yet contributed code to this project. Handle with care.")}
= _('First-time contributor') = issuable_first_contribution_icon
- elsif access = note_max_access_for_user(note) - if access = note_max_access_for_user(note)
%span.note-role= Gitlab::Access.human_access(access) %span.note-role.note-role-access= Gitlab::Access.human_access(access)
- if note.resolvable? - if note.resolvable?
- can_resolve = can?(current_user, :resolve_note, note) - can_resolve = can?(current_user, :resolve_note, note)
......
...@@ -539,20 +539,12 @@ describe Issuable do ...@@ -539,20 +539,12 @@ describe Issuable do
context "for issues" do context "for issues" do
let(:contributor_issue) { create(:issue, author: contributor, project: project) } let(:contributor_issue) { create(:issue, author: contributor, project: project) }
let(:first_time_contributor_issue) { create(:issue, author: first_time_contributor, project: project) } let(:first_time_contributor_issue) { create(:issue, author: first_time_contributor, project: project) }
let(:first_time_contributor_issue_other_project) { create(:issue, author: first_time_contributor, project: other_project) }
it "is true when you don't have any merged MR" do it "is false even without merged MR" do
expect(merged_mr).to be expect(merged_mr).to be
expect(first_time_contributor_issue).to be_first_contribution expect(first_time_contributor_issue).not_to be_first_contribution
expect(contributor_issue).not_to be_first_contribution expect(contributor_issue).not_to be_first_contribution
end end
it "handles multiple projects separately" do
expect(merged_mr).to be
expect(merged_mr_other_project).to be
expect(first_time_contributor_issue).to be_first_contribution
expect(first_time_contributor_issue_other_project).not_to be_first_contribution
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment