diff options
author | Rémy Coutable <remy@rymai.me> | 2018-08-01 18:21:24 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-08-01 18:21:24 +0300 |
commit | 83a0db0c551236518bdec1a7ae3a1ed1d05f5aaa (patch) | |
tree | e13ad022ea223e7bde5202a31ee81169225fec99 /lib/api | |
parent | ea6fc714bb0306ac8ca56b5dafe4b6777aafe5fc (diff) | |
parent | 12095251c3777c5231cab97854d5dca69d31cc5d (diff) |
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
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/entities.rb | 8 | ||||
-rw-r--r-- | lib/api/users.rb | 35 |
2 files changed, 43 insertions, 0 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 4be7707d3e7..f858d9fa23d 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -62,6 +62,14 @@ module API expose :admin?, as: :is_admin end + class UserStatus < Grape::Entity + expose :emoji + expose :message + expose :message_html do |entity| + MarkupHelper.markdown_field(entity, :message) + end + end + class Email < Grape::Entity expose :id, :email end diff --git a/lib/api/users.rb b/lib/api/users.rb index e83887b3e9e..b0811bb4aad 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -121,6 +121,17 @@ module API present user, opts end + desc "Get the status of a user" + params do + requires :id_or_username, type: String, desc: 'The ID or username of the user' + end + get ":id_or_username/status" do + user = find_user(params[:id_or_username]) + not_found!('User') unless user && can?(current_user, :read_user, user) + + present user.status || {}, with: Entities::UserStatus + end + desc 'Create a user. Available only for admins.' do success Entities::UserPublic end @@ -740,6 +751,30 @@ module API present paginate(activities), with: Entities::UserActivity end + + desc 'Set the status of the current user' do + success Entities::UserStatus + end + params do + optional :emoji, type: String, desc: "The emoji to set on the status" + optional :message, type: String, desc: "The status message to set" + end + put "status" do + forbidden! unless can?(current_user, :update_user_status, current_user) + + if ::Users::SetStatusService.new(current_user, declared_params).execute + present current_user.status, with: Entities::UserStatus + else + render_validation_error!(current_user.status) + end + end + + desc 'get the status of the current user' do + success Entities::UserStatus + end + get 'status' do + present current_user.status || {}, with: Entities::UserStatus + end end end end |