2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Projects::GroupLinks::CreateService, '#execute' do
|
2020-06-23 00:09:42 +05:30
|
|
|
let_it_be(:user) { create :user }
|
|
|
|
let_it_be(:group) { create :group }
|
|
|
|
let_it_be(:project) { create :project }
|
2020-08-18 19:51:02 +05:30
|
|
|
let(:group_access) { Gitlab::Access::DEVELOPER }
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:opts) do
|
|
|
|
{
|
2020-08-18 19:51:02 +05:30
|
|
|
link_group_access: group_access,
|
2018-03-17 18:26:18 +05:30
|
|
|
expires_at: nil
|
|
|
|
}
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
subject { described_class.new(project, user, opts) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-03-13 22:55:13 +05:30
|
|
|
before do
|
|
|
|
group.add_developer(user)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'adds group to project' do
|
|
|
|
expect { subject.execute(group) }.to change { project.project_group_links.count }.from(0).to(1)
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it 'updates authorization', :sidekiq_inline do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect { subject.execute(group) }.to(
|
|
|
|
change { Ability.allowed?(user, :read_project, project) }
|
|
|
|
.from(false).to(true))
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'returns false if group is blank' do
|
|
|
|
expect { subject.execute(nil) }.not_to change { project.project_group_links.count }
|
|
|
|
end
|
2019-03-13 22:55:13 +05:30
|
|
|
|
|
|
|
it 'returns error if user is not allowed to share with a group' do
|
2020-04-22 19:07:51 +05:30
|
|
|
expect { subject.execute(create(:group)) }.not_to change { project.project_group_links.count }
|
2019-03-13 22:55:13 +05:30
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
context 'with specialized_project_authorization_workers' do
|
|
|
|
let_it_be(:other_user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_developer(other_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'schedules authorization update for users with access to group' do
|
|
|
|
expect(AuthorizedProjectsWorker).not_to(
|
|
|
|
receive(:bulk_perform_async)
|
|
|
|
)
|
|
|
|
expect(AuthorizedProjectUpdate::ProjectGroupLinkCreateWorker).to(
|
2020-08-18 19:51:02 +05:30
|
|
|
receive(:perform_async)
|
|
|
|
.with(project.id, group.id, group_access)
|
|
|
|
.and_call_original
|
2020-07-28 23:09:34 +05:30
|
|
|
)
|
|
|
|
expect(AuthorizedProjectUpdate::UserRefreshWithLowUrgencyWorker).to(
|
|
|
|
receive(:bulk_perform_in)
|
|
|
|
.with(1.hour,
|
|
|
|
array_including([user.id], [other_user.id]),
|
|
|
|
batch_delay: 30.seconds, batch_size: 100)
|
|
|
|
.and_call_original
|
|
|
|
)
|
|
|
|
|
|
|
|
subject.execute(group)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when feature is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(specialized_project_authorization_project_share_worker: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses AuthorizedProjectsWorker' do
|
|
|
|
expect(AuthorizedProjectsWorker).to(
|
|
|
|
receive(:bulk_perform_async).with(array_including([user.id], [other_user.id])).and_call_original
|
|
|
|
)
|
|
|
|
expect(AuthorizedProjectUpdate::ProjectCreateWorker).not_to(
|
|
|
|
receive(:perform_async)
|
|
|
|
)
|
|
|
|
expect(AuthorizedProjectUpdate::UserRefreshWithLowUrgencyWorker).not_to(
|
|
|
|
receive(:bulk_perform_in)
|
|
|
|
)
|
|
|
|
|
|
|
|
subject.execute(group)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|