Commit 2026dc0d authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Render canary links based on server-side flag

This fixes the issue where these may be inconsistent with the
canary favicon.

This happens when:

1. The cookie is set but the canary is not serving any requests
2. The cookie is not set but we're forcing traffic to canary on
specific routes
parent 2fc77624
...@@ -160,24 +160,6 @@ function deferredInitialisation() { ...@@ -160,24 +160,6 @@ function deferredInitialisation() {
}); });
loadAwardsHandler(); 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', () => { document.addEventListener('DOMContentLoaded', () => {
......
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
%li.d-md-none %li.d-md-none
= render 'shared/user_dropdown_contributing_link' = render 'shared/user_dropdown_contributing_link'
= render_if_exists 'shared/user_dropdown_instance_review' = render_if_exists 'shared/user_dropdown_instance_review'
- if Gitlab.com? - if Gitlab.com_but_not_canary?
%li.js-canary-link.d-md-none %li.d-md-none
= link_to _("Switch to GitLab Next"), "https://next.gitlab.com/" = link_to _("Switch to GitLab Next"), "https://next.gitlab.com/"
- if current_user_menu?(:sign_out) - if current_user_menu?(:sign_out)
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
- if logo_text.present? - if logo_text.present?
%span.logo-text.d-none.d-lg-block.prepend-left-8 %span.logo-text.d-none.d-lg-block.prepend-left-8
= logo_text = logo_text
- if Gitlab.com? - if Gitlab.com_and_canary?
= link_to 'https://next.gitlab.com', class: 'label-link js-canary-badge canary-badge bg-transparent hidden', target: :_blank do = 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 %span.color-label.has-tooltip.badge.badge-pill.green-badge
= _('Next') = _('Next')
......
...@@ -12,6 +12,6 @@ ...@@ -12,6 +12,6 @@
%li %li
= render 'shared/user_dropdown_contributing_link' = render 'shared/user_dropdown_contributing_link'
= render_if_exists 'shared/user_dropdown_instance_review' = render_if_exists 'shared/user_dropdown_instance_review'
- if Gitlab.com? - if Gitlab.com_but_not_canary?
%li.js-canary-link %li
= link_to _("Switch to GitLab Next"), "https://next.gitlab.com/" = 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 ...@@ -47,6 +47,18 @@ module Gitlab
Gitlab.config.gitlab.url == COM_URL || gl_subdomain? Gitlab.config.gitlab.url == COM_URL || gl_subdomain?
end 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? def self.org?
Gitlab.config.gitlab.url == 'https://dev.gitlab.org' Gitlab.config.gitlab.url == 'https://dev.gitlab.org'
end end
......
...@@ -7,7 +7,7 @@ module Gitlab ...@@ -7,7 +7,7 @@ module Gitlab
image_name = image_name =
if appearance.favicon.exists? if appearance.favicon.exists?
appearance.favicon_path appearance.favicon_path
elsif Gitlab::Utils.to_boolean(ENV['CANARY']) elsif Gitlab.canary?
'favicon-yellow.png' 'favicon-yellow.png'
elsif Rails.env.development? elsif Rails.env.development?
development_favicon development_favicon
......
...@@ -96,6 +96,48 @@ describe Gitlab do ...@@ -96,6 +96,48 @@ describe Gitlab do
end end
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 describe '.dev_env_org_or_com?' do
it 'is true when on .com' do it 'is true when on .com' do
allow(described_class).to receive_messages(com?: true, org?: false) 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