Commit 1bbfbdaa authored by peterhegman's avatar peterhegman

Move feature flag into `gitlab_employee?` method

`gitlab_employee?` and `:gitlab_employee_badge` were being used
together in multiple places. This combines them into one source of
truth. It also allows us to clean up the HAML templates.
parent 45381caa
...@@ -1696,7 +1696,7 @@ class User < ApplicationRecord ...@@ -1696,7 +1696,7 @@ class User < ApplicationRecord
def gitlab_employee? def gitlab_employee?
strong_memoize(:gitlab_employee) do strong_memoize(:gitlab_employee) do
if Gitlab.com? if Feature.enabled?(:gitlab_employee_badge) && Gitlab.com?
Mail::Address.new(email).domain == "gitlab.com" && confirmed? Mail::Address.new(email).domain == "gitlab.com" && confirmed?
else else
false false
...@@ -1713,6 +1713,10 @@ class User < ApplicationRecord ...@@ -1713,6 +1713,10 @@ class User < ApplicationRecord
!confirmed? && !confirmation_period_valid? !confirmed? && !confirmation_period_valid?
end end
def organization
gitlab_employee? ? 'GitLab' : super
end
protected protected
# override, from Devise::Validatable # override, from Devise::Validatable
......
# frozen_string_literal: true # frozen_string_literal: true
class NoteUserEntity < UserEntity class NoteUserEntity < UserEntity
expose :gitlab_employee?, as: :is_gitlab_employee, if: ->(user, options) { ::Feature.enabled?(:gitlab_employee_badge) && user.gitlab_employee? } expose :gitlab_employee?, as: :is_gitlab_employee, if: ->(user, options) { user.gitlab_employee? }
unexpose :web_url unexpose :web_url
end end
...@@ -101,10 +101,7 @@ ...@@ -101,10 +101,7 @@
- else - else
= f.text_field :location, label: s_('Profiles|Location'), class: 'input-lg', placeholder: s_("Profiles|City, country") = f.text_field :location, label: s_('Profiles|Location'), class: 'input-lg', placeholder: s_("Profiles|City, country")
= f.text_field :job_title, class: 'input-md' = f.text_field :job_title, class: 'input-md'
- if Feature.enabled?(:gitlab_employee_badge) && @user.gitlab_employee? = f.text_field :organization, readonly: @user.gitlab_employee?, label: s_('Profiles|Organization'), class: 'input-md', help: s_("Profiles|Who you represent or work for")
= f.text_field :organization, readonly: true, value: 'GitLab', label: s_('Profiles|Organization'), class: 'input-md', help: s_("Profiles|Who you represent or work for")
- else
= f.text_field :organization, label: s_('Profiles|Organization'), class: 'input-md', help: s_("Profiles|Who you represent or work for")
= f.text_area :bio, label: s_('Profiles|Bio'), rows: 4, maxlength: 250, help: s_("Profiles|Tell us about yourself in fewer than 250 characters") = f.text_area :bio, label: s_('Profiles|Bio'), rows: 4, maxlength: 250, help: s_("Profiles|Tell us about yourself in fewer than 250 characters")
%hr %hr
%h5= s_("Private profile") %h5= s_("Private profile")
......
...@@ -4406,6 +4406,16 @@ describe User, :do_not_mock_admin_mode do ...@@ -4406,6 +4406,16 @@ describe User, :do_not_mock_admin_mode do
it { is_expected.to be false } it { is_expected.to be false }
end end
context 'when `:gitlab_employee_badge` feature flag is disabled' do
let(:user) { build(:user, email: 'test@gitlab.com') }
before do
stub_feature_flags(gitlab_employee_badge: false)
end
it { is_expected.to be false }
end
end end
describe '#current_highest_access_level' do describe '#current_highest_access_level' do
...@@ -4428,6 +4438,27 @@ describe User, :do_not_mock_admin_mode do ...@@ -4428,6 +4438,27 @@ describe User, :do_not_mock_admin_mode do
end end
end end
describe '#organization' do
using RSpec::Parameterized::TableSyntax
let(:user) { build(:user, organization: 'ACME') }
subject { user.organization }
where(:gitlab_employee?, :expected_result) do
true | 'GitLab'
false | 'ACME'
end
with_them do
before do
allow(user).to receive(:gitlab_employee?).and_return(gitlab_employee?)
end
it { is_expected.to eql(expected_result) }
end
end
context 'when after_commit :update_highest_role' do context 'when after_commit :update_highest_role' do
describe 'create user' do describe 'create user' do
it 'initializes a new Members::UpdateHighestRoleService object' do it 'initializes a new Members::UpdateHighestRoleService object' do
......
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