diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-02 15:08:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-02 15:08:02 +0300 |
commit | f62c9f693fbe0d9bfac43cbe24b86af3c35f6a17 (patch) | |
tree | 7bbeb4fdf92d78324a92ff8a1385ea807c78665a /app/services/protected_branches | |
parent | 81745c5a7143999d492943a2dceb977ced0a766f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/protected_branches')
8 files changed, 22 insertions, 15 deletions
diff --git a/app/services/protected_branches/api_service.rb b/app/services/protected_branches/api_service.rb index b8fe9bac13e..0a7777c7fed 100644 --- a/app/services/protected_branches/api_service.rb +++ b/app/services/protected_branches/api_service.rb @@ -3,11 +3,11 @@ module ProtectedBranches class ApiService < ProtectedBranches::BaseService def create - ::ProtectedBranches::CreateService.new(@project, @current_user, protected_branch_params).execute + ::ProtectedBranches::CreateService.new(project_or_group, @current_user, protected_branch_params).execute end def update(protected_branch) - ::ProtectedBranches::UpdateService.new(@project, @current_user, + ::ProtectedBranches::UpdateService.new(project_or_group, @current_user, protected_branch_params(with_defaults: false)).execute(protected_branch) end @@ -36,4 +36,4 @@ protected_branch_params(with_defaults: false)).execute(protected_branch) end end -ProtectedBranches::ApiService.prepend_mod_with('ProtectedBranches::ApiService') +ProtectedBranches::ApiService.prepend_mod diff --git a/app/services/protected_branches/base_service.rb b/app/services/protected_branches/base_service.rb index d26c1b148bf..951017b2d01 100644 --- a/app/services/protected_branches/base_service.rb +++ b/app/services/protected_branches/base_service.rb @@ -2,10 +2,12 @@ module ProtectedBranches class BaseService < ::BaseService + attr_reader :project_or_group + # current_user - The user that performs the action # params - A hash of parameters - def initialize(project, current_user = nil, params = {}) - @project = project + def initialize(project_or_group, current_user = nil, params = {}) + @project_or_group = project_or_group @current_user = current_user @params = params end @@ -15,7 +17,7 @@ module ProtectedBranches end def refresh_cache - CacheService.new(@project, @current_user, @params).refresh + CacheService.new(@project_or_group, @current_user, @params).refresh end end end diff --git a/app/services/protected_branches/cache_service.rb b/app/services/protected_branches/cache_service.rb index 66ca549c508..af8c9ce74bb 100644 --- a/app/services/protected_branches/cache_service.rb +++ b/app/services/protected_branches/cache_service.rb @@ -66,13 +66,18 @@ module ProtectedBranches log_error( 'class' => self.class.name, 'message' => "Cache mismatch '#{encoded_ref_name}': cached value: #{cached_value}, real value: #{real_value}", - 'project_id' => @project.id, - 'project_path' => @project.full_path + 'record_class' => project_or_group.class.name, + 'record_id' => project_or_group.id, + 'record_path' => project_or_group.full_path ) end def redis_key - @redis_key ||= [CACHE_ROOT_KEY, @project.id].join(':') + @redis_key ||= if Feature.enabled?(:group_protected_branches) + [CACHE_ROOT_KEY, project_or_group.class.name, project_or_group.id].join(':') + else + [CACHE_ROOT_KEY, project_or_group.id].join(':') + end end def metrics diff --git a/app/services/protected_branches/create_service.rb b/app/services/protected_branches/create_service.rb index 903addf7afc..46585e0b65d 100644 --- a/app/services/protected_branches/create_service.rb +++ b/app/services/protected_branches/create_service.rb @@ -23,9 +23,9 @@ module ProtectedBranches end def protected_branch - @protected_branch ||= project.protected_branches.new(params) + @protected_branch ||= project_or_group.protected_branches.new(params) end end end -ProtectedBranches::CreateService.prepend_mod_with('ProtectedBranches::CreateService') +ProtectedBranches::CreateService.prepend_mod diff --git a/app/services/protected_branches/destroy_service.rb b/app/services/protected_branches/destroy_service.rb index 01d3b68314f..a32a867491e 100644 --- a/app/services/protected_branches/destroy_service.rb +++ b/app/services/protected_branches/destroy_service.rb @@ -10,4 +10,4 @@ module ProtectedBranches end end -ProtectedBranches::DestroyService.prepend_mod_with('ProtectedBranches::DestroyService') +ProtectedBranches::DestroyService.prepend_mod diff --git a/app/services/protected_branches/legacy_api_create_service.rb b/app/services/protected_branches/legacy_api_create_service.rb index aef99a860a0..f662d9d1bf0 100644 --- a/app/services/protected_branches/legacy_api_create_service.rb +++ b/app/services/protected_branches/legacy_api_create_service.rb @@ -24,7 +24,7 @@ module ProtectedBranches @params.merge!(push_access_levels_attributes: [{ access_level: push_access_level }], merge_access_levels_attributes: [{ access_level: merge_access_level }]) - service = ProtectedBranches::CreateService.new(@project, @current_user, @params) + service = ProtectedBranches::CreateService.new(project_or_group, @current_user, @params) service.execute end end diff --git a/app/services/protected_branches/legacy_api_update_service.rb b/app/services/protected_branches/legacy_api_update_service.rb index 8ff6c4bd734..b144797ab6d 100644 --- a/app/services/protected_branches/legacy_api_update_service.rb +++ b/app/services/protected_branches/legacy_api_update_service.rb @@ -30,7 +30,7 @@ module ProtectedBranches params[:merge_access_levels_attributes] = [{ access_level: Gitlab::Access::MAINTAINER }] end - service = ProtectedBranches::UpdateService.new(project, current_user, params) + service = ProtectedBranches::UpdateService.new(project_or_group, current_user, params) service.execute(protected_branch) end end diff --git a/app/services/protected_branches/update_service.rb b/app/services/protected_branches/update_service.rb index c155e0022f5..4b54bf92989 100644 --- a/app/services/protected_branches/update_service.rb +++ b/app/services/protected_branches/update_service.rb @@ -19,4 +19,4 @@ module ProtectedBranches end end -ProtectedBranches::UpdateService.prepend_mod_with('ProtectedBranches::UpdateService') +ProtectedBranches::UpdateService.prepend_mod |