Commit e20c8612 authored by Douwe Maan's avatar Douwe Maan

Merge branch '6160-add-premium-license-check-for-system-messages' into 'master'

Add Premium license checks for system messages

Closes #6160

See merge request gitlab-org/gitlab-ee!6460
parents d784bad9 b1d05d74
# Adding a system message to every page # Adding a system message to every page
> [Introduced][ee-1283] in [GitLab Premium][eep] 10.7.
Navigate to the **Admin** area and go to the **Appearance** page. Navigate to the **Admin** area and go to the **Appearance** page.
Under **System header and footer** insert your header message and/or footer message. Under **System header and footer** insert your header message and/or footer message.
...@@ -14,3 +16,6 @@ After saving, all GitLab pages will contain the custom system header and/or foot ...@@ -14,3 +16,6 @@ After saving, all GitLab pages will contain the custom system header and/or foot
The GitLab sign in page will also show the header and the footer messages: The GitLab sign in page will also show the header and the footer messages:
![sign_up_custom_header_and_footer](system_header_and_footer_messages/sign_up_custom_header_and_footer.png) ![sign_up_custom_header_and_footer](system_header_and_footer_messages/sign_up_custom_header_and_footer.png)
[eep]: https://about.gitlab.com/pricing/
[ee-4972]: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/4972
...@@ -2,7 +2,17 @@ module EE ...@@ -2,7 +2,17 @@ module EE
module Admin module Admin
module AppearancesController module AppearancesController
def allowed_appearance_params def allowed_appearance_params
super + %i[ if License.feature_available?(:system_header_footer)
super + header_footer_params
else
super
end
end
private
def header_footer_params
%i[
header_message header_message
footer_message footer_message
message_background_color message_background_color
......
...@@ -14,10 +14,14 @@ module EE ...@@ -14,10 +14,14 @@ module EE
end end
def show_header? def show_header?
return unless ::License.feature_available?(:system_header_footer)
header_message.present? header_message.present?
end end
def show_footer? def show_footer?
return unless ::License.feature_available?(:system_header_footer)
footer_message.present? footer_message.present?
end end
end end
......
...@@ -60,6 +60,7 @@ class License < ActiveRecord::Base ...@@ -60,6 +60,7 @@ class License < ActiveRecord::Base
external_authorization_service external_authorization_service
ci_cd_projects ci_cd_projects
group_burndown_charts group_burndown_charts
system_header_footer
].freeze ].freeze
EEU_FEATURES = EEP_FEATURES + %i[ EEU_FEATURES = EEP_FEATURES + %i[
...@@ -154,6 +155,7 @@ class License < ActiveRecord::Base ...@@ -154,6 +155,7 @@ class License < ActiveRecord::Base
object_storage object_storage
repository_size_limit repository_size_limit
external_authorization_service external_authorization_service
system_header_footer
].freeze ].freeze
validate :valid_license validate :valid_license
......
- return unless License.feature_available?(:system_header_footer_form)
- form = local_assigns.fetch(:form) - form = local_assigns.fetch(:form)
%fieldset.system_header_footer %fieldset.system_header_footer
......
---
title: Add Premium license checks for system messages
merge_request: 6460
author:
type: fixed
require 'spec_helper'
describe Admin::AppearancesController do
let(:admin) { create(:admin) }
let(:header_message) { "Header message" }
let(:footer_message) { "Footer" }
describe 'POST #create' do
let(:create_params) do
{
title: "Foo",
description: "Bar",
header_message: header_message,
footer_message: footer_message
}
end
before do
sign_in(admin)
end
context 'when system messages feature is available' do
it 'creates appearance with footer and header message' do
stub_licensed_features(system_header_footer: true)
post :create, appearance: create_params
expect(Appearance.current).to have_attributes(
header_message: header_message,
footer_message: footer_message
)
end
end
context 'when system messages feature is not available' do
it 'does not create appearance with footer and header message' do
stub_licensed_features(system_header_footer: false)
post :create, appearance: create_params
expect(Appearance.current).to have_attributes(
header_message: nil,
footer_message: nil
)
end
end
end
describe 'PUT #update' do
let(:update_params) do
{
header_message: header_message,
footer_message: footer_message
}
end
before do
create(:appearance)
sign_in(admin)
end
context 'when system messages feature is available' do
it 'updates appearance with footer and header message' do
stub_licensed_features(system_header_footer: true)
put :update, appearance: update_params
expect(Appearance.current).to have_attributes(
header_message: header_message,
footer_message: footer_message
)
end
end
context 'when system messages feature is not available' do
it 'does not update appearance with footer and header message' do
stub_licensed_features(system_header_footer: false)
post :create, appearance: update_params
expect(Appearance.current).to have_attributes(
header_message: nil,
footer_message: nil
)
end
end
end
end
...@@ -57,6 +57,12 @@ describe 'Display system header and footer bar' do ...@@ -57,6 +57,12 @@ describe 'Display system header and footer bar' do
create(:appearance, header_message: header_message) create(:appearance, header_message: header_message)
sign_in(create(:user)) sign_in(create(:user))
end
context 'when licensed' do
before do
stub_licensed_features(system_header_footer: true)
visit root_path visit root_path
end end
...@@ -64,11 +70,28 @@ describe 'Display system header and footer bar' do ...@@ -64,11 +70,28 @@ describe 'Display system header and footer bar' do
it_behaves_like 'system footer is not configured' it_behaves_like 'system footer is not configured'
end end
context 'when unlicensed' do
before do
stub_licensed_features(system_header_footer: false)
visit root_path
end
it_behaves_like 'system header is not configured'
end
end
context 'when only system footer is defined' do context 'when only system footer is defined' do
before do before do
create(:appearance, footer_message: footer_message) create(:appearance, footer_message: footer_message)
sign_in(create(:user)) sign_in(create(:user))
end
context 'when licensed' do
before do
stub_licensed_features(system_header_footer: true)
visit root_path visit root_path
end end
...@@ -76,17 +99,46 @@ describe 'Display system header and footer bar' do ...@@ -76,17 +99,46 @@ describe 'Display system header and footer bar' do
it_behaves_like 'system footer is configured' it_behaves_like 'system footer is configured'
end end
context 'when unlicensed' do
before do
stub_licensed_features(system_header_footer: false)
visit root_path
end
it_behaves_like 'system footer is not configured'
end
end
context 'when system header and footer are defined' do context 'when system header and footer are defined' do
before do before do
create(:appearance, header_message: header_message, footer_message: footer_message) create(:appearance, header_message: header_message, footer_message: footer_message)
sign_in(create(:user)) sign_in(create(:user))
end
context 'when licensed' do
before do
stub_licensed_features(system_header_footer: true)
visit root_path visit root_path
end end
it_behaves_like 'system header is configured' it_behaves_like 'system header is configured'
it_behaves_like 'system footer is configured' it_behaves_like 'system footer is configured'
end end
context 'when unlicensed' do
before do
stub_licensed_features(system_header_footer: false)
visit root_path
end
it_behaves_like 'system header is not configured'
it_behaves_like 'system footer is not configured'
end
end
end end
context 'when not authenticated' do context 'when not authenticated' do
...@@ -102,6 +154,11 @@ describe 'Display system header and footer bar' do ...@@ -102,6 +154,11 @@ describe 'Display system header and footer bar' do
context 'when only system header is defined' do context 'when only system header is defined' do
before do before do
create(:appearance, header_message: header_message) create(:appearance, header_message: header_message)
end
context 'when licensed' do
before do
stub_licensed_features(system_header_footer: true)
visit root_path visit root_path
end end
...@@ -110,9 +167,25 @@ describe 'Display system header and footer bar' do ...@@ -110,9 +167,25 @@ describe 'Display system header and footer bar' do
it_behaves_like 'system footer is not configured' it_behaves_like 'system footer is not configured'
end end
context 'when unlicensed' do
before do
stub_licensed_features(system_header_footer: false)
visit root_path
end
it_behaves_like 'system header is not configured'
end
end
context 'when only system footer is defined' do context 'when only system footer is defined' do
before do before do
create(:appearance, footer_message: footer_message) create(:appearance, footer_message: footer_message)
end
context 'when licensed' do
before do
stub_licensed_features(system_header_footer: true)
visit root_path visit root_path
end end
...@@ -121,9 +194,25 @@ describe 'Display system header and footer bar' do ...@@ -121,9 +194,25 @@ describe 'Display system header and footer bar' do
it_behaves_like 'system footer is configured' it_behaves_like 'system footer is configured'
end end
context 'when unlicensed' do
before do
stub_licensed_features(system_header_footer: false)
visit root_path
end
it_behaves_like 'system footer is not configured'
end
end
context 'when system header and footer are defined' do context 'when system header and footer are defined' do
before do before do
create(:appearance, header_message: header_message, footer_message: footer_message) create(:appearance, header_message: header_message, footer_message: footer_message)
end
context 'when licensed' do
before do
stub_licensed_features(system_header_footer: true)
visit root_path visit root_path
end end
...@@ -131,5 +220,17 @@ describe 'Display system header and footer bar' do ...@@ -131,5 +220,17 @@ describe 'Display system header and footer bar' do
it_behaves_like 'system header is configured' it_behaves_like 'system header is configured'
it_behaves_like 'system footer is configured' it_behaves_like 'system footer is configured'
end end
context 'when unlicensed' do
before do
stub_licensed_features(system_header_footer: false)
visit root_path
end
it_behaves_like 'system header is not configured'
it_behaves_like 'system footer is not configured'
end
end
end end
end end
...@@ -14,10 +14,20 @@ describe AppearancesHelper do ...@@ -14,10 +14,20 @@ describe AppearancesHelper do
end end
context 'when header message is set' do context 'when header message is set' do
it 'includes current message' do it 'returns nil when unlicensed' do
create(:appearance, header_message: "Foo bar")
stub_licensed_features(system_header_footer: false)
expect(helper.header_message).to be_nil
end
it 'includes current message when licensed' do
message = "Foo bar" message = "Foo bar"
create(:appearance, header_message: message) create(:appearance, header_message: message)
stub_licensed_features(system_header_footer: true)
expect(helper.header_message).to include(message) expect(helper.header_message).to include(message)
end end
end end
...@@ -31,10 +41,20 @@ describe AppearancesHelper do ...@@ -31,10 +41,20 @@ describe AppearancesHelper do
end end
context 'when footer message is set' do context 'when footer message is set' do
it 'includes current message' do it 'returns nil when unlicensed' do
create(:appearance, footer_message: "Foo bar")
stub_licensed_features(system_header_footer: false)
expect(helper.footer_message).to be_nil
end
it 'includes current message when licensed' do
message = "Foo bar" message = "Foo bar"
create(:appearance, footer_message: message) create(:appearance, footer_message: message)
stub_licensed_features(system_header_footer: true)
expect(helper.footer_message).to include(message) expect(helper.footer_message).to include(message)
end end
end end
......
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