diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-08-27 18:31:01 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-09-11 18:32:00 +0300 |
commit | 2039c8280db1646845c33d6c5a74e5f23ca6f4de (patch) | |
tree | e2b3cd3012d9711cda7c6afb962ae4228d59521a /app/services/todos | |
parent | 91c40973dc620430b173ea2df968587d2a708dff (diff) |
Disable existing offenses for the CodeReuse cops
This whitelists all existing offenses for the various CodeReuse cops, of
which most are triggered by the CodeReuse/ActiveRecord cop.
Diffstat (limited to 'app/services/todos')
6 files changed, 40 insertions, 0 deletions
diff --git a/app/services/todos/destroy/base_service.rb b/app/services/todos/destroy/base_service.rb index aeb60e50c64..f3f1dbb5698 100644 --- a/app/services/todos/destroy/base_service.rb +++ b/app/services/todos/destroy/base_service.rb @@ -11,13 +11,17 @@ module Todos private + # rubocop: disable CodeReuse/ActiveRecord def without_authorized(items) items.where('user_id NOT IN (?)', authorized_users) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def authorized_users ProjectAuthorization.select(:user_id).where(project_id: project_ids) end + # rubocop: enable CodeReuse/ActiveRecord def todos raise NotImplementedError diff --git a/app/services/todos/destroy/confidential_issue_service.rb b/app/services/todos/destroy/confidential_issue_service.rb index efec0f22da5..6276e332448 100644 --- a/app/services/todos/destroy/confidential_issue_service.rb +++ b/app/services/todos/destroy/confidential_issue_service.rb @@ -7,18 +7,22 @@ module Todos attr_reader :issue + # rubocop: disable CodeReuse/ActiveRecord def initialize(issue_id) @issue = Issue.find_by(id: issue_id) end + # rubocop: enable CodeReuse/ActiveRecord private override :todos + # rubocop: disable CodeReuse/ActiveRecord def todos Todo.where(target: issue) .where('user_id != ?', issue.author_id) .where('user_id NOT IN (?)', issue.assignees.select(:id)) end + # rubocop: enable CodeReuse/ActiveRecord override :todos_to_remove? def todos_to_remove? @@ -31,11 +35,13 @@ module Todos end override :authorized_users + # rubocop: disable CodeReuse/ActiveRecord def authorized_users ProjectAuthorization.select(:user_id) .where(project_id: project_ids) .where('access_level >= ?', Gitlab::Access::REPORTER) end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/services/todos/destroy/entity_leave_service.rb b/app/services/todos/destroy/entity_leave_service.rb index 4cb9d08713d..e8d1bcdd142 100644 --- a/app/services/todos/destroy/entity_leave_service.rb +++ b/app/services/todos/destroy/entity_leave_service.rb @@ -7,6 +7,7 @@ module Todos attr_reader :user, :entity + # rubocop: disable CodeReuse/ActiveRecord def initialize(user_id, entity_id, entity_type) unless %w(Group Project).include?(entity_type) raise ArgumentError.new("#{entity_type} is not an entity user can leave") @@ -15,6 +16,7 @@ module Todos @user = User.find_by(id: user_id) @entity = entity_type.constantize.find_by(id: entity_id) end + # rubocop: enable CodeReuse/ActiveRecord def execute return unless entity && user @@ -40,21 +42,28 @@ module Todos end end + # rubocop: disable CodeReuse/ActiveRecord def remove_confidential_issue_todos Todo.where( target_id: confidential_issues.select(:id), target_type: Issue, user_id: user.id ).delete_all end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def remove_project_todos Todo.where(project_id: non_authorized_projects, user_id: user.id).delete_all end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def remove_group_todos Todo.where(group_id: non_authorized_groups, user_id: user.id).delete_all end + # rubocop: enable CodeReuse/ActiveRecord override :project_ids + # rubocop: disable CodeReuse/ActiveRecord def project_ids condition = case entity when Project @@ -65,22 +74,29 @@ module Todos Project.where(condition).select(:id) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def non_authorized_projects project_ids.where('id NOT IN (?)', user.authorized_projects.select(:id)) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def non_authorized_groups return [] unless entity.is_a?(Namespace) entity.self_and_descendants.select(:id) .where('id NOT IN (?)', GroupsFinder.new(user).execute.select(:id)) end + # rubocop: enable CodeReuse/ActiveRecord + # rubocop: disable CodeReuse/ActiveRecord def non_member_groups entity.self_and_descendants.select(:id) .where('id NOT IN (?)', user.membership_groups.select(:id)) end + # rubocop: enable CodeReuse/ActiveRecord def user_has_reporter_access? return unless entity.is_a?(Namespace) @@ -88,6 +104,7 @@ module Todos entity.member?(User.find(user.id), Gitlab::Access::REPORTER) end + # rubocop: disable CodeReuse/ActiveRecord def confidential_issues assigned_ids = IssueAssignee.select(:issue_id).where(user_id: user.id) authorized_reporter_projects = user @@ -98,6 +115,7 @@ module Todos .where('author_id != ?', user.id) .where('id NOT IN (?)', assigned_ids) end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/services/todos/destroy/group_private_service.rb b/app/services/todos/destroy/group_private_service.rb index f67f1d40597..d7ecbb952aa 100644 --- a/app/services/todos/destroy/group_private_service.rb +++ b/app/services/todos/destroy/group_private_service.rb @@ -7,16 +7,20 @@ module Todos attr_reader :group + # rubocop: disable CodeReuse/ActiveRecord def initialize(group_id) @group = Group.find_by(id: group_id) end + # rubocop: enable CodeReuse/ActiveRecord private override :todos + # rubocop: disable CodeReuse/ActiveRecord def todos Todo.where(group_id: group.id) end + # rubocop: enable CodeReuse/ActiveRecord override :authorized_users def authorized_users diff --git a/app/services/todos/destroy/private_features_service.rb b/app/services/todos/destroy/private_features_service.rb index 7e204885b31..a8c3fe0ef5a 100644 --- a/app/services/todos/destroy/private_features_service.rb +++ b/app/services/todos/destroy/private_features_service.rb @@ -10,6 +10,7 @@ module Todos @user_id = user_id end + # rubocop: disable CodeReuse/ActiveRecord def execute ProjectFeature.where(project_id: project_ids).each do |project_features| target_types = [] @@ -22,6 +23,7 @@ module Todos remove_todos(project_features.project_id, target_types) end end + # rubocop: enable CodeReuse/ActiveRecord private @@ -29,6 +31,7 @@ module Todos feature_level == ProjectFeature::PRIVATE end + # rubocop: disable CodeReuse/ActiveRecord def remove_todos(project_id, target_types) items = Todo.where(project_id: project_id) items = items.where(user_id: user_id) if user_id @@ -37,6 +40,7 @@ module Todos .where(target_type: target_types) .delete_all end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/services/todos/destroy/project_private_service.rb b/app/services/todos/destroy/project_private_service.rb index ae8fab3ffca..e00d10c3780 100644 --- a/app/services/todos/destroy/project_private_service.rb +++ b/app/services/todos/destroy/project_private_service.rb @@ -7,16 +7,20 @@ module Todos attr_reader :project + # rubocop: disable CodeReuse/ActiveRecord def initialize(project_id) @project = Project.find_by(id: project_id) end + # rubocop: enable CodeReuse/ActiveRecord private override :todos + # rubocop: disable CodeReuse/ActiveRecord def todos Todo.where(project_id: project.id) end + # rubocop: enable CodeReuse/ActiveRecord override :project_ids def project_ids |