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
> [Introduced][ee-1283] in [GitLab Premium][eep] 10.7.
Navigate to the **Admin** area and go to the **Appearance** page.
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
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)
[eep]: https://about.gitlab.com/pricing/
[ee-4972]: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/4972
......@@ -2,7 +2,17 @@ module EE
module Admin
module AppearancesController
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
footer_message
message_background_color
......
......@@ -14,10 +14,14 @@ module EE
end
def show_header?
return unless ::License.feature_available?(:system_header_footer)
header_message.present?
end
def show_footer?
return unless ::License.feature_available?(:system_header_footer)
footer_message.present?
end
end
......
......@@ -60,6 +60,7 @@ class License < ActiveRecord::Base
external_authorization_service
ci_cd_projects
group_burndown_charts
system_header_footer
].freeze
EEU_FEATURES = EEP_FEATURES + %i[
......@@ -154,6 +155,7 @@ class License < ActiveRecord::Base
object_storage
repository_size_limit
external_authorization_service
system_header_footer
].freeze
validate :valid_license
......
- return unless License.feature_available?(:system_header_footer_form)
- form = local_assigns.fetch(:form)
%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,11 +57,28 @@ describe 'Display system header and footer bar' do
create(:appearance, header_message: header_message)
sign_in(create(:user))
visit root_path
end
it_behaves_like 'system header is configured'
it_behaves_like 'system footer is not configured'
context 'when licensed' do
before do
stub_licensed_features(system_header_footer: true)
visit root_path
end
it_behaves_like 'system header is configured'
it_behaves_like 'system footer is not configured'
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
......@@ -69,11 +86,28 @@ describe 'Display system header and footer bar' do
create(:appearance, footer_message: footer_message)
sign_in(create(:user))
visit root_path
end
it_behaves_like 'system header is not configured'
it_behaves_like 'system footer is configured'
context 'when licensed' do
before do
stub_licensed_features(system_header_footer: true)
visit root_path
end
it_behaves_like 'system header is not configured'
it_behaves_like 'system footer is configured'
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
......@@ -81,11 +115,29 @@ describe 'Display system header and footer bar' do
create(:appearance, header_message: header_message, footer_message: footer_message)
sign_in(create(:user))
visit root_path
end
it_behaves_like 'system header is configured'
it_behaves_like 'system footer is configured'
context 'when licensed' do
before do
stub_licensed_features(system_header_footer: true)
visit root_path
end
it_behaves_like 'system header is configured'
it_behaves_like 'system footer is configured'
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
......@@ -102,34 +154,83 @@ describe 'Display system header and footer bar' do
context 'when only system header is defined' do
before do
create(:appearance, header_message: header_message)
end
visit root_path
context 'when licensed' do
before do
stub_licensed_features(system_header_footer: true)
visit root_path
end
it_behaves_like 'system header is configured'
it_behaves_like 'system footer is not configured'
end
it_behaves_like 'system header is configured'
it_behaves_like 'system footer is not configured'
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
before do
create(:appearance, footer_message: footer_message)
end
visit root_path
context 'when licensed' do
before do
stub_licensed_features(system_header_footer: true)
visit root_path
end
it_behaves_like 'system header is not configured'
it_behaves_like 'system footer is configured'
end
it_behaves_like 'system header is not configured'
it_behaves_like 'system footer is configured'
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
before do
create(:appearance, header_message: header_message, footer_message: footer_message)
end
visit root_path
context 'when licensed' do
before do
stub_licensed_features(system_header_footer: true)
visit root_path
end
it_behaves_like 'system header is configured'
it_behaves_like 'system footer is configured'
end
it_behaves_like 'system header is configured'
it_behaves_like 'system footer is configured'
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
......@@ -14,10 +14,20 @@ describe AppearancesHelper do
end
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"
create(:appearance, header_message: message)
stub_licensed_features(system_header_footer: true)
expect(helper.header_message).to include(message)
end
end
......@@ -31,10 +41,20 @@ describe AppearancesHelper do
end
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"
create(:appearance, footer_message: message)
stub_licensed_features(system_header_footer: true)
expect(helper.footer_message).to include(message)
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