diff options
Diffstat (limited to 'spec/services/projects/group_links')
3 files changed, 77 insertions, 12 deletions
diff --git a/spec/services/projects/group_links/create_service_spec.rb b/spec/services/projects/group_links/create_service_spec.rb index 9bc780fe177..4ea5f2b3a53 100644 --- a/spec/services/projects/group_links/create_service_spec.rb +++ b/spec/services/projects/group_links/create_service_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Projects::GroupLinks::CreateService, '#execute' do let_it_be(:user) { create :user } let_it_be(:group) { create :group } let_it_be(:project) { create :project } + let(:group_access) { Gitlab::Access::DEVELOPER } let(:opts) do { @@ -49,9 +50,9 @@ RSpec.describe Projects::GroupLinks::CreateService, '#execute' do expect(AuthorizedProjectsWorker).not_to( receive(:bulk_perform_async) ) - expect(AuthorizedProjectUpdate::ProjectGroupLinkCreateWorker).to( + expect(AuthorizedProjectUpdate::ProjectRecalculateWorker).to( receive(:perform_async) - .with(project.id, group.id, group_access) + .with(project.id) .and_call_original ) expect(AuthorizedProjectUpdate::UserRefreshFromReplicaWorker).to( diff --git a/spec/services/projects/group_links/destroy_service_spec.rb b/spec/services/projects/group_links/destroy_service_spec.rb index d60e9a01e54..d65afb68bfe 100644 --- a/spec/services/projects/group_links/destroy_service_spec.rb +++ b/spec/services/projects/group_links/destroy_service_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Projects::GroupLinks::DestroyService, '#execute' do let_it_be(:user) { create :user } let_it_be(:project) { create(:project, :private) } let_it_be(:group) { create(:group) } + let!(:group_link) { create(:project_group_link, project: project, group: group) } subject { described_class.new(project, user) } diff --git a/spec/services/projects/group_links/update_service_spec.rb b/spec/services/projects/group_links/update_service_spec.rb index 053c5eb611e..4a38fb0c7d9 100644 --- a/spec/services/projects/group_links/update_service_spec.rb +++ b/spec/services/projects/group_links/update_service_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Projects::GroupLinks::UpdateService, '#execute' do let_it_be(:user) { create :user } let_it_be(:group) { create :group } let_it_be(:project) { create :project } + let!(:link) { create(:project_group_link, project: project, group: group) } let(:expiry_date) { 1.month.from_now.to_date } @@ -32,25 +33,87 @@ RSpec.describe Projects::GroupLinks::UpdateService, '#execute' do expect(link.expires_at).to eq(expiry_date) end - it 'updates project permissions' do - expect { subject }.to change { user.can?(:create_release, project) }.from(true).to(false) - end + context 'project authorizations update' do + context 'when the feature flag `specialized_worker_for_project_share_update_auth_recalculation` is enabled' do + before do + stub_feature_flags(specialized_worker_for_project_share_update_auth_recalculation: true) + end + + it 'calls AuthorizedProjectUpdate::ProjectRecalculateWorker to update project authorizations' do + expect(AuthorizedProjectUpdate::ProjectRecalculateWorker) + .to receive(:perform_async).with(link.project.id) + + subject + end + + 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) + ) - it 'executes UserProjectAccessChangedService' do - expect_next_instance_of(UserProjectAccessChangedService) do |service| - expect(service).to receive(:execute) + subject + end + + it 'updates project authorizations of users who had access to the project via the group share', :sidekiq_inline do + group.add_maintainer(user) + + expect { subject }.to( + change { Ability.allowed?(user, :create_release, project) } + .from(true).to(false)) + end end - subject + context 'when the feature flag `specialized_worker_for_project_share_update_auth_recalculation` is disabled' do + before do + stub_feature_flags(specialized_worker_for_project_share_update_auth_recalculation: false) + end + + it 'calls UserProjectAccessChangedService to update project authorizations' do + expect_next_instance_of(UserProjectAccessChangedService, [user.id]) do |service| + expect(service).to receive(:execute) + end + + subject + end + + it 'updates project authorizations of users who had access to the project via the group share' do + group.add_maintainer(user) + + expect { subject }.to( + change { Ability.allowed?(user, :create_release, project) } + .from(true).to(false)) + end + end end context 'with only param not requiring authorization refresh' do let(:group_link_params) { { expires_at: Date.tomorrow } } - it 'does not execute UserProjectAccessChangedService' do - expect(UserProjectAccessChangedService).not_to receive(:new) + context 'when the feature flag `specialized_worker_for_project_share_update_auth_recalculation` is enabled' do + before do + stub_feature_flags(specialized_worker_for_project_share_update_auth_recalculation: true) + end + + it 'does not perform any project authorizations update using `AuthorizedProjectUpdate::ProjectRecalculateWorker`' do + expect(AuthorizedProjectUpdate::ProjectRecalculateWorker).not_to receive(:perform_async) + + subject + end + end + + context 'when the feature flag `specialized_worker_for_project_share_update_auth_recalculation` is disabled' do + before do + stub_feature_flags(specialized_worker_for_project_share_update_auth_recalculation: false) + end + + it 'does not perform any project authorizations update using `UserProjectAccessChangedService`' do + expect(UserProjectAccessChangedService).not_to receive(:new) - subject + subject + end end end end |