diff --git a/app/helpers/admin/identities_helper.rb b/app/helpers/admin/identities_helper.rb index 8557f322bff577731a14d5e632b54ab5d697c4b5..48e01840394e756ae98c41985ef653fa37a04ed2 100644 --- a/app/helpers/admin/identities_helper.rb +++ b/app/helpers/admin/identities_helper.rb @@ -22,6 +22,14 @@ def saml_group_cell_testid(identity) def saml_group_link(identity) '-' end + + def identity_cells_to_render?(identities, _user) + identities.present? + end + + def scim_identities_collection(_user) + [] + end end end diff --git a/app/views/admin/identities/index.html.haml b/app/views/admin/identities/index.html.haml index 99d5e2a93c4c855803039be524c3a493f3656a2c..1bb149699398d5ed6f42650aba6bd22f4b3a4d32 100644 --- a/app/views/admin/identities/index.html.haml +++ b/app/views/admin/identities/index.html.haml @@ -11,8 +11,10 @@ %th{ class: 'gl-border-t-0!' }= _('Group') %th{ class: 'gl-border-t-0!' }= _('Identifier') %th{ class: 'gl-border-t-0!' }= _('Actions') - = render @identities - - if @identities.blank? + - if identity_cells_to_render?(@identities, @user) + = render_if_exists partial: 'admin/identities/scim_identity', collection: scim_identities_collection(@user) + = render @identities + - else %tbody %tr %td{ colspan: '5' } diff --git a/ee/app/helpers/ee/admin/identities_helper.rb b/ee/app/helpers/ee/admin/identities_helper.rb index 416d4faf81ae83dc42eebba714a646226d126151..425a254cf4ec10d191fb28814f49aaba79f8d24e 100644 --- a/ee/app/helpers/ee/admin/identities_helper.rb +++ b/ee/app/helpers/ee/admin/identities_helper.rb @@ -31,6 +31,15 @@ def saml_group_link(identity) link_to identity.saml_provider.group.path, identity.saml_provider.group end + + def identity_cells_to_render?(identities, user) + super || user.scim_identities.present? + end + + override :scim_identities_collection + def scim_identities_collection(user) + user.scim_identities + end end end end diff --git a/ee/app/views/admin/identities/_scim_identity.html.haml b/ee/app/views/admin/identities/_scim_identity.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..5f969e04b4246c2a79dd6b03a5d4e3538c6e2136 --- /dev/null +++ b/ee/app/views/admin/identities/_scim_identity.html.haml @@ -0,0 +1,10 @@ +%tr + %td + SCIM + %td{ data: { testid: 'provider_id_blank' } } + = '-' + %td + = link_to scim_identity.group.path, scim_identity.group + %td + = scim_identity.extern_uid + %td diff --git a/ee/spec/helpers/ee/admin/identities_helper_spec.rb b/ee/spec/helpers/ee/admin/identities_helper_spec.rb index 1a692c4193752799a8afad07a32b2b9f4840b987..27c2809d35bcd3caaab5deefccc9a4c9206f8145 100644 --- a/ee/spec/helpers/ee/admin/identities_helper_spec.rb +++ b/ee/spec/helpers/ee/admin/identities_helper_spec.rb @@ -3,18 +3,23 @@ require 'spec_helper' RSpec.describe Admin::IdentitiesHelper do - let_it_be(:user) { create(:user) } let_it_be(:group) { create(:group) } let_it_be(:saml_provider) { create(:saml_provider, group: group) } let_it_be(:saml_identity) do - create(:identity, provider: 'group_saml', saml_provider_id: saml_provider.id, user: user, - extern_uid: 'saml-uid') + create(:identity, provider: 'group_saml', saml_provider_id: saml_provider.id, extern_uid: 'saml-uid') end let_it_be(:ldap_identity) do - create(:identity, user: user, extern_uid: 'without-saml-uid') + create(:identity, extern_uid: 'without-saml-uid') end + let_it_be(:user_without_scim_identities) { create(:user) } + let_it_be(:scim_identity) do + create(:scim_identity, group: group, extern_uid: 'scim-uid') + end + + let_it_be(:user_with_scim_identities) { scim_identity.user } + describe '#provider_id_cell_testid' do context 'without SAML provider ID' do it 'shows blank provider id for data-testid' do @@ -70,4 +75,24 @@ end end end + + describe '#identity_cells_to_render?' do + context 'without SCIM identies' do + it 'returns false' do + expect(helper.identity_cells_to_render?([], user_without_scim_identities)).to eq false + end + end + + context 'with SCIM identities' do + it 'returns true' do + expect(helper.identity_cells_to_render?([], user_with_scim_identities)).to eq true + end + end + end + + describe '#scim_identities_collection' do + it 'returns SCIM identities' do + expect(helper.scim_identities_collection(user_with_scim_identities)).to match_array [scim_identity] + end + end end diff --git a/ee/spec/views/admin/identities/index.html.haml_spec.rb b/ee/spec/views/admin/identities/index.html.haml_spec.rb index 0ec25e48462992371bf0c6c176f0eeebbc20ef3a..499b58d7a12272258b3042bf2abf6c5869ef6ac6 100644 --- a/ee/spec/views/admin/identities/index.html.haml_spec.rb +++ b/ee/spec/views/admin/identities/index.html.haml_spec.rb @@ -7,7 +7,7 @@ let_it_be(:group) { create(:group) } let_it_be(:saml_provider) { create(:saml_provider, group: group) } - let_it_be(:saml_user) { create(:user) } + let_it_be(:saml_user, refind: true) { create(:user) } let_it_be(:saml_identity) do create(:identity, provider: 'group_saml', saml_provider_id: saml_provider.id, user: saml_user, extern_uid: 'saml-uid') @@ -18,9 +18,55 @@ view.lookup_context.prefixes = ['admin/identities'] end + context 'without SCIM or other identities' do + before do + assign(:identities, []) + end + + it 'shows information text' do + render + + expect(rendered).to include('<td colspan="5">').exactly(1) + expect(rendered).to include(_('This user has no identities')) + end + end + + context 'with SCIM identities' do + before_all do + create(:scim_identity, group: group, extern_uid: 'scim-uid', user: saml_user) + assign(:identities, []) + end + + it 'shows exactly 5 columns' do + render + + expect(rendered).to include('</td>').exactly(5) + end + + it 'shows identity without provider ID' do + render + + # Provider + expect(rendered).to include('SCIM') + # Provider ID + expect(rendered).to include('data-testid="provider_id_blank"') + # Group + expect(rendered).to include("<a href=\"/#{group.path}\">#{group.path}</a>") + # Identifier + expect(rendered).to include('scim-uid') + end + + it 'shows no edit or delete identity buttons' do + render + + expect(rendered).not_to include("aria-label=\"#{_('Edit')}\"") + expect(rendered).not_to include("aria-label=\"#{_('Delete identity')}\"") + end + end + context 'with SAML identities' do before do - assign(:identities, saml_user.identities) + assign(:identities, saml_identity) end it 'shows exactly 5 columns' do diff --git a/spec/helpers/admin/identities_helper_spec.rb b/spec/helpers/admin/identities_helper_spec.rb index f8e56e4f32d853f4880511569b1a3595219a7d81..9a7fdd3aa6931d70cced63c0a6e3e59a7fb8fb64 100644 --- a/spec/helpers/admin/identities_helper_spec.rb +++ b/spec/helpers/admin/identities_helper_spec.rb @@ -35,4 +35,24 @@ expect(helper.saml_group_link(identity)).to eq '-' end end + + describe '#identity_cells_to_render?' do + context 'without identities' do + it 'returns false' do + expect(helper.identity_cells_to_render?([], user)).to eq false + end + end + + context 'with identities' do + it 'returns true' do + expect(helper.identity_cells_to_render?(identity, user)).to eq true + end + end + end + + describe '#scim_identities_collection' do + it 'returns empty array' do + expect(helper.scim_identities_collection(user)).to eq [] + end + end end