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
ebde9bd6
Commit
ebde9bd6
authored
Feb 03, 2022
by
eugielimpin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update API to accept BroadcastMessage target_access_levels attribute
parent
4c3e65b0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
3 deletions
+26
-3
lib/api/broadcast_messages.rb
lib/api/broadcast_messages.rb
+4
-0
lib/api/entities/broadcast_message.rb
lib/api/entities/broadcast_message.rb
+1
-1
spec/requests/api/broadcast_messages_spec.rb
spec/requests/api/broadcast_messages_spec.rb
+21
-2
No files found.
lib/api/broadcast_messages.rb
View file @
ebde9bd6
...
...
@@ -36,6 +36,8 @@ module API
optional
:ends_at
,
type:
DateTime
,
desc:
'Ending time'
,
default:
->
{
1
.
hour
.
from_now
}
optional
:color
,
type:
String
,
desc:
'Background color'
optional
:font
,
type:
String
,
desc:
'Foreground color'
optional
:target_access_levels
,
type:
Array
[
Integer
],
coerce_with:
Validations
::
Types
::
CommaSeparatedToIntegerArray
.
coerce
,
values:
BroadcastMessage
::
ALLOWED_TARGET_ACCESS_LEVELS
,
desc:
'Target user roles'
optional
:target_path
,
type:
String
,
desc:
'Target path'
optional
:broadcast_type
,
type:
String
,
values:
BroadcastMessage
.
broadcast_types
.
keys
,
desc:
'Broadcast type. Defaults to banner'
,
default:
->
{
'banner'
}
optional
:dismissable
,
type:
Boolean
,
desc:
'Is dismissable'
...
...
@@ -76,6 +78,8 @@ module API
optional
:ends_at
,
type:
DateTime
,
desc:
'Ending time'
optional
:color
,
type:
String
,
desc:
'Background color'
optional
:font
,
type:
String
,
desc:
'Foreground color'
optional
:target_access_levels
,
type:
Array
[
Integer
],
coerce_with:
Validations
::
Types
::
CommaSeparatedToIntegerArray
.
coerce
,
values:
BroadcastMessage
::
ALLOWED_TARGET_ACCESS_LEVELS
,
desc:
'Target user roles'
optional
:target_path
,
type:
String
,
desc:
'Target path'
optional
:broadcast_type
,
type:
String
,
values:
BroadcastMessage
.
broadcast_types
.
keys
,
desc:
'Broadcast Type'
optional
:dismissable
,
type:
Boolean
,
desc:
'Is dismissable'
...
...
lib/api/entities/broadcast_message.rb
View file @
ebde9bd6
...
...
@@ -3,7 +3,7 @@
module
API
module
Entities
class
BroadcastMessage
<
Grape
::
Entity
expose
:id
,
:message
,
:starts_at
,
:ends_at
,
:color
,
:font
,
:target_path
,
:broadcast_type
,
:dismissable
expose
:id
,
:message
,
:starts_at
,
:ends_at
,
:color
,
:font
,
:target_
access_levels
,
:target_
path
,
:broadcast_type
,
:dismissable
expose
:active?
,
as: :active
end
end
...
...
spec/requests/api/broadcast_messages_spec.rb
View file @
ebde9bd6
...
...
@@ -17,7 +17,7 @@ RSpec.describe API::BroadcastMessages do
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_kind_of
(
Array
)
expect
(
json_response
.
first
.
keys
)
.
to
match_array
(
%w(id message starts_at ends_at color font active target_path broadcast_type dismissable)
)
.
to
match_array
(
%w(id message starts_at ends_at color font active target_
access_levels target_
path broadcast_type dismissable)
)
end
end
...
...
@@ -28,7 +28,7 @@ RSpec.describe API::BroadcastMessages do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'id'
]).
to
eq
message
.
id
expect
(
json_response
.
keys
)
.
to
match_array
(
%w(id message starts_at ends_at color font active target_path broadcast_type dismissable)
)
.
to
match_array
(
%w(id message starts_at ends_at color font active target_
access_levels target_
path broadcast_type dismissable)
)
end
end
...
...
@@ -77,6 +77,16 @@ RSpec.describe API::BroadcastMessages do
expect
(
json_response
[
'font'
]).
to
eq
attrs
[
:font
]
end
it
'accepts target access levels'
do
target_access_levels
=
[
Gitlab
::
Access
::
GUEST
,
Gitlab
::
Access
::
DEVELOPER
]
attrs
=
attributes_for
(
:broadcast_message
,
target_access_levels:
target_access_levels
)
post
api
(
'/broadcast_messages'
,
admin
),
params:
attrs
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
expect
(
json_response
[
'target_access_levels'
]).
to
eq
attrs
[
:target_access_levels
]
end
it
'accepts a target path'
do
attrs
=
attributes_for
(
:broadcast_message
,
target_path:
"*/welcome"
)
...
...
@@ -171,6 +181,15 @@ RSpec.describe API::BroadcastMessages do
expect
{
message
.
reload
}.
to
change
{
message
.
message
}.
to
(
'new message'
)
end
it
'accepts a new target_access_levels'
do
attrs
=
{
target_access_levels:
[
Gitlab
::
Access
::
MAINTAINER
]
}
put
api
(
"/broadcast_messages/
#{
message
.
id
}
"
,
admin
),
params:
attrs
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'target_access_levels'
]).
to
eq
attrs
[
:target_access_levels
]
end
it
'accepts a new target_path'
do
attrs
=
{
target_path:
'*/welcome'
}
...
...
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