2110247f83
In the previous setup the GroupsFinder class had two distinct tasks: 1. Finding the projects user A could see 2. Finding the projects of user A that user B could see Task two was actually handled outside of the GroupsFinder (in the UsersController) by restricting the returned list of groups to those the viewed user was a member of. Moving all this logic into a single finder proved to be far too complex and confusing, hence there are now two finders: * GroupsFinder: for finding groups a user can see * JoinedGroupsFinder: for finding groups that user A is a member of, restricted to either public groups or groups user B can also see.
49 lines
1.4 KiB
Ruby
49 lines
1.4 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe JoinedGroupsFinder do
|
|
describe '#execute' do
|
|
let(:source_user) { create(:user) }
|
|
let(:current_user) { create(:user) }
|
|
|
|
let(:group1) { create(:group) }
|
|
let(:group2) { create(:group) }
|
|
let(:group3) { create(:group) }
|
|
let(:group4) { create(:group, public: true) }
|
|
|
|
let!(:public_project) { create(:project, :public, group: group1) }
|
|
let!(:internal_project) { create(:project, :internal, group: group2) }
|
|
let!(:private_project) { create(:project, :private, group: group3) }
|
|
|
|
let(:finder) { described_class.new(source_user) }
|
|
|
|
before do
|
|
[group1, group2, group3, group4].each do |group|
|
|
group.add_user(source_user, Gitlab::Access::MASTER)
|
|
end
|
|
end
|
|
|
|
describe 'with a current user' do
|
|
describe 'when the current user has access to the projects of the source user' do
|
|
before do
|
|
private_project.team.add_user(current_user, Gitlab::Access::DEVELOPER)
|
|
end
|
|
|
|
subject { finder.execute(current_user) }
|
|
|
|
it { is_expected.to eq([group4, group3, group2, group1]) }
|
|
end
|
|
|
|
describe 'when the current user does not have access to the projects of the source user' do
|
|
subject { finder.execute(current_user) }
|
|
|
|
it { is_expected.to eq([group4, group2, group1]) }
|
|
end
|
|
end
|
|
|
|
describe 'without a current user' do
|
|
subject { finder.execute }
|
|
|
|
it { is_expected.to eq([group4, group1]) }
|
|
end
|
|
end
|
|
end
|