Commit 019ba282 authored by peterhegman's avatar peterhegman

Refactor member entity properties to use presenter

Refactor `group_sso` and `group_managed_account` entity properties to
use methods on presenter
parent 6f4c63c9
...@@ -5,10 +5,14 @@ module EE ...@@ -5,10 +5,14 @@ module EE
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
def group_sso? def group_sso?
return false unless member.user.present?
member.user.group_sso?(source) member.user.group_sso?(source)
end end
def group_managed_account? def group_managed_account?
return false unless member.user.present?
member.user.group_managed_account? member.user.group_managed_account?
end end
......
...@@ -9,13 +9,9 @@ module EE ...@@ -9,13 +9,9 @@ module EE
can?(current_user, :owner_access, group) && member.user&.using_gitlab_com_seat?(group) can?(current_user, :owner_access, group) && member.user&.using_gitlab_com_seat?(group)
end end
expose :group_sso do |member| expose :group_sso?, as: :group_sso
member.user&.group_sso?(group)
end
expose :group_managed_account do |member| expose :group_managed_account?, as: :group_managed_account
member.user&.group_managed_account?
end
expose :can_override do |member| expose :can_override do |member|
member.can_override? member.can_override?
......
...@@ -12,6 +12,14 @@ RSpec.describe GroupMemberPresenter do ...@@ -12,6 +12,14 @@ RSpec.describe GroupMemberPresenter do
let(:saml_provider) { double(:saml_provider) } let(:saml_provider) { double(:saml_provider) }
let(:group) { double(:group) } let(:group) { double(:group) }
context 'when member does not have a user (invited member)' do
let(:group_member) { build(:group_member, :invited) }
it 'returns `false`' do
expect(presenter.group_sso?).to eq false
end
end
it 'calls through to User#group_sso?' do it 'calls through to User#group_sso?' do
expect(user).to receive(:group_sso?).with(group).and_return(true) expect(user).to receive(:group_sso?).with(group).and_return(true)
...@@ -20,6 +28,14 @@ RSpec.describe GroupMemberPresenter do ...@@ -20,6 +28,14 @@ RSpec.describe GroupMemberPresenter do
end end
describe '#group_managed_account?' do describe '#group_managed_account?' do
context 'when member does not have a user (invited member)' do
let(:group_member) { build(:group_member, :invited) }
it 'returns `false`' do
expect(presenter.group_managed_account?).to eq false
end
end
context 'when user is part of the group managed account' do context 'when user is part of the group managed account' do
before do before do
expect(user).to receive(:group_managed_account?).and_return(true) expect(user).to receive(:group_managed_account?).and_return(true)
......
...@@ -20,13 +20,13 @@ RSpec.describe MemberEntity do ...@@ -20,13 +20,13 @@ RSpec.describe MemberEntity do
end end
it 'correctly exposes `group_sso`' do it 'correctly exposes `group_sso`' do
allow(member.user).to receive(:group_sso?).with(group).and_return(true) allow(member).to receive(:group_sso?).and_return(true)
expect(entity_hash[:group_sso]).to be(true) expect(entity_hash[:group_sso]).to be(true)
end end
it 'correctly exposes `group_managed_account`' do it 'correctly exposes `group_managed_account`' do
allow(member.user).to receive(:group_managed_account?).and_return(true) allow(member).to receive(:group_managed_account?).and_return(true)
expect(entity_hash[:group_managed_account]).to be(true) expect(entity_hash[:group_managed_account]).to be(true)
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