Commit 0e4be207 authored by Michael Kozono's avatar Michael Kozono

Merge branch...

Merge branch '207120-the-api-for-group-members-returns-true-for-is_using_seat-even-when-user-is-not' into 'master'

API for Namespace members has correct boolean for user using seat

Closes #207120

See merge request gitlab-org/gitlab!25988
parents 777410a8 5aadf831
...@@ -33,5 +33,16 @@ module EE ...@@ -33,5 +33,16 @@ module EE
errors.add(:user, 'is not linked to a SAML account') errors.add(:user, 'is not linked to a SAML account')
end end
end end
# The method is exposed in the API as is_using_seat
# in ee/lib/ee/api/entities.rb
#
# rubocop: disable Naming/PredicateName
def is_using_seat
return user.using_gitlab_com_seat?(source) if ::Gitlab.com?
user.using_license_seat?
end
# rubocop: enable Naming/PredicateName
end end
end end
...@@ -250,15 +250,10 @@ module EE ...@@ -250,15 +250,10 @@ module EE
end end
def using_license_seat? def using_license_seat?
return false unless active? active? &&
return false if internal? !internal? &&
return false unless License.current has_current_license? &&
paid_in_current_license?
if License.current.exclude_guests_from_active_count?
highest_role > ::Gitlab::Access::GUEST
else
true
end
end end
def using_gitlab_com_seat?(namespace) def using_gitlab_com_seat?(namespace)
...@@ -353,5 +348,11 @@ module EE ...@@ -353,5 +348,11 @@ module EE
reporter_developer_maintainer_owned_groups.select(select).where(parent_id: nil) reporter_developer_maintainer_owned_groups.select(select).where(parent_id: nil)
]).to_sql ]).to_sql
end end
def paid_in_current_license?
return true unless License.current.exclude_guests_from_active_count?
highest_role > ::Gitlab::Access::GUEST
end
end end
end end
---
title: API for Namespace members has correct boolean if user using paid seat
merge_request: 25988
author:
type: fixed
...@@ -93,9 +93,7 @@ module EE ...@@ -93,9 +93,7 @@ module EE
expose :group_saml_identity, expose :group_saml_identity,
using: ::API::Entities::Identity, using: ::API::Entities::Identity,
if: -> (member, options) { Ability.allowed?(options[:current_user], :read_group_saml_identity, member.source) } if: -> (member, options) { Ability.allowed?(options[:current_user], :read_group_saml_identity, member.source) }
expose :is_using_seat, if: -> (member, options) { options[:show_seat_info] } do |member, _options| expose :is_using_seat, if: -> (_, options) { options[:show_seat_info] }
!!member.user&.using_license_seat?
end
end end
end end
......
...@@ -13,4 +13,34 @@ describe Member, type: :model do ...@@ -13,4 +13,34 @@ describe Member, type: :model do
.to be_instance_of(::EE::NullNotificationService) .to be_instance_of(::EE::NullNotificationService)
end end
end end
describe '#is_using_seat', :aggregate_failures do
let(:user) { build :user }
let(:group) { create :group }
let(:member) { build :group_member, group: group, user: user }
context 'when hosted on GL.com' do
before do
allow(Gitlab).to receive(:com?).and_return true
end
it 'calls users check for using the gitlab_com seat method' do
expect(user).to receive(:using_gitlab_com_seat?).with(group).once.and_return true
expect(user).not_to receive(:using_license_seat?)
expect(member.is_using_seat).to be_truthy
end
end
context 'when not hosted on GL.com' do
before do
allow(Gitlab).to receive(:com?).and_return false
end
it 'calls users check for using the License seat method' do
expect(user).to receive(:using_license_seat?).with(no_args).and_return true
expect(user).not_to receive(:using_gitlab_com_seat?)
expect(member.is_using_seat).to be_truthy
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