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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
03b2ac65
Commit
03b2ac65
authored
Jun 15, 2017
by
Mike Ricketts
Committed by
Rémy Coutable
Jun 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#13336 - display multiple messages in both the UI and git output
parent
039c3753
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
19 deletions
+61
-19
app/helpers/broadcast_messages_helper.rb
app/helpers/broadcast_messages_helper.rb
+1
-1
app/models/broadcast_message.rb
app/models/broadcast_message.rb
+1
-1
app/views/layouts/_broadcast.html.haml
app/views/layouts/_broadcast.html.haml
+2
-1
changelogs/unreleased/13336-multiple-broadcast-messages.yml
changelogs/unreleased/13336-multiple-broadcast-messages.yml
+4
-0
lib/api/internal.rb
lib/api/internal.rb
+9
-1
spec/models/broadcast_message_spec.rb
spec/models/broadcast_message_spec.rb
+13
-6
spec/requests/api/internal_spec.rb
spec/requests/api/internal_spec.rb
+31
-9
No files found.
app/helpers/broadcast_messages_helper.rb
View file @
03b2ac65
module
BroadcastMessagesHelper
def
broadcast_message
(
message
=
BroadcastMessage
.
current
)
def
broadcast_message
(
message
)
return
unless
message
.
present?
content_tag
:div
,
class:
'broadcast-message'
,
style:
broadcast_message_style
(
message
)
do
...
...
app/models/broadcast_message.rb
View file @
03b2ac65
...
...
@@ -16,7 +16,7 @@ class BroadcastMessage < ActiveRecord::Base
def
self
.
current
Rails
.
cache
.
fetch
(
"broadcast_message_current"
,
expires_in:
1
.
minute
)
do
where
(
"ends_at > :now AND starts_at <= :now"
,
now:
Time
.
zone
.
now
).
last
where
(
'ends_at > :now AND starts_at <= :now'
,
now:
Time
.
zone
.
now
).
order
([
:created_at
,
:id
]).
to_a
end
end
...
...
app/views/layouts/_broadcast.html.haml
View file @
03b2ac65
=
broadcast_message
-
BroadcastMessage
.
current
.
each
do
|
message
|
=
broadcast_message
(
message
)
changelogs/unreleased/13336-multiple-broadcast-messages.yml
0 → 100644
View file @
03b2ac65
---
title
:
Display all current broadcast messages, not just the last one
merge_request
:
11113
author
:
rickettm
lib/api/internal.rb
View file @
03b2ac65
...
...
@@ -86,8 +86,16 @@ module API
}
end
get
"/broadcast_messages"
do
if
messages
=
BroadcastMessage
.
current
present
messages
,
with:
Entities
::
BroadcastMessage
else
[]
end
end
get
"/broadcast_message"
do
if
message
=
BroadcastMessage
.
current
if
message
=
BroadcastMessage
.
current
.
last
present
message
,
with:
Entities
::
BroadcastMessage
else
{}
...
...
spec/models/broadcast_message_spec.rb
View file @
03b2ac65
...
...
@@ -21,22 +21,29 @@ describe BroadcastMessage, models: true do
end
describe
'.current'
do
it
"returns last message if time match"
do
it
'returns message if time match'
do
message
=
create
(
:broadcast_message
)
expect
(
BroadcastMessage
.
current
).
to
eq
message
expect
(
BroadcastMessage
.
current
).
to
include
(
message
)
end
it
"returns nil if time not come"
do
it
'returns multiple messages if time match'
do
message1
=
create
(
:broadcast_message
)
message2
=
create
(
:broadcast_message
)
expect
(
BroadcastMessage
.
current
).
to
contain_exactly
(
message1
,
message2
)
end
it
'returns empty list if time not come'
do
create
(
:broadcast_message
,
:future
)
expect
(
BroadcastMessage
.
current
).
to
be_
nil
expect
(
BroadcastMessage
.
current
).
to
be_
empty
end
it
"returns nil if time has passed"
do
it
'returns empty list if time has passed'
do
create
(
:broadcast_message
,
:expired
)
expect
(
BroadcastMessage
.
current
).
to
be_
nil
expect
(
BroadcastMessage
.
current
).
to
be_
empty
end
end
...
...
spec/requests/api/internal_spec.rb
View file @
03b2ac65
...
...
@@ -15,21 +15,43 @@ describe API::Internal do
end
end
describe
"GET /internal/broadcast_message"
do
context
"broadcast message exists"
do
let!
(
:broadcast_message
)
{
create
(
:broadcast_message
,
starts_at:
Time
.
now
.
yesterday
,
ends_at:
Time
.
now
.
tomorr
ow
)
}
describe
'GET /internal/broadcast_message'
do
context
'broadcast message exists'
do
let!
(
:broadcast_message
)
{
create
(
:broadcast_message
,
starts_at:
1
.
day
.
ago
,
ends_at:
1
.
day
.
from_n
ow
)
}
it
do
get
api
(
"/internal/broadcast_message"
),
secret_token:
secret_token
it
'returns one broadcast message'
do
get
api
(
'/internal/broadcast_message'
),
secret_token:
secret_token
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"message"
]).
to
eq
(
broadcast_message
.
message
)
expect
(
json_response
[
'message'
]).
to
eq
(
broadcast_message
.
message
)
end
end
context
"broadcast message doesn't exist"
do
it
do
get
api
(
"/internal/broadcast_message"
),
secret_token:
secret_token
context
'broadcast message does not exist'
do
it
'returns nothing'
do
get
api
(
'/internal/broadcast_message'
),
secret_token:
secret_token
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_empty
end
end
end
describe
'GET /internal/broadcast_messages'
do
context
'broadcast message(s) exist'
do
let!
(
:broadcast_message
)
{
create
(
:broadcast_message
,
starts_at:
1
.
day
.
ago
,
ends_at:
1
.
day
.
from_now
)
}
it
'returns active broadcast message(s)'
do
get
api
(
'/internal/broadcast_messages'
),
secret_token:
secret_token
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
0
][
'message'
]).
to
eq
(
broadcast_message
.
message
)
end
end
context
'broadcast message does not exist'
do
it
'returns nothing'
do
get
api
(
'/internal/broadcast_messages'
),
secret_token:
secret_token
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_empty
...
...
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