Commit f2a52a2d authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '207118-readonly-organization-field-for-gitlab-employees' into 'master'

Change organization field to `readonly` for GitLab employees

See merge request gitlab-org/gitlab!28151
parents 35326d84 fafd8f48
...@@ -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,7 +101,7 @@ ...@@ -101,7 +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'
= f.text_field :organization, label: s_('Profiles|Organization'), class: 'input-md', help: s_("Profiles|Who you represent or work for") = 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_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
......
...@@ -19,4 +19,48 @@ describe 'profiles/show' do ...@@ -19,4 +19,48 @@ describe 'profiles/show' do
expect(rendered).to have_field('user_id', with: user.id) expect(rendered).to have_field('user_id', with: user.id)
end end
end end
context 'gitlab.com organization field' do
before do
allow(Gitlab).to receive(:com?).and_return(true)
end
context 'when `:gitlab_employee_badge` feature flag is enabled' do
context 'and when user has an `@gitlab.com` email address' do
let(:user) { create(:user, email: 'test@gitlab.com') }
it 'displays the organization field as `readonly` with a `value` of `GitLab`' do
render
expect(rendered).to have_selector('#user_organization[readonly][value="GitLab"]')
end
end
context 'and when a user does not have an `@gitlab.com` email' do
let(:user) { create(:user, email: 'test@example.com') }
it 'displays an editable organization field' do
render
expect(rendered).to have_selector('#user_organization:not([readonly]):not([value="GitLab"])')
end
end
end
context 'when `:gitlab_employee_badge` feature flag is disabled' do
before do
stub_feature_flags(gitlab_employee_badge: false)
end
context 'and when a user has an `@gitlab.com` email' do
let(:user) { create(:user, email: 'test@gitlab.com') }
it 'displays an editable organization field' do
render
expect(rendered).to have_selector('#user_organization:not([readonly]):not([value="GitLab"])')
end
end
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