2020-06-23 00:09:42 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Projects::GroupLinks::UpdateService, '#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 }
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
let!(:link) { create(:project_group_link, project: project, group: group) }
|
|
|
|
|
|
|
|
let(:expiry_date) { 1.month.from_now.to_date }
|
|
|
|
let(:group_link_params) do
|
|
|
|
{ group_access: Gitlab::Access::GUEST,
|
|
|
|
expires_at: expiry_date }
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(link).execute(group_link_params) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates existing link' do
|
|
|
|
expect(link.group_access).to eq(Gitlab::Access::DEVELOPER)
|
|
|
|
expect(link.expires_at).to be_nil
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
|
|
|
link.reload
|
|
|
|
|
|
|
|
expect(link.group_access).to eq(Gitlab::Access::GUEST)
|
|
|
|
expect(link.expires_at).to eq(expiry_date)
|
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
context 'project authorizations update' do
|
2021-11-18 22:05:49 +05:30
|
|
|
it 'calls AuthorizedProjectUpdate::ProjectRecalculateWorker to update project authorizations' do
|
|
|
|
expect(AuthorizedProjectUpdate::ProjectRecalculateWorker)
|
|
|
|
.to receive(:perform_async).with(link.project.id)
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
subject
|
|
|
|
end
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
it 'calls AuthorizedProjectUpdate::UserRefreshFromReplicaWorker with a delay to update project authorizations' do
|
|
|
|
expect(AuthorizedProjectUpdate::UserRefreshFromReplicaWorker).to(
|
|
|
|
receive(:bulk_perform_in)
|
|
|
|
.with(1.hour,
|
|
|
|
[[user.id]],
|
|
|
|
batch_delay: 30.seconds, batch_size: 100)
|
|
|
|
)
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
subject
|
|
|
|
end
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
it 'updates project authorizations of users who had access to the project via the group share', :sidekiq_inline do
|
|
|
|
group.add_maintainer(user)
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect { subject }.to(
|
|
|
|
change { Ability.allowed?(user, :create_release, project) }
|
|
|
|
.from(true).to(false))
|
2021-09-30 23:02:18 +05:30
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'with only param not requiring authorization refresh' do
|
|
|
|
let(:group_link_params) { { expires_at: Date.tomorrow } }
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
it 'does not perform any project authorizations update using `AuthorizedProjectUpdate::ProjectRecalculateWorker`' do
|
|
|
|
expect(AuthorizedProjectUpdate::ProjectRecalculateWorker).not_to receive(:perform_async)
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
subject
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|