Welcome to mirror list, hosted at ThFree Co, Russian Federation.

base_service.rb « destroy « todos « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7378f10e7c4256f03374d289990bd77b106f479a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

module Todos
  module Destroy
    class BaseService
      def execute
        return unless todos_to_remove?

        without_authorized(todos).delete_all
      end

      private

      # rubocop: disable CodeReuse/ActiveRecord
      def without_authorized(items)
        items.where('todos.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
      end

      def project_ids
        raise NotImplementedError
      end

      def todos_to_remove?
        raise NotImplementedError
      end
    end
  end
end