Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-07-13 18:52:31 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2018-07-30 16:01:26 +0300
commitb4c4b48a8c0258ff266c523488aa169a1b5ea0f3 (patch)
tree7b2c5a6b1f3bc7e672cb3e64600e6bd2403d8748 /app
parent812bfb158b70b09cfd438379a4b9446aa85b52ec (diff)
Allow users to set a status
This can be done trough the API for the current user, or on the profile page.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/profiles_controller.rb3
-rw-r--r--app/models/user.rb2
-rw-r--r--app/models/user_status.rb2
-rw-r--r--app/policies/user_policy.rb1
-rw-r--r--app/services/users/set_status_service.rb38
-rw-r--r--app/services/users/update_service.rb12
-rw-r--r--app/views/profiles/show.html.haml10
7 files changed, 64 insertions, 4 deletions
diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb
index 56a7b766b77..6f50cbb4a36 100644
--- a/app/controllers/profiles_controller.rb
+++ b/app/controllers/profiles_controller.rb
@@ -100,7 +100,8 @@ class ProfilesController < Profiles::ApplicationController
:website_url,
:organization,
:preferred_language,
- :private_profile
+ :private_profile,
+ status: [:emoji, :message]
)
end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 58429f8d607..a85a6d41378 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -141,6 +141,8 @@ class User < ActiveRecord::Base
has_many :term_agreements
belongs_to :accepted_term, class_name: 'ApplicationSetting::Term'
+ has_one :status, class_name: 'UserStatus'
+
#
# Validations
#
diff --git a/app/models/user_status.rb b/app/models/user_status.rb
index df65d89b03c..72938cfbca0 100644
--- a/app/models/user_status.rb
+++ b/app/models/user_status.rb
@@ -9,5 +9,5 @@ class UserStatus < ActiveRecord::Base
validates :emoji, inclusion: { in: Gitlab::Emoji.emojis_names }
validates :message, length: { maximum: 100 }, allow_blank: true
- cache_markdown_field :message, pipeline: :single_line
+ cache_markdown_field :message, pipeline: :emoji
end
diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb
index b5717029354..e1efd84e510 100644
--- a/app/policies/user_policy.rb
+++ b/app/policies/user_policy.rb
@@ -16,6 +16,7 @@ class UserPolicy < BasePolicy
rule { ~subject_ghost & (user_is_self | admin) }.policy do
enable :destroy_user
enable :update_user
+ enable :update_user_status
end
rule { default }.enable :read_user_profile
diff --git a/app/services/users/set_status_service.rb b/app/services/users/set_status_service.rb
new file mode 100644
index 00000000000..275e13faf59
--- /dev/null
+++ b/app/services/users/set_status_service.rb
@@ -0,0 +1,38 @@
+# 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
+ 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
diff --git a/app/services/users/update_service.rb b/app/services/users/update_service.rb
index 6dadb5a4eac..a897e4bd56a 100644
--- a/app/services/users/update_service.rb
+++ b/app/services/users/update_service.rb
@@ -7,6 +7,7 @@ module Users
def initialize(current_user, params = {})
@current_user = current_user
@user = params.delete(:user)
+ @status_params = params.delete(:status)
@params = params.dup
end
@@ -17,10 +18,11 @@ module Users
assign_attributes(&block)
- if @user.save(validate: validate)
+ if @user.save(validate: validate) && update_status
notify_success(user_exists)
else
- error(@user.errors.full_messages.uniq.join('. '))
+ messages = @user.errors.full_messages + Array(@user.status&.errors&.full_messages)
+ error(messages.uniq.join('. '))
end
end
@@ -34,6 +36,12 @@ module Users
private
+ def update_status
+ return true unless @status_params
+
+ Users::SetStatusService.new(current_user, @status_params.merge(user: @user)).execute
+ end
+
def notify_success(user_exists)
notify_new_user(@user, nil) unless user_exists
diff --git a/app/views/profiles/show.html.haml b/app/views/profiles/show.html.haml
index a4835584b50..5e70cc09104 100644
--- a/app/views/profiles/show.html.haml
+++ b/app/views/profiles/show.html.haml
@@ -33,6 +33,16 @@
%hr
.row
.col-lg-4.profile-settings-sidebar
+ %h4.prepend-top-0= s_("User|Current Status")
+ %p= _("This emoji and message will appear on your profile and throughout the interface.")
+ .col-lg-8
+ .row
+ = f.fields_for :status, @user.status do |status_form|
+ = status_form.text_field :emoji
+ = status_form.text_field :message, maxlength: 100
+ %hr
+ .row
+ .col-lg-4.profile-settings-sidebar
%h4.prepend-top-0
Main settings
%p