Skip to content
Snippets Groups Projects
Commit 83a0db0c authored by Rémy Coutable's avatar Rémy Coutable
Browse files

Merge branch 'bvl-user-status-message-35463' into 'master'

Allow users to set a status

Closes #35463

See merge request gitlab-org/gitlab-ce!20614
parents ea6fc714 12095251
No related branches found
No related tags found
1 merge request!10495Merge Requests - Assignee
Showing
with 74 additions and 14 deletions
Loading
Loading
@@ -74,6 +74,9 @@ export default {
</div>
<a :href="author.path">
<span class="note-header-author-name">{{ author.name }}</span>
<span
v-if="author.status_tooltip_html"
v-html="author.status_tooltip_html"></span>
<span class="note-headline-light">
@{{ author.username }}
</span>
Loading
Loading
Loading
Loading
@@ -113,6 +113,9 @@ export default {
 
{{ user.name }}
</a>
<span
v-if="user.status_tooltip_html"
v-html="user.status_tooltip_html"></span>
</template>
</section>
 
Loading
Loading
Loading
Loading
@@ -2,10 +2,18 @@ module MembersPresentation
extend ActiveSupport::Concern
 
def present_members(members)
preload_associations(members)
Gitlab::View::Presenter::Factory.new(
members,
current_user: current_user,
presenter_class: MembersPresenter
).fabricate!
end
def preload_associations(members)
ActiveRecord::Associations::Preloader.new.preload(members, :user)
ActiveRecord::Associations::Preloader.new.preload(members, :source)
ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :status)
ActiveRecord::Associations::Preloader.new.preload(members.map(&:user), :u2f_registrations)
end
end
module MembershipActions
include MembersPresentation
extend ActiveSupport::Concern
 
def create
Loading
Loading
@@ -20,6 +21,7 @@ module MembershipActions
.execute(member)
.present(current_user: current_user)
 
present_members([member])
respond_to do |format|
format.js { render 'shared/members/update', locals: { member: member } }
end
Loading
Loading
Loading
Loading
@@ -41,7 +41,7 @@ module NotesActions
@note = Notes::CreateService.new(note_project, current_user, create_params).execute
 
if @note.is_a?(Note)
Notes::RenderService.new(current_user).execute([@note])
prepare_notes_for_rendering([@note], noteable)
end
 
respond_to do |format|
Loading
Loading
@@ -56,7 +56,7 @@ module NotesActions
@note = Notes::UpdateService.new(project, current_user, note_params).execute(note)
 
if @note.is_a?(Note)
Notes::RenderService.new(current_user).execute([@note])
prepare_notes_for_rendering([@note])
end
 
respond_to do |format|
Loading
Loading
Loading
Loading
@@ -4,6 +4,7 @@ module RendersNotes
preload_noteable_for_regular_notes(notes)
preload_max_access_for_authors(notes, @project)
preload_first_time_contribution_for_authors(noteable, notes)
preload_author_status(notes)
Notes::RenderService.new(current_user).execute(notes)
 
notes
Loading
Loading
@@ -28,4 +29,8 @@ module RendersNotes
 
notes.each {|n| n.specialize_for_first_contribution!(noteable)}
end
def preload_author_status(notes)
ActiveRecord::Associations::Preloader.new.preload(notes, { author: :status })
end
end
Loading
Loading
@@ -30,7 +30,7 @@ class Groups::GroupMembersController < Groups::ApplicationController
end
 
@members = @members.page(params[:page]).per(50)
@members = present_members(@members.includes(:user))
@members = present_members(@members)
 
@requesters = present_members(
AccessRequestsFinder.new(@group).execute(current_user))
Loading
Loading
Loading
Loading
@@ -100,7 +100,8 @@ class ProfilesController < Profiles::ApplicationController
:website_url,
:organization,
:preferred_language,
:private_profile
:private_profile,
status: [:emoji, :message]
)
end
end
Loading
Loading
@@ -22,7 +22,9 @@ class Projects::CommitController < Projects::ApplicationController
apply_diff_view_cookie!
 
respond_to do |format|
format.html { render }
format.html do
render
end
format.diff do
send_git_diff(@project.repository, @commit.diff_refs)
end
Loading
Loading
@@ -124,7 +126,10 @@ class Projects::CommitController < Projects::ApplicationController
end
 
def commit
@noteable = @commit ||= @project.commit_by(oid: params[:id])
@noteable = @commit ||= @project.commit_by(oid: params[:id]).tap do |commit|
# preload author and their status for rendering
commit&.author&.status
end
end
 
def define_commit_vars
Loading
Loading
Loading
Loading
@@ -165,7 +165,7 @@ class Projects::IssuesController < Projects::ApplicationController
return @issue if defined?(@issue)
 
# The Sortable default scope causes performance issues when used with find_by
@issuable = @noteable = @issue ||= @project.issues.where(iid: params[:id]).reorder(nil).take!
@issuable = @noteable = @issue ||= @project.issues.includes(author: :status).where(iid: params[:id]).reorder(nil).take!
@note = @project.notes.new(noteable: @issuable)
 
return render_404 unless can?(current_user, :read_issue, @issue)
Loading
Loading
Loading
Loading
@@ -6,7 +6,7 @@ class Projects::MergeRequests::ApplicationController < Projects::ApplicationCont
private
 
def merge_request
@issuable = @merge_request ||= @project.merge_requests.find_by!(iid: params[:id])
@issuable = @merge_request ||= @project.merge_requests.includes(author: :status).find_by!(iid: params[:id])
end
 
def merge_request_params
Loading
Loading
class Projects::NotesController < Projects::ApplicationController
include RendersNotes
include NotesActions
include NotesHelper
include ToggleAwardEmoji
Loading
Loading
@@ -53,7 +54,7 @@ class Projects::NotesController < Projects::ApplicationController
private
 
def render_json_with_notes_serializer
Notes::RenderService.new(current_user).execute([note])
prepare_notes_for_rendering([note])
 
render json: note_serializer.represent(note)
end
Loading
Loading
Loading
Loading
@@ -161,7 +161,11 @@ class Projects::PipelinesController < Projects::ApplicationController
end
 
def pipeline
@pipeline ||= project.pipelines.find_by!(id: params[:id]).present(current_user: current_user)
@pipeline ||= project
.pipelines
.includes(user: :status)
.find_by!(id: params[:id])
.present(current_user: current_user)
end
 
def commit
Loading
Loading
Loading
Loading
@@ -88,7 +88,7 @@ class Projects::SnippetsController < Projects::ApplicationController
protected
 
def snippet
@snippet ||= @project.snippets.find(params[:id])
@snippet ||= @project.snippets.inc_relations_for_view.find(params[:id])
end
alias_method :awardable, :snippet
alias_method :spammable, :snippet
Loading
Loading
Loading
Loading
@@ -9,7 +9,7 @@ class Snippets::NotesController < ApplicationController
private
 
def note
@note ||= snippet.notes.find(params[:id])
@note ||= snippet.notes.inc_relations_for_view.find(params[:id])
end
alias_method :awardable, :note
 
Loading
Loading
Loading
Loading
@@ -95,7 +95,7 @@ class SnippetsController < ApplicationController
protected
 
def snippet
@snippet ||= PersonalSnippet.find_by(id: params[:id])
@snippet ||= PersonalSnippet.inc_relations_for_view.find_by(id: params[:id])
end
 
alias_method :awardable, :snippet
Loading
Loading
Loading
Loading
@@ -159,6 +159,12 @@ module IssuablesHelper
output << content_tag(:strong) do
author_output = link_to_member(project, issuable.author, size: 24, mobile_classes: "d-none d-sm-inline", tooltip: true)
author_output << link_to_member(project, issuable.author, size: 24, by_username: true, avatar: false, mobile_classes: "d-block d-sm-none")
if status = user_status(issuable.author)
author_output << "&ensp; #{status}".html_safe
end
author_output
end
 
output << "&ensp;".html_safe
Loading
Loading
Loading
Loading
@@ -9,4 +9,8 @@ module ProfilesHelper
end
end
end
def show_user_status_field?
Feature.enabled?(:user_status_form) || cookies[:feature_user_status_form] == 'true'
end
end
Loading
Loading
@@ -39,6 +39,24 @@ module UsersHelper
"access:#{max_project_member_access(project)}"
end
 
def user_status(user)
return unless user
unless user.association(:status).loaded?
exception = RuntimeError.new("Status was not preloaded")
Gitlab::Sentry.track_exception(exception, extra: { user: user.inspect })
end
return unless user.status
content_tag :span,
class: 'user-status-emoji has-tooltip',
title: user.status.message_html,
data: { html: true, placement: 'top' } do
emoji_icon user.status.emoji
end
end
private
 
def get_profile_tabs
Loading
Loading
Loading
Loading
@@ -101,7 +101,7 @@ class Note < ActiveRecord::Base
scope :inc_author_project, -> { includes(:project, :author) }
scope :inc_author, -> { includes(:author) }
scope :inc_relations_for_view, -> do
includes(:project, :author, :updated_by, :resolved_by, :award_emoji,
includes(:project, { author: :status }, :updated_by, :resolved_by, :award_emoji,
:system_note_metadata, :note_diff_file)
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment