2018-08-11 03:00:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-27 05:28:17 -04:00
|
|
|
module Todos
|
|
|
|
module Destroy
|
|
|
|
class PrivateFeaturesService < ::Todos::Destroy::BaseService
|
|
|
|
attr_reader :project_ids, :user_id
|
|
|
|
|
|
|
|
def initialize(project_ids, user_id = nil)
|
|
|
|
@project_ids = project_ids
|
|
|
|
@user_id = user_id
|
|
|
|
end
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-07-27 05:28:17 -04:00
|
|
|
def execute
|
|
|
|
ProjectFeature.where(project_id: project_ids).each do |project_features|
|
|
|
|
target_types = []
|
2018-11-17 10:14:36 -05:00
|
|
|
target_types << Issue.name if private?(project_features.issues_access_level)
|
|
|
|
target_types << MergeRequest.name if private?(project_features.merge_requests_access_level)
|
|
|
|
target_types << Commit.name if private?(project_features.repository_access_level)
|
2018-07-27 05:28:17 -04:00
|
|
|
|
|
|
|
next if target_types.empty?
|
|
|
|
|
|
|
|
remove_todos(project_features.project_id, target_types)
|
|
|
|
end
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-07-27 05:28:17 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def private?(feature_level)
|
|
|
|
feature_level == ProjectFeature::PRIVATE
|
|
|
|
end
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-07-27 05:28:17 -04:00
|
|
|
def remove_todos(project_id, target_types)
|
|
|
|
items = Todo.where(project_id: project_id)
|
|
|
|
items = items.where(user_id: user_id) if user_id
|
|
|
|
|
2021-04-01 17:09:22 -04:00
|
|
|
items.where.not(user_id: authorized_users)
|
2018-07-27 05:28:17 -04:00
|
|
|
.where(target_type: target_types)
|
|
|
|
.delete_all
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-07-27 05:28:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|