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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/todos/destroy/group_private_service.rb')
-rw-r--r--app/services/todos/destroy/group_private_service.rb36
1 files changed, 20 insertions, 16 deletions
diff --git a/app/services/todos/destroy/group_private_service.rb b/app/services/todos/destroy/group_private_service.rb
index 60599ca9ca4..6962c204e0e 100644
--- a/app/services/todos/destroy/group_private_service.rb
+++ b/app/services/todos/destroy/group_private_service.rb
@@ -7,30 +7,34 @@ module Todos
attr_reader :group
- # rubocop: disable CodeReuse/ActiveRecord
def initialize(group_id)
- @group = Group.find_by(id: group_id)
+ @group = Group.find_by_id(group_id)
+ end
+
+ def execute
+ return unless todos_to_remove?
+
+ delete_todos
end
- # rubocop: enable CodeReuse/ActiveRecord
private
- override :todos
- # rubocop: disable CodeReuse/ActiveRecord
- def todos
- Todo.where(group_id: group.id)
+ def delete_todos
+ authorized_users = Member.from_union(
+ [
+ group.descendant_project_members_with_inactive.select(:user_id),
+ group.members_with_parents.select(:user_id)
+ ],
+ remove_duplicates: false
+ ).select(:user_id)
+
+ todos.not_in_users(authorized_users).delete_all
end
- # rubocop: enable CodeReuse/ActiveRecord
-
- override :authorized_users
- def authorized_users
- User.from_union([
- group.project_users_with_descendants.select(:id),
- group.members_with_parents.select(:user_id)
- ], remove_duplicates: false)
+
+ def todos
+ Todo.for_group(group.id)
end
- override :todos_to_remove?
def todos_to_remove?
group&.private?
end