gitlab-org--gitlab-foss/app/services/users/set_status_service.rb
Bob Van Landuyt f1d3ea63cf Show the status of a user in interactions
The status is shown for
- The author of a commit when viewing a commit
- Notes on a commit (regular/diff)
- The user that triggered a pipeline when viewing a pipeline
- The author of a merge request when viewing a merge request
- The author of notes on a merge request (regular/diff)
- The author of an issue when viewing an issue
- The author of notes on an issue
- The author of a snippet when viewing a snippet
- The author of notes on a snippet
- A user's profile page
- The list of members of a group/user
2018-07-30 15:01:26 +02:00

39 lines
857 B
Ruby

# frozen_string_literal: true
module Users
class SetStatusService
include Gitlab::Allowable
attr_reader :current_user, :target_user, :params
def initialize(current_user, params)
@current_user, @params = current_user, params.dup
@target_user = params.delete(:user) || current_user
end
def execute
return false unless can?(current_user, :update_user_status, target_user)
if params[:emoji].present? || params[:message].present?
set_status
else
remove_status
end
end
private
def set_status
params[:emoji] = UserStatus::DEFAULT_EMOJI if params[:emoji].blank?
user_status.update(params)
end
def remove_status
UserStatus.delete(target_user.id)
end
def user_status
target_user.status || target_user.build_status
end
end
end