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 ConfidentialIssueService < ::Todos::Destroy::BaseService
|
|
|
|
extend ::Gitlab::Utils::Override
|
|
|
|
|
|
|
|
attr_reader :issue
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-07-16 14:30:17 -04:00
|
|
|
def initialize(issue_id)
|
|
|
|
@issue = Issue.find_by(id: issue_id)
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-07-16 14:30:17 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
override :todos
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-07-16 14:30:17 -04:00
|
|
|
def todos
|
|
|
|
Todo.where(target: issue)
|
2018-07-26 10:53:50 -04:00
|
|
|
.where('user_id != ?', issue.author_id)
|
|
|
|
.where('user_id NOT IN (?)', issue.assignees.select(:id))
|
2018-07-16 14:30:17 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-07-16 14:30:17 -04:00
|
|
|
|
|
|
|
override :todos_to_remove?
|
|
|
|
def todos_to_remove?
|
|
|
|
issue&.confidential?
|
|
|
|
end
|
|
|
|
|
|
|
|
override :project_ids
|
|
|
|
def project_ids
|
|
|
|
issue.project_id
|
|
|
|
end
|
2018-07-26 10:53:50 -04:00
|
|
|
|
|
|
|
override :authorized_users
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-07-26 10:53:50 -04:00
|
|
|
def authorized_users
|
|
|
|
ProjectAuthorization.select(:user_id)
|
|
|
|
.where(project_id: project_ids)
|
|
|
|
.where('access_level >= ?', Gitlab::Access::REPORTER)
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-07-16 14:30:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|