Commit c840c099 authored by Dmitry Gruzd's avatar Dmitry Gruzd

Merge branch '2374-fix-gitlab-subscription-number-users' into 'master'

Add guest scope to group_member

See merge request gitlab-org/gitlab!57839
parents 1166c2b8 b9b4c986
...@@ -73,6 +73,10 @@ module LoadedInGroupList ...@@ -73,6 +73,10 @@ module LoadedInGroupList
def member_count def member_count
@member_count ||= try(:preloaded_member_count) || members.count @member_count ||= try(:preloaded_member_count) || members.count
end end
def guest_count
@guest_count ||= members.guests.count
end
end end
LoadedInGroupList::ClassMethods.prepend_if_ee('EE::LoadedInGroupList::ClassMethods') LoadedInGroupList::ClassMethods.prepend_if_ee('EE::LoadedInGroupList::ClassMethods')
...@@ -69,7 +69,8 @@ module SubscriptionsHelper ...@@ -69,7 +69,8 @@ module SubscriptionsHelper
{ {
id: namespace.id, id: namespace.id,
name: namespace.name, name: namespace.name,
users: namespace.member_count users: namespace.member_count,
guests: namespace.guest_count
} }
end end
end end
......
...@@ -22,6 +22,7 @@ module EE ...@@ -22,6 +22,7 @@ module EE
end end
scope :reporters, -> { where(access_level: ::Gitlab::Access::REPORTER) } scope :reporters, -> { where(access_level: ::Gitlab::Access::REPORTER) }
scope :guests, -> { where(access_level: ::Gitlab::Access::GUEST) }
scope :non_owners, -> { where("members.access_level < ?", ::Gitlab::Access::OWNER) } scope :non_owners, -> { where("members.access_level < ?", ::Gitlab::Access::OWNER) }
scope :by_user_id, ->(user_id) { where(user_id: user_id) } scope :by_user_id, ->(user_id) { where(user_id: user_id) }
end end
......
...@@ -38,12 +38,14 @@ RSpec.describe SubscriptionsHelper do ...@@ -38,12 +38,14 @@ RSpec.describe SubscriptionsHelper do
describe '#subscription_data' do describe '#subscription_data' do
let_it_be(:user) { create(:user, setup_for_company: nil, name: 'First Last') } let_it_be(:user) { create(:user, setup_for_company: nil, name: 'First Last') }
let_it_be(:user2) { create(:user) }
let_it_be(:group) { create(:group, name: 'My Namespace') } let_it_be(:group) { create(:group, name: 'My Namespace') }
before do before do
allow(helper).to receive(:params).and_return(plan_id: 'bronze_id', namespace_id: group.id.to_s) allow(helper).to receive(:params).and_return(plan_id: 'bronze_id', namespace_id: group.id.to_s)
allow(helper).to receive(:current_user).and_return(user) allow(helper).to receive(:current_user).and_return(user)
group.add_owner(user) group.add_owner(user)
group.add_guest(user2)
end end
subject { helper.subscription_data([group]) } subject { helper.subscription_data([group]) }
...@@ -54,7 +56,7 @@ RSpec.describe SubscriptionsHelper do ...@@ -54,7 +56,7 @@ RSpec.describe SubscriptionsHelper do
it { is_expected.to include(ci_minutes_plans: '[{"name":"1000 CI minutes pack","code":"ci_minutes","active":true,"deprecated":false,"free":null,"price_per_month":0.8333333333333334,"price_per_year":10,"features":null,"about_page_href":null,"hide_deprecated_card":false}]') } it { is_expected.to include(ci_minutes_plans: '[{"name":"1000 CI minutes pack","code":"ci_minutes","active":true,"deprecated":false,"free":null,"price_per_month":0.8333333333333334,"price_per_year":10,"features":null,"about_page_href":null,"hide_deprecated_card":false}]') }
it { is_expected.to include(plan_id: 'bronze_id') } it { is_expected.to include(plan_id: 'bronze_id') }
it { is_expected.to include(namespace_id: group.id.to_s) } it { is_expected.to include(namespace_id: group.id.to_s) }
it { is_expected.to include(group_data: %Q{[{"id":#{group.id},"name":"My Namespace","users":1}]}) } it { is_expected.to include(group_data: %Q{[{"id":#{group.id},"name":"My Namespace","users":2,"guests":1}]}) }
describe 'new_user' do describe 'new_user' do
where(:referer, :expected_result) do where(:referer, :expected_result) do
......
...@@ -181,14 +181,22 @@ RSpec.describe GroupMember do ...@@ -181,14 +181,22 @@ RSpec.describe GroupMember do
end end
describe 'scopes' do describe 'scopes' do
let_it_be(:group) { create(:group) }
let_it_be(:member1) { create(:group_member, group: group) }
let_it_be(:member2) { create(:group_member, group: group) }
let_it_be(:member3) { create(:group_member) }
let_it_be(:guest1) { create(:group_member, :guest) }
let_it_be(:guest2) { create(:group_member, :guest, group: group) }
describe '.by_group_ids' do describe '.by_group_ids' do
it 'returns only members from selected groups' do it 'returns only members from selected groups' do
group = create(:group) expect(described_class.by_group_ids([group.id])).to contain_exactly(member1, member2, guest2)
member1 = create(:group_member, group: group) end
member2 = create(:group_member, group: group) end
create(:group_member)
expect(described_class.by_group_ids([group.id])).to match_array([member1, member2]) describe '.guests' do
it 'returns only guests members' do
expect(described_class.guests).to contain_exactly(guest1, guest2)
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