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
fdd14516
Commit
fdd14516
authored
Dec 09, 2020
by
Adam Hegyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix user status update when availability is given
parent
e8fd0f30
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
15 deletions
+43
-15
app/services/users/set_status_service.rb
app/services/users/set_status_service.rb
+14
-5
spec/services/users/set_status_service_spec.rb
spec/services/users/set_status_service_spec.rb
+29
-10
No files found.
app/services/users/set_status_service.rb
View file @
fdd14516
...
...
@@ -14,10 +14,10 @@ module Users
def
execute
return
false
unless
can?
(
current_user
,
:update_user_status
,
target_user
)
if
params
[
:emoji
].
present?
||
params
[
:message
].
present?
||
params
[
:availability
].
present?
set_status
else
if
status_cleared?
remove_status
else
set_status
end
end
...
...
@@ -25,8 +25,7 @@ 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
])
params
[
:availability
]
=
UserStatus
.
availabilities
[
:not_set
]
unless
new_user_availability
user_status
.
update
(
params
)
end
...
...
@@ -38,5 +37,15 @@ module Users
def
user_status
target_user
.
status
||
target_user
.
build_status
end
def
status_cleared?
params
[
:emoji
].
blank?
&&
params
[
:message
].
blank?
&&
(
new_user_availability
.
blank?
||
new_user_availability
==
UserStatus
.
availabilities
[
:not_set
])
end
def
new_user_availability
UserStatus
.
availabilities
[
params
[
:availability
]]
end
end
end
spec/services/users/set_status_service_spec.rb
View file @
fdd14516
...
...
@@ -31,19 +31,28 @@ RSpec.describe Users::SetStatusService do
expect
(
service
.
execute
).
to
be
(
true
)
end
context
'when setting availability to not_set'
do
before
do
params
[
:availability
]
=
'not_set'
create
(
:user_status
,
user:
current_user
,
availability:
'busy'
)
end
it
'updates the availability'
do
expect
{
service
.
execute
}.
to
change
{
current_user
.
status
.
availability
}.
from
(
'busy'
).
to
(
'not_set'
)
end
end
context
'when the given availability value is not valid'
do
let
(
:params
)
{
{
availability:
'not a valid value'
}
}
before
do
params
[
:availability
]
=
'not a valid value'
end
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
...
...
@@ -69,11 +78,21 @@ RSpec.describe Users::SetStatusService do
context
'without params'
do
let
(
:params
)
{
{}
}
it
'deletes the status'
do
status
=
create
(
:user_status
,
user:
current_user
)
shared_examples
'removes user status record'
do
it
'deletes the status'
do
status
=
create
(
:user_status
,
user:
current_user
)
expect
{
service
.
execute
}
.
to
change
{
current_user
.
reload
.
status
}.
from
(
status
).
to
(
nil
)
end
end
it_behaves_like
'removes user status record'
context
'when not_set is given for availability'
do
let
(
:params
)
{
{
availability:
'not_set'
}
}
expect
{
service
.
execute
}
.
to
change
{
current_user
.
reload
.
status
}.
from
(
status
).
to
(
nil
)
it_behaves_like
'removes user status record'
end
end
end
...
...
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