2018-08-11 03:00:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-16 14:30:17 -04:00
|
|
|
module Todos
|
|
|
|
module Destroy
|
|
|
|
class BaseService
|
|
|
|
def execute
|
|
|
|
return unless todos_to_remove?
|
|
|
|
|
|
|
|
without_authorized(todos).delete_all
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-07-16 14:30:17 -04:00
|
|
|
def without_authorized(items)
|
|
|
|
items.where('user_id NOT IN (?)', authorized_users)
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-07-16 14:30:17 -04:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-07-16 14:30:17 -04:00
|
|
|
def authorized_users
|
|
|
|
ProjectAuthorization.select(:user_id).where(project_id: project_ids)
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-07-16 14:30:17 -04:00
|
|
|
|
|
|
|
def todos
|
2018-07-27 05:28:17 -04:00
|
|
|
raise NotImplementedError
|
2018-07-16 14:30:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def project_ids
|
2018-07-27 05:28:17 -04:00
|
|
|
raise NotImplementedError
|
2018-07-16 14:30:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def todos_to_remove?
|
2018-07-27 05:28:17 -04:00
|
|
|
raise NotImplementedError
|
2018-07-16 14:30:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|