Commit cf13d476 authored by Magdalena Frankiewicz's avatar Magdalena Frankiewicz

Have two availabilities: not_set and busy

Make not_set a default availability
parent c33a1314
......@@ -127,7 +127,7 @@ class ProfilesController < Profiles::ApplicationController
:include_private_contributions,
:timezone,
:job_title,
status: [:emoji, :message]
status: [:emoji, :message, :availability]
)
end
end
......@@ -5,6 +5,8 @@ module Types
graphql_name 'AvailabilityEnum'
description 'User availability status'
value 'BUSY', value: :busy
::UserStatus.availabilities.keys.each do |availability_value|
value availability_value.upcase, value: availability_value, description: availability_value.titleize
end
end
end
......@@ -11,7 +11,7 @@ module Types
description: 'User status message'
field :emoji, GraphQL::STRING_TYPE, null: true,
description: 'String representation of emoji'
field :availability, Types::AvailabilityEnum, null: true,
field :availability, Types::AvailabilityEnum, null: false,
description: 'User availability status'
end
end
......@@ -9,7 +9,7 @@ class UserStatus < ApplicationRecord
belongs_to :user
enum availability: { busy: 0 }
enum availability: { not_set: 0, busy: 1 }
validates :user, presence: true
validates :emoji, inclusion: { in: Gitlab::Emoji.emojis_names }
......
......@@ -14,7 +14,7 @@ module Users
def execute
return false unless can?(current_user, :update_user_status, target_user)
if params[:emoji].present? || params[:message].present?
if params[:emoji].present? || params[:message].present? || params[:availability].present?
set_status
else
remove_status
......@@ -25,6 +25,9 @@ module Users
def set_status
params[:emoji] = UserStatus::DEFAULT_EMOJI if params[:emoji].blank?
params.delete(:availability) if params[:availability].blank?
return false if params[:availability].present? && UserStatus.availabilities.keys.exclude?(params[:availability])
user_status.update(params)
end
......
......@@ -4,6 +4,6 @@ class AddAvailabilityToUserStatuses < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
add_column :user_statuses, :availability, :integer, limit: 2
add_column :user_statuses, :availability, :integer, limit: 2, default: 0, null: false
end
end
......@@ -16783,7 +16783,7 @@ CREATE TABLE user_statuses (
emoji character varying DEFAULT 'speech_balloon'::character varying NOT NULL,
message character varying(100),
message_html character varying,
availability smallint
availability smallint DEFAULT 0 NOT NULL
);
CREATE SEQUENCE user_statuses_user_id_seq
......
......@@ -931,7 +931,15 @@ type AlertTodoCreatePayload {
User availability status
"""
enum AvailabilityEnum {
"""
Busy
"""
BUSY
"""
Not Set
"""
NOT_SET
}
"""
......@@ -21369,7 +21377,7 @@ type UserStatus {
"""
User availability status
"""
availability: AvailabilityEnum
availability: AvailabilityEnum!
"""
String representation of emoji
......
......@@ -2399,9 +2399,15 @@
"inputFields": null,
"interfaces": null,
"enumValues": [
{
"name": "NOT_SET",
"description": "Not Set",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "BUSY",
"description": null,
"description": "Busy",
"isDeprecated": false,
"deprecationReason": null
}
......@@ -61800,9 +61806,13 @@
],
"type": {
"kind": "ENUM",
"name": "AvailabilityEnum",
"ofType": null
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "AvailabilityEnum",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
......@@ -2979,7 +2979,7 @@ Autogenerated return type of UpdateSnippet.
| Field | Type | Description |
| ----- | ---- | ----------- |
| `availability` | AvailabilityEnum | User availability status |
| `availability` | AvailabilityEnum! | User availability status |
| `emoji` | String | String representation of emoji |
| `message` | String | User status message |
| `messageHtml` | String | HTML of the user status message |
......@@ -3314,7 +3314,8 @@ User availability status.
| Value | Description |
| ----- | ----------- |
| `BUSY` | |
| `BUSY` | Busy |
| `NOT_SET` | Not Set |
### BlobViewersType
......
......@@ -952,6 +952,7 @@ module API
params do
optional :emoji, type: String, desc: "The emoji to set on the status"
optional :message, type: String, desc: "The status message to set"
optional :availability, type: String, desc: "The availability of user to set"
end
put "status", feature_category: :users do
forbidden! unless can?(current_user, :update_user_status, current_user)
......
......@@ -84,9 +84,10 @@ RSpec.describe ProfilesController, :request_store do
it 'allows setting a user status' do
sign_in(user)
put :update, params: { user: { status: { message: 'Working hard!' } } }
put :update, params: { user: { status: { message: 'Working hard!', availability: 'busy' } } }
expect(user.reload.status.message).to eq('Working hard!')
expect(user.reload.status.availability).to eq('busy')
expect(response).to have_gitlab_http_status(:found)
end
......
......@@ -6,6 +6,6 @@ RSpec.describe GitlabSchema.types['AvailabilityEnum'] do
specify { expect(described_class.graphql_name).to eq('AvailabilityEnum') }
it 'exposes all the existing access levels' do
expect(described_class.values.keys).to match_array(%w[BUSY])
expect(described_class.values.keys).to match_array(%w[NOT_SET BUSY])
end
end
......@@ -59,6 +59,7 @@ RSpec.describe 'getting user information' do
let(:user_params) { { username: user.username } }
before do
create(:user_status, user: user)
post_graphql(query, current_user: current_user)
end
......@@ -76,9 +77,15 @@ RSpec.describe 'getting user information' do
'username' => presenter.username,
'webUrl' => presenter.web_url,
'avatarUrl' => presenter.avatar_url,
'status' => presenter.status,
'email' => presenter.email
))
expect(graphql_data['user']['status']).to match(
a_hash_including(
'emoji' => presenter.status.emoji,
'message' => presenter.status.message,
'availability' => presenter.status.availability.upcase
))
end
describe 'assignedMergeRequests' do
......
......@@ -9,13 +9,14 @@ RSpec.describe Users::SetStatusService do
describe '#execute' do
context 'when params are set' do
let(:params) { { emoji: 'taurus', message: 'a random status' } }
let(:params) { { emoji: 'taurus', message: 'a random status', availability: 'busy' } }
it 'creates a status' do
service.execute
expect(current_user.status.emoji).to eq('taurus')
expect(current_user.status.message).to eq('a random status')
expect(current_user.status.availability).to eq('busy')
end
it 'updates a status if it already existed' do
......@@ -25,6 +26,26 @@ RSpec.describe Users::SetStatusService do
expect(current_user.status.message).to eq('a random status')
end
it 'returns true' do
create(:user_status, user: current_user)
expect(service.execute).to be(true)
end
context 'when the given availability value is not valid' do
let(:params) { { availability: 'not a valid value' } }
it 'does not update the status' do
user_status = create(:user_status, user: current_user)
expect { service.execute }.not_to change { user_status.reload }
end
it 'returns false' do
create(:user_status, user: current_user)
expect(service.execute).to be(false)
end
end
context 'for another user' do
let(:target_user) { create(:user) }
let(:params) do
......
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