Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
cf13d476
Commit
cf13d476
authored
Oct 23, 2020
by
Magdalena Frankiewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Have two availabilities: not_set and busy
Make not_set a default availability
parent
c33a1314
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
72 additions
and
18 deletions
+72
-18
app/controllers/profiles_controller.rb
app/controllers/profiles_controller.rb
+1
-1
app/graphql/types/availability_enum.rb
app/graphql/types/availability_enum.rb
+3
-1
app/graphql/types/user_status_type.rb
app/graphql/types/user_status_type.rb
+1
-1
app/models/user_status.rb
app/models/user_status.rb
+1
-1
app/services/users/set_status_service.rb
app/services/users/set_status_service.rb
+4
-1
db/migrate/20201022103304_add_availability_to_user_statuses.rb
...grate/20201022103304_add_availability_to_user_statuses.rb
+1
-1
db/structure.sql
db/structure.sql
+1
-1
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+9
-1
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+14
-4
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+3
-2
lib/api/users.rb
lib/api/users.rb
+1
-0
spec/controllers/profiles_controller_spec.rb
spec/controllers/profiles_controller_spec.rb
+2
-1
spec/graphql/types/availability_enum_spec.rb
spec/graphql/types/availability_enum_spec.rb
+1
-1
spec/requests/api/graphql/user_query_spec.rb
spec/requests/api/graphql/user_query_spec.rb
+8
-1
spec/services/users/set_status_service_spec.rb
spec/services/users/set_status_service_spec.rb
+22
-1
No files found.
app/controllers/profiles_controller.rb
View file @
cf13d476
...
...
@@ -127,7 +127,7 @@ class ProfilesController < Profiles::ApplicationController
:include_private_contributions
,
:timezone
,
:job_title
,
status:
[
:emoji
,
:message
]
status:
[
:emoji
,
:message
,
:availability
]
)
end
end
app/graphql/types/availability_enum.rb
View file @
cf13d476
...
...
@@ -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
app/graphql/types/user_status_type.rb
View file @
cf13d476
...
...
@@ -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:
tru
e
,
field
:availability
,
Types
::
AvailabilityEnum
,
null:
fals
e
,
description:
'User availability status'
end
end
app/models/user_status.rb
View file @
cf13d476
...
...
@@ -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
}
...
...
app/services/users/set_status_service.rb
View file @
cf13d476
...
...
@@ -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
...
...
db/migrate/20201022103304_add_availability_to_user_statuses.rb
View file @
cf13d476
...
...
@@ -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
db/structure.sql
View file @
cf13d476
...
...
@@ -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
...
...
doc/api/graphql/reference/gitlab_schema.graphql
View file @
cf13d476
...
...
@@ -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
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
cf13d476
...
...
@@ -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
doc/api/graphql/reference/index.md
View file @
cf13d476
...
...
@@ -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
...
...
lib/api/users.rb
View file @
cf13d476
...
...
@@ -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
)
...
...
spec/controllers/profiles_controller_spec.rb
View file @
cf13d476
...
...
@@ -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
...
...
spec/graphql/types/availability_enum_spec.rb
View file @
cf13d476
...
...
@@ -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
spec/requests/api/graphql/user_query_spec.rb
View file @
cf13d476
...
...
@@ -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
...
...
spec/services/users/set_status_service_spec.rb
View file @
cf13d476
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment