Commit 37f45fd7 authored by Robert May's avatar Robert May Committed by Kerri Miller

Improve scoped message support for shell

Updates the post receive service to allow the display of
broadcast messages which feature a target_path if the
project path matches, or returns a generic broadcast if
no specific one is found.
parent a05759d0
...@@ -29,9 +29,7 @@ class PostReceiveService ...@@ -29,9 +29,7 @@ class PostReceiveService
response.add_alert_message(message) response.add_alert_message(message)
end end
broadcast_message = BroadcastMessage.current_banner_messages&.last&.message
response.add_alert_message(broadcast_message) response.add_alert_message(broadcast_message)
response.add_merge_request_urls(merge_request_urls) response.add_merge_request_urls(merge_request_urls)
# Neither User nor Project are guaranteed to be returned; an orphaned write deploy # Neither User nor Project are guaranteed to be returned; an orphaned write deploy
...@@ -74,6 +72,24 @@ class PostReceiveService ...@@ -74,6 +72,24 @@ class PostReceiveService
::MergeRequests::GetUrlsService.new(project).execute(params[:changes]) ::MergeRequests::GetUrlsService.new(project).execute(params[:changes])
end end
private
def broadcast_message
banner = nil
if project
scoped_messages = BroadcastMessage.current_banner_messages(project.full_path).select do |message|
message.target_path.present? && message.matches_current_path(project.full_path)
end
banner = scoped_messages.last
end
banner ||= BroadcastMessage.current_banner_messages.last
banner&.message
end
end end
PostReceiveService.prepend_if_ee('EE::PostReceiveService') PostReceiveService.prepend_if_ee('EE::PostReceiveService')
---
title: Allow for return of scoped broadcast messages on shell
merge_request: 46333
author:
type: changed
...@@ -232,6 +232,49 @@ RSpec.describe PostReceiveService do ...@@ -232,6 +232,49 @@ RSpec.describe PostReceiveService do
end end
end end
context "broadcast message has a target_path" do
let!(:older_scoped_message) do
create(:broadcast_message, message: "Old top secret", target_path: "/company/sekrit-project")
end
let!(:latest_scoped_message) do
create(:broadcast_message, message: "Top secret", target_path: "/company/sekrit-project")
end
let!(:unscoped_message) do
create(:broadcast_message, message: "Hi")
end
context "no project path matches" do
it "does not output the scoped broadcast messages" do
expect(subject).not_to include(build_alert_message(older_scoped_message.message))
expect(subject).not_to include(build_alert_message(latest_scoped_message.message))
end
it "does output another message that doesn't have a target_path" do
expect(subject).to include(build_alert_message(unscoped_message.message))
end
end
context "project path matches" do
before do
allow(project).to receive(:full_path).and_return("/company/sekrit-project")
end
it "does output the latest scoped broadcast message" do
expect(subject).to include(build_alert_message(latest_scoped_message.message))
end
it "does not output the older scoped broadcast message" do
expect(subject).not_to include(build_alert_message(older_scoped_message.message))
end
it "does not output another message that doesn't have a target_path" do
expect(subject).not_to include(build_alert_message(unscoped_message.message))
end
end
end
context 'with a redirected data' do context 'with a redirected data' do
it 'returns redirected message on the response' do it 'returns redirected message on the response' do
project_moved = Gitlab::Checks::ProjectMoved.new(project.repository, user, 'http', 'foo/baz') project_moved = Gitlab::Checks::ProjectMoved.new(project.repository, user, 'http', 'foo/baz')
......
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