diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ci/build.rb | 6 | ||||
-rw-r--r-- | app/models/ci/pipeline.rb | 4 | ||||
-rw-r--r-- | app/models/commit_status.rb | 4 | ||||
-rw-r--r-- | app/models/container_repository.rb | 2 | ||||
-rw-r--r-- | app/models/dashboard_group_milestone.rb | 2 | ||||
-rw-r--r-- | app/models/environment.rb | 2 | ||||
-rw-r--r-- | app/models/global_milestone.rb | 6 | ||||
-rw-r--r-- | app/models/group.rb | 4 | ||||
-rw-r--r-- | app/models/hooks/service_hook.rb | 2 | ||||
-rw-r--r-- | app/models/hooks/web_hook.rb | 4 | ||||
-rw-r--r-- | app/models/issue.rb | 4 | ||||
-rw-r--r-- | app/models/key.rb | 8 | ||||
-rw-r--r-- | app/models/member.rb | 10 | ||||
-rw-r--r-- | app/models/members/project_member.rb | 2 | ||||
-rw-r--r-- | app/models/merge_request.rb | 12 | ||||
-rw-r--r-- | app/models/merge_request_diff.rb | 2 | ||||
-rw-r--r-- | app/models/note.rb | 2 | ||||
-rw-r--r-- | app/models/pages_domain.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 20 | ||||
-rw-r--r-- | app/models/project_import_state.rb | 2 | ||||
-rw-r--r-- | app/models/project_services/slash_commands_service.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 24 |
22 files changed, 122 insertions, 6 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index faa160ad6ba..42d30d56aa2 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -139,9 +139,11 @@ module Ci end def retry(build, current_user) + # rubocop: disable CodeReuse/ServiceClass Ci::RetryBuildService .new(build.project, current_user) .execute(build) + # rubocop: enable CodeReuse/ServiceClass end end @@ -224,11 +226,13 @@ module Ci self.when == 'manual' end + # rubocop: disable CodeReuse/ServiceClass def play(current_user) Ci::PlayBuildService .new(project, current_user) .execute(self) end + # rubocop: enable CodeReuse/ServiceClass def cancelable? active? || created? @@ -385,9 +389,11 @@ module Ci update(coverage: coverage) if coverage.present? end + # rubocop: disable CodeReuse/ServiceClass def parse_trace_sections! ExtractSectionsFromBuildTraceService.new(project, user).execute(self) end + # rubocop: enable CodeReuse/ServiceClass def trace Gitlab::Ci::Trace.new(self) diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 2955e0b2bca..4295c46e689 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -387,10 +387,12 @@ module Ci end end + # rubocop: disable CodeReuse/ServiceClass def retry_failed(current_user) Ci::RetryPipelineService.new(project, current_user) .execute(self) end + # rubocop: enable CodeReuse/ServiceClass def mark_as_processable_after_stage(stage_idx) builds.skipped.after_stage(stage_idx).find_each(&:process) @@ -525,9 +527,11 @@ module Ci project.notes.for_commit_id(sha) end + # rubocop: disable CodeReuse/ServiceClass def process! Ci::ProcessPipelineService.new(project, user).execute(self) end + # rubocop: enable CodeReuse/ServiceClass def update_status retry_optimistic_lock(self) do diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index b65d7672973..fe2f144ef03 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -58,9 +58,11 @@ class CommitStatus < ActiveRecord::Base # These are pages deployments and external statuses. # before_create unless: :importing? do + # rubocop: disable CodeReuse/ServiceClass Ci::EnsureStageService.new(project, user).execute(self) do |stage| self.run_after_commit { StageUpdateWorker.perform_async(stage.id) } end + # rubocop: enable CodeReuse/ServiceClass end state_machine :status do @@ -130,10 +132,12 @@ class CommitStatus < ActiveRecord::Base after_transition any => :failed do |commit_status| next unless commit_status.project + # rubocop: disable CodeReuse/ServiceClass commit_status.run_after_commit do MergeRequests::AddTodoWhenBuildFailsService .new(project, nil).execute(self) end + # rubocop: enable CodeReuse/ServiceClass end end diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb index 41413854d5c..93ca3a5daf4 100644 --- a/app/models/container_repository.rb +++ b/app/models/container_repository.rb @@ -10,6 +10,7 @@ class ContainerRepository < ActiveRecord::Base before_destroy :delete_tags! + # rubocop: disable CodeReuse/ServiceClass def registry @registry ||= begin token = Auth::ContainerRegistryAuthenticationService.full_access_token(path) @@ -20,6 +21,7 @@ class ContainerRepository < ActiveRecord::Base ContainerRegistry::Registry.new(url, token: token, path: host_port) end end + # rubocop: enable CodeReuse/ServiceClass def path @path ||= [project.full_path, name] diff --git a/app/models/dashboard_group_milestone.rb b/app/models/dashboard_group_milestone.rb index 13807d43265..4e39f60b0d2 100644 --- a/app/models/dashboard_group_milestone.rb +++ b/app/models/dashboard_group_milestone.rb @@ -13,7 +13,7 @@ class DashboardGroupMilestone < GlobalMilestone end def self.build_collection(groups) - MilestonesFinder.new(group_ids: groups.pluck(:id)).execute.map { |m| new(m) } + MilestonesFinder.new(group_ids: groups.pluck(:id)).execute.map { |m| new(m) } # rubocop: disable CodeReuse/Finder end override :group_milestone? diff --git a/app/models/environment.rb b/app/models/environment.rb index c8d1d378ae0..309bd4f37c9 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -158,9 +158,11 @@ class Environment < ActiveRecord::Base prometheus_adapter.query(:additional_metrics_environment, self) if has_metrics? end + # rubocop: disable CodeReuse/ServiceClass def prometheus_adapter @prometheus_adapter ||= Prometheus::AdapterService.new(project, deployment_platform).prometheus_adapter end + # rubocop: enable CodeReuse/ServiceClass def slug super.presence || generate_slug diff --git a/app/models/global_milestone.rb b/app/models/global_milestone.rb index 6e23e811b0e..a6cebabe089 100644 --- a/app/models/global_milestone.rb +++ b/app/models/global_milestone.rb @@ -17,7 +17,7 @@ class GlobalMilestone params = { project_ids: projects.map(&:id), state: params[:state] } - child_milestones = MilestonesFinder.new(params).execute + child_milestones = MilestonesFinder.new(params).execute # rubocop: disable CodeReuse/Finder milestones = child_milestones.select(:id, :title).group_by(&:title).map do |title, grouped| milestones_relation = Milestone.where(id: grouped.map(&:id)) @@ -48,7 +48,7 @@ class GlobalMilestone params = { group_ids: [group.id], state: 'all' } - relation = MilestonesFinder.new(params).execute + relation = MilestonesFinder.new(params).execute # rubocop: disable CodeReuse/Finder grouped_by_state = relation.reorder(nil).group(:state).count { @@ -64,7 +64,7 @@ class GlobalMilestone params = { project_ids: projects.map(&:id), state: 'all' } - relation = MilestonesFinder.new(params).execute + relation = MilestonesFinder.new(params).execute # rubocop: disable CodeReuse/Finder project_milestones_by_state_and_title = relation.reorder(nil).group(:state, :title).count opened = count_by_state(project_milestones_by_state_and_title, 'active') diff --git a/app/models/group.rb b/app/models/group.rb index 106a1f4a94c..024e77188b8 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -236,14 +236,18 @@ class Group < Namespace system_hook_service.execute_hooks_for(self, :destroy) end + # rubocop: disable CodeReuse/ServiceClass def system_hook_service SystemHooksService.new end + # rubocop: enable CodeReuse/ServiceClass + # rubocop: disable CodeReuse/ServiceClass def refresh_members_authorized_projects(blocking: true) UserProjectAccessChangedService.new(user_ids_for_project_authorizations) .execute(blocking: blocking) end + # rubocop: enable CodeReuse/ServiceClass def user_ids_for_project_authorizations members_with_parents.pluck(:user_id) diff --git a/app/models/hooks/service_hook.rb b/app/models/hooks/service_hook.rb index bda82a116a1..7d9f6d89d44 100644 --- a/app/models/hooks/service_hook.rb +++ b/app/models/hooks/service_hook.rb @@ -4,7 +4,9 @@ class ServiceHook < WebHook belongs_to :service validates :service, presence: true + # rubocop: disable CodeReuse/ServiceClass def execute(data) WebHookService.new(self, data, 'service_hook').execute end + # rubocop: enable CodeReuse/ServiceClass end diff --git a/app/models/hooks/web_hook.rb b/app/models/hooks/web_hook.rb index 20f15c15277..771a61b090f 100644 --- a/app/models/hooks/web_hook.rb +++ b/app/models/hooks/web_hook.rb @@ -11,13 +11,17 @@ class WebHook < ActiveRecord::Base validates :token, format: { without: /\n/ } validates :push_events_branch_filter, branch_filter: true + # rubocop: disable CodeReuse/ServiceClass def execute(data, hook_name) WebHookService.new(self, data, hook_name).execute end + # rubocop: enable CodeReuse/ServiceClass + # rubocop: disable CodeReuse/ServiceClass def async_execute(data, hook_name) WebHookService.new(self, data, hook_name).async_execute end + # rubocop: enable CodeReuse/ServiceClass # Allow urls pointing localhost and the local network def allow_local_requests? diff --git a/app/models/issue.rb b/app/models/issue.rb index d0cd7461daa..d13fbcf002c 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -172,6 +172,7 @@ class Issue < ActiveRecord::Base # All branches containing the current issue's ID, except for # those with a merge request open referencing the current issue. + # rubocop: disable CodeReuse/ServiceClass def related_branches(current_user) branches_with_iid = project.repository.branch_names.select do |branch| branch =~ /\A#{iid}-(?!\d+-stable)/i @@ -185,6 +186,7 @@ class Issue < ActiveRecord::Base branches_with_iid - branches_with_merge_request end + # rubocop: enable CodeReuse/ServiceClass def suggested_branch_name return to_branch_name unless project.repository.branch_exists?(to_branch_name) @@ -278,9 +280,11 @@ class Issue < ActiveRecord::Base true end + # rubocop: disable CodeReuse/ServiceClass def update_project_counter_caches Projects::OpenIssuesCountService.new(project).refresh_cache end + # rubocop: enable CodeReuse/ServiceClass private diff --git a/app/models/key.rb b/app/models/key.rb index 3bb0d2f6f9c..bdb83e12793 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -55,9 +55,11 @@ class Key < ActiveRecord::Base "key-#{id}" end + # rubocop: disable CodeReuse/ServiceClass def update_last_used_at Keys::LastUsedService.new(self).execute end + # rubocop: enable CodeReuse/ServiceClass def add_to_shell GitlabShellWorker.perform_async( @@ -67,9 +69,11 @@ class Key < ActiveRecord::Base ) end + # rubocop: disable CodeReuse/ServiceClass def post_create_hook SystemHooksService.new.execute_hooks_for(self, :create) end + # rubocop: enable CodeReuse/ServiceClass def remove_from_shell GitlabShellWorker.perform_async( @@ -79,15 +83,19 @@ class Key < ActiveRecord::Base ) end + # rubocop: disable CodeReuse/ServiceClass def refresh_user_cache return unless user Users::KeysCountService.new(user).refresh_cache end + # rubocop: enable CodeReuse/ServiceClass + # rubocop: disable CodeReuse/ServiceClass def post_destroy_hook SystemHooksService.new.execute_hooks_for(self, :destroy) end + # rubocop: enable CodeReuse/ServiceClass def public_key @public_key ||= Gitlab::SSHPublicKey.new(key) diff --git a/app/models/member.rb b/app/models/member.rb index d9b4e8d2ac6..0696ea46c8b 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -145,6 +145,7 @@ class Member < ActiveRecord::Base end def add_user(source, user, access_level, existing_members: nil, current_user: nil, expires_at: nil, ldap: false) + # rubocop: disable CodeReuse/ServiceClass # `user` can be either a User object, User ID or an email to be invited member = retrieve_member(source, user, existing_members) access_level = retrieve_access_level(access_level) @@ -171,6 +172,7 @@ class Member < ActiveRecord::Base end member + # rubocop: enable CodeReuse/ServiceClass end def add_users(source, users, access_level, current_user: nil, expires_at: nil) @@ -339,12 +341,14 @@ class Member < ActiveRecord::Base @notification_setting ||= user&.notification_settings_for(source) end + # rubocop: disable CodeReuse/ServiceClass def notifiable?(type, opts = {}) # always notify when there isn't a user yet return true if user.blank? NotificationRecipientService.notifiable?(user, type, notifiable_options.merge(opts)) end + # rubocop: enable CodeReuse/ServiceClass private @@ -374,6 +378,7 @@ class Member < ActiveRecord::Base # in a transaction. Doing so can lead to the job running before the # transaction has been committed, resulting in the job either throwing an # error or not doing any meaningful work. + # rubocop: disable CodeReuse/ServiceClass def refresh_member_authorized_projects # If user/source is being destroyed, project access are going to be # destroyed eventually because of DB foreign keys, so we shouldn't bother @@ -382,6 +387,7 @@ class Member < ActiveRecord::Base UserProjectAccessChangedService.new(user_id).execute end + # rubocop: enable CodeReuse/ServiceClass def after_accept_invite post_create_hook @@ -395,13 +401,17 @@ class Member < ActiveRecord::Base post_create_hook end + # rubocop: disable CodeReuse/ServiceClass def system_hook_service SystemHooksService.new end + # rubocop: enable CodeReuse/ServiceClass + # rubocop: disable CodeReuse/ServiceClass def notification_service NotificationService.new end + # rubocop: enable CodeReuse/ServiceClass def notifiable_options {} diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index 0154fe5aeba..537f2a3a231 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -138,7 +138,9 @@ class ProjectMember < Member super end + # rubocop: disable CodeReuse/ServiceClass def event_service EventCreateService.new end + # rubocop: enable CodeReuse/ServiceClass end diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 396647a14ae..e19bf62dcd0 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -137,12 +137,14 @@ class MergeRequest < ActiveRecord::Base Gitlab::Timeless.timeless(merge_request, &block) end + # rubocop: disable CodeReuse/ServiceClass after_transition unchecked: :cannot_be_merged do |merge_request, transition| if merge_request.notify_conflict? NotificationService.new.merge_request_unmergeable(merge_request) TodoService.new.merge_request_became_unmergeable(merge_request) end end + # rubocop: enable CodeReuse/ServiceClass def check_state?(merge_status) [:unchecked, :cannot_be_merged_recheck].include?(merge_status.to_sym) @@ -623,11 +625,13 @@ class MergeRequest < ActiveRecord::Base end end + # rubocop: disable CodeReuse/ServiceClass def reload_diff(current_user = nil) return unless open? MergeRequests::ReloadDiffsService.new(self, current_user).execute end + # rubocop: enable CodeReuse/ServiceClass def check_if_can_be_merged return unless self.class.state_machines[:merge_status].check_state?(merge_status) && Gitlab::Database.read_write? @@ -1036,6 +1040,7 @@ class MergeRequest < ActiveRecord::Base actual_head_pipeline&.has_test_reports? end + # rubocop: disable CodeReuse/ServiceClass def compare_test_reports unless has_test_reports? return { status: :error, status_reason: 'This merge request does not have test reports' } @@ -1050,7 +1055,9 @@ class MergeRequest < ActiveRecord::Base data end || { status: :parsing } end + # rubocop: enable CodeReuse/ServiceClass + # rubocop: disable CodeReuse/ServiceClass def calculate_reactive_cache(identifier, *args) case identifier.to_sym when :compare_test_results @@ -1060,6 +1067,7 @@ class MergeRequest < ActiveRecord::Base raise NotImplementedError, "Unknown identifier: #{identifier}" end end + # rubocop: enable CodeReuse/ServiceClass def all_commits # MySQL doesn't support LIMIT in a subquery. @@ -1125,6 +1133,7 @@ class MergeRequest < ActiveRecord::Base diff_refs && diff_refs.complete? end + # rubocop: disable CodeReuse/ServiceClass def update_diff_discussion_positions(old_diff_refs:, new_diff_refs:, current_user: nil) return unless has_complete_diff_refs? return if new_diff_refs == old_diff_refs @@ -1154,6 +1163,7 @@ class MergeRequest < ActiveRecord::Base .execute(self) end end + # rubocop: enable CodeReuse/ServiceClass def keep_around_commit project.repository.keep_around(self.merge_commit_sha) @@ -1189,9 +1199,11 @@ class MergeRequest < ActiveRecord::Base true end + # rubocop: disable CodeReuse/ServiceClass def update_project_counter_caches Projects::OpenMergeRequestsCountService.new(target_project).refresh_cache end + # rubocop: enable CodeReuse/ServiceClass def first_contribution? return false if project.team.max_member_access(author_id) > Gitlab::Access::GUEST diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index bbe4f6f7969..02c6b650f33 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -219,12 +219,14 @@ class MergeRequestDiff < ActiveRecord::Base self.id == merge_request.latest_merge_request_diff_id end + # rubocop: disable CodeReuse/ServiceClass def compare_with(sha) # When compare merge request versions we want diff A..B instead of A...B # so we handle cases when user does squash and rebase of the commits between versions. # For this reason we set straight to true by default. CompareService.new(project, head_commit_sha).execute(project, sha, straight: true) end + # rubocop: enable CodeReuse/ServiceClass private diff --git a/app/models/note.rb b/app/models/note.rb index 8f090cc31e6..4429c1dcb07 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -181,6 +181,7 @@ class Note < ActiveRecord::Base end end + # rubocop: disable CodeReuse/ServiceClass def cross_reference? return unless system? @@ -190,6 +191,7 @@ class Note < ActiveRecord::Base SystemNoteService.cross_reference?(note) end end + # rubocop: enable CodeReuse/ServiceClass def diff_note? false diff --git a/app/models/pages_domain.rb b/app/models/pages_domain.rb index 7739a3894d3..7a33ade826b 100644 --- a/app/models/pages_domain.rb +++ b/app/models/pages_domain.rb @@ -140,9 +140,11 @@ class PagesDomain < ActiveRecord::Base self.verification_code = SecureRandom.hex(16) end + # rubocop: disable CodeReuse/ServiceClass def update_daemon ::Projects::UpdatePagesConfigurationService.new(project).execute end + # rubocop: enable CodeReuse/ServiceClass def pages_config_changed? project_id_changed? || diff --git a/app/models/project.rb b/app/models/project.rb index 8928bffd36c..036335d7cd9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1115,12 +1115,14 @@ class Project < ActiveRecord::Base find_or_initialize_services.find { |service| service.to_param == name } end + # rubocop: disable CodeReuse/ServiceClass def create_labels Label.templates.each do |label| params = label.attributes.except('id', 'template', 'created_at', 'updated_at') Labels::FindOrCreateService.new(nil, self, params).execute(skip_authorization: true) end end + # rubocop: enable CodeReuse/ServiceClass def find_service(list, name) list.find { |service| service.to_param == name } @@ -1168,6 +1170,7 @@ class Project < ActiveRecord::Base end end + # rubocop: disable CodeReuse/ServiceClass def send_move_instructions(old_path_with_namespace) # New project path needs to be committed to the DB or notification will # retrieve stale information @@ -1175,6 +1178,7 @@ class Project < ActiveRecord::Base NotificationService.new.project_was_moved(self, old_path_with_namespace) end end + # rubocop: enable CodeReuse/ServiceClass def owner if group @@ -1184,6 +1188,7 @@ class Project < ActiveRecord::Base end end + # rubocop: disable CodeReuse/ServiceClass def execute_hooks(data, hooks_scope = :push_hooks) run_after_commit_or_now do hooks.hooks_for(hooks_scope).select_active(hooks_scope, data).each do |hook| @@ -1192,6 +1197,7 @@ class Project < ActiveRecord::Base SystemHooksService.new.execute_hooks(data, hooks_scope) end end + # rubocop: enable CodeReuse/ServiceClass def execute_services(data, hooks_scope = :push_hooks) # Call only service hooks that are active for this scope @@ -1506,13 +1512,17 @@ class Project < ActiveRecord::Base self.runners_token && ActiveSupport::SecurityUtils.variable_size_secure_compare(token, self.runners_token) end + # rubocop: disable CodeReuse/ServiceClass def open_issues_count(current_user = nil) Projects::OpenIssuesCountService.new(self, current_user).count end + # rubocop: enable CodeReuse/ServiceClass + # rubocop: disable CodeReuse/ServiceClass def open_merge_requests_count Projects::OpenMergeRequestsCountService.new(self).count end + # rubocop: enable CodeReuse/ServiceClass def visibility_level_allowed_as_fork?(level = self.visibility_level) return true unless forked? @@ -1593,6 +1603,7 @@ class Project < ActiveRecord::Base end # TODO: what to do here when not using Legacy Storage? Do we still need to rename and delay removal? + # rubocop: disable CodeReuse/ServiceClass def remove_pages # Projects with a missing namespace cannot have their pages removed return unless namespace @@ -1608,6 +1619,7 @@ class Project < ActiveRecord::Base PagesWorker.perform_in(5.minutes, :remove, namespace.full_path, temp_path) end end + # rubocop: enable CodeReuse/ServiceClass def rename_repo path_before = previous_changes['path'].first @@ -1668,6 +1680,7 @@ class Project < ActiveRecord::Base end end + # rubocop: disable CodeReuse/ServiceClass def after_create_default_branch return unless default_branch @@ -1688,6 +1701,7 @@ class Project < ActiveRecord::Base ProtectedBranches::CreateService.new(self, creator, params).execute(skip_authorization: true) end end + # rubocop: enable CodeReuse/ServiceClass def remove_import_jid return unless import_jid @@ -1918,9 +1932,11 @@ class Project < ActiveRecord::Base # @deprecated cannot remove yet because it has an index with its name in elasticsearch alias_method :path_with_namespace, :full_path + # rubocop: disable CodeReuse/ServiceClass def forks_count Projects::ForksCountService.new(self).count end + # rubocop: enable CodeReuse/ServiceClass def legacy_storage? [nil, 0].include?(self.storage_version) @@ -2071,6 +2087,7 @@ class Project < ActiveRecord::Base private + # rubocop: disable CodeReuse/ServiceClass def rename_or_migrate_repository! if Gitlab::CurrentSettings.hashed_storage_enabled? && storage_upgradable? && @@ -2080,6 +2097,7 @@ class Project < ActiveRecord::Base storage.rename_repo end end + # rubocop: enable CodeReuse/ServiceClass def storage_upgradable? storage_version != LATEST_STORAGE_VERSION @@ -2104,6 +2122,7 @@ class Project < ActiveRecord::Base self.project_feature.untrack_statistics_for_deletion! end + # rubocop: disable CodeReuse/ServiceClass def execute_rename_repository_hooks!(full_path_before) # When we import a project overwriting the original project, there # is a move operation. In that case we don't want to send the instructions. @@ -2114,6 +2133,7 @@ class Project < ActiveRecord::Base reload_repository! end + # rubocop: enable CodeReuse/ServiceClass def storage @storage ||= diff --git a/app/models/project_import_state.rb b/app/models/project_import_state.rb index 89ed09af96a..d59cb43dea4 100644 --- a/app/models/project_import_state.rb +++ b/app/models/project_import_state.rb @@ -48,9 +48,11 @@ class ProjectImportState < ActiveRecord::Base project.reset_cache_and_import_attrs if Gitlab::ImportSources.importer_names.include?(project.import_type) && project.repo_exists? + # rubocop: disable CodeReuse/ServiceClass state.run_after_commit do Projects::AfterImportService.new(project).execute end + # rubocop: enable CodeReuse/ServiceClass end end end diff --git a/app/models/project_services/slash_commands_service.rb b/app/models/project_services/slash_commands_service.rb index e3ab60adefd..bfabc6d262c 100644 --- a/app/models/project_services/slash_commands_service.rb +++ b/app/models/project_services/slash_commands_service.rb @@ -44,11 +44,15 @@ class SlashCommandsService < Service private + # rubocop: disable CodeReuse/ServiceClass def find_chat_user(params) ChatNames::FindUserService.new(self, params).execute end + # rubocop: enable CodeReuse/ServiceClass + # rubocop: disable CodeReuse/ServiceClass def authorize_chat_name_url(params) ChatNames::AuthorizeUserService.new(self, params).execute end + # rubocop: enable CodeReuse/ServiceClass end diff --git a/app/models/user.rb b/app/models/user.rb index 568ec101016..dac8779488d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -61,6 +61,7 @@ class User < ActiveRecord::Base # Override Devise::Models::Trackable#update_tracked_fields! # to limit database writes to at most once every hour + # rubocop: disable CodeReuse/ServiceClass def update_tracked_fields!(request) return if Gitlab::Database.read_only? @@ -71,6 +72,7 @@ class User < ActiveRecord::Base Users::UpdateService.new(self, user: self).execute(validate: false) end + # rubocop: enable CodeReuse/ServiceClass attr_accessor :force_random_password @@ -455,7 +457,7 @@ class User < ActiveRecord::Base def find_by_personal_access_token(token_string) return unless token_string - PersonalAccessTokensFinder.new(state: 'active').find_by(token: token_string)&.user + PersonalAccessTokensFinder.new(state: 'active').find_by(token: token_string)&.user # rubocop: disable CodeReuse/Finder end # Returns a user for the given SSH key. @@ -627,6 +629,7 @@ class User < ActiveRecord::Base # hash and `_was` variables getting munged. # By using an `after_commit` instead of `after_update`, we avoid the recursive callback # scenario, though it then requires us to use the `previous_changes` hash + # rubocop: disable CodeReuse/ServiceClass def update_emails_with_primary_email(previous_email) primary_email_record = emails.find_by(email: email) Emails::DestroyService.new(self, user: self).execute(primary_email_record) if primary_email_record @@ -635,6 +638,7 @@ class User < ActiveRecord::Base # have access to the original confirmation values at this point, so just set confirmed_at Emails::CreateService.new(self, user: self, email: previous_email).execute(confirmed_at: confirmed_at) end + # rubocop: enable CodeReuse/ServiceClass def update_invalid_gpg_signatures gpg_keys.each(&:update_invalid_gpg_signatures) @@ -663,9 +667,11 @@ class User < ActiveRecord::Base all_expanded_groups.where(require_two_factor_authentication: true) end + # rubocop: disable CodeReuse/ServiceClass def refresh_authorized_projects Users::RefreshAuthorizedProjectsService.new(self).execute end + # rubocop: enable CodeReuse/ServiceClass def remove_project_authorizations(project_ids) project_authorizations.where(project_id: project_ids).delete_all @@ -718,11 +724,13 @@ class User < ActiveRecord::Base authorized_projects(Gitlab::Access::REPORTER).non_archived.with_issues_enabled end + # rubocop: disable CodeReuse/ServiceClass def require_ssh_key? count = Users::KeysCountService.new(self).count count.zero? && Gitlab::ProtocolAccess.allowed?('ssh') end + # rubocop: enable CodeReuse/ServiceClass def require_password_creation_for_web? allow_password_authentication_for_web? && password_automatically_set? @@ -786,6 +794,7 @@ class User < ActiveRecord::Base projects_limit - personal_projects_count end + # rubocop: disable CodeReuse/ServiceClass def recent_push(project = nil) service = Users::LastPushEventService.new(self) @@ -795,6 +804,7 @@ class User < ActiveRecord::Base service.last_event_for_user end end + # rubocop: enable CodeReuse/ServiceClass def several_namespaces? owned_groups.any? || maintainers_groups.any? @@ -932,9 +942,11 @@ class User < ActiveRecord::Base email.start_with?('temp-email-for-oauth') end + # rubocop: disable CodeReuse/ServiceClass def avatar_url(size: nil, scale: 2, **args) GravatarService.new.execute(email, size, scale, username: username) end + # rubocop: enable CodeReuse/ServiceClass def primary_email_verified? confirmed? && !temp_oauth_email? @@ -1000,26 +1012,32 @@ class User < ActiveRecord::Base system_hook_service.execute_hooks_for(self, :destroy) end + # rubocop: disable CodeReuse/ServiceClass def remove_key_cache Users::KeysCountService.new(self).delete_cache end + # rubocop: enable CodeReuse/ServiceClass def delete_async(deleted_by:, params: {}) block if params[:hard_delete] DeleteUserWorker.perform_async(deleted_by.id, id, params.to_h) end + # rubocop: disable CodeReuse/ServiceClass def notification_service NotificationService.new end + # rubocop: enable CodeReuse/ServiceClass def log_info(message) Gitlab::AppLogger.info message end + # rubocop: disable CodeReuse/ServiceClass def system_hook_service SystemHooksService.new end + # rubocop: enable CodeReuse/ServiceClass def starred?(project) starred_projects.exists?(project.id) @@ -1188,6 +1206,7 @@ class User < ActiveRecord::Base # See: # <https://github.com/plataformatec/devise/blob/v4.0.0/lib/devise/models/lockable.rb#L92> # + # rubocop: disable CodeReuse/ServiceClass def increment_failed_attempts! return if ::Gitlab::Database.read_only? @@ -1200,6 +1219,7 @@ class User < ActiveRecord::Base Users::UpdateService.new(self, user: self).execute(validate: false) end end + # rubocop: enable CodeReuse/ServiceClass def access_level if admin? @@ -1440,7 +1460,7 @@ class User < ActiveRecord::Base &creation_block ) - Users::UpdateService.new(user, user: user).execute(validate: false) + Users::UpdateService.new(user, user: user).execute(validate: false) # rubocop: disable CodeReuse/ServiceClass user ensure Gitlab::ExclusiveLease.cancel(lease_key, uuid) |