Commit 9e04c966 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch '28801-fix-canary-inconsistency' into 'master'

Render canary links based on server-side flag

See merge request gitlab-org/gitlab!19645
parents 3c8f5a86 2026dc0d
......@@ -160,24 +160,6 @@ function deferredInitialisation() {
});
loadAwardsHandler();
/**
* Toggle Canary Badge
*
* For GitLab.com only, when the user is using canary
* we render a Next badge and hide the option to switch
* to canay
*/
if (Cookies.get('gitlab_canary') && Cookies.get('gitlab_canary') === 'true') {
const canaryBadge = document.querySelector('.js-canary-badge');
const canaryLink = document.querySelector('.js-canary-link');
if (canaryBadge) {
canaryBadge.classList.remove('hidden');
}
if (canaryLink) {
canaryLink.classList.add('hidden');
}
}
}
document.addEventListener('DOMContentLoaded', () => {
......
......@@ -35,8 +35,8 @@
%li.d-md-none
= render 'shared/user_dropdown_contributing_link'
= render_if_exists 'shared/user_dropdown_instance_review'
- if Gitlab.com?
%li.js-canary-link.d-md-none
- if Gitlab.com_but_not_canary?
%li.d-md-none
= link_to _("Switch to GitLab Next"), "https://next.gitlab.com/"
- if current_user_menu?(:sign_out)
......
......@@ -18,8 +18,8 @@
- if logo_text.present?
%span.logo-text.d-none.d-lg-block.prepend-left-8
= logo_text
- if Gitlab.com?
= link_to 'https://next.gitlab.com', class: 'label-link js-canary-badge canary-badge bg-transparent hidden', target: :_blank do
- if Gitlab.com_and_canary?
= link_to 'https://next.gitlab.com', class: 'label-link canary-badge bg-transparent', target: :_blank do
%span.color-label.has-tooltip.badge.badge-pill.green-badge
= _('Next')
......
......@@ -12,6 +12,6 @@
%li
= render 'shared/user_dropdown_contributing_link'
= render_if_exists 'shared/user_dropdown_instance_review'
- if Gitlab.com?
%li.js-canary-link
- if Gitlab.com_but_not_canary?
%li
= link_to _("Switch to GitLab Next"), "https://next.gitlab.com/"
---
title: Fix canary badge and favicon inconsistency
merge_request: 19645
author:
type: fixed
......@@ -47,6 +47,18 @@ module Gitlab
Gitlab.config.gitlab.url == COM_URL || gl_subdomain?
end
def self.canary?
Gitlab::Utils.to_boolean(ENV['CANARY'])
end
def self.com_and_canary?
com? && canary?
end
def self.com_but_not_canary?
com? && !canary?
end
def self.org?
Gitlab.config.gitlab.url == 'https://dev.gitlab.org'
end
......
......@@ -7,7 +7,7 @@ module Gitlab
image_name =
if appearance.favicon.exists?
appearance.favicon_path
elsif Gitlab::Utils.to_boolean(ENV['CANARY'])
elsif Gitlab.canary?
'favicon-yellow.png'
elsif Rails.env.development?
development_favicon
......
......@@ -96,6 +96,48 @@ describe Gitlab do
end
end
describe '.canary?' do
it 'is true when CANARY env var is set to true' do
stub_env('CANARY', '1')
expect(described_class.canary?).to eq true
end
it 'is false when CANARY env var is set to false' do
stub_env('CANARY', '0')
expect(described_class.canary?).to eq false
end
end
describe '.com_and_canary?' do
it 'is true when on .com and canary' do
allow(described_class).to receive_messages(com?: true, canary?: true)
expect(described_class.com_and_canary?).to eq true
end
it 'is false when on .com but not on canary' do
allow(described_class).to receive_messages(com?: true, canary?: false)
expect(described_class.com_and_canary?).to eq false
end
end
describe '.com_but_not_canary?' do
it 'is false when on .com and canary' do
allow(described_class).to receive_messages(com?: true, canary?: true)
expect(described_class.com_but_not_canary?).to eq false
end
it 'is true when on .com but not on canary' do
allow(described_class).to receive_messages(com?: true, canary?: false)
expect(described_class.com_but_not_canary?).to eq true
end
end
describe '.dev_env_org_or_com?' do
it 'is true when on .com' do
allow(described_class).to receive_messages(com?: true, org?: false)
......
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