diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-14 03:11:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-14 03:11:11 +0300 |
commit | eb9f5ce5d9ec0c5dd4954ffe448214ae8eb144ac (patch) | |
tree | 32a97b1bb6c3b3f317683e649d2e4d9991464bde /app/services/todos | |
parent | d6f2690ceeffc5306381618473cc4e3e613ebecf (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/todos')
5 files changed, 56 insertions, 70 deletions
diff --git a/app/services/todos/destroy/base_service.rb b/app/services/todos/destroy/base_service.rb index ed5c4df85b1..c9c86330e1c 100644 --- a/app/services/todos/destroy/base_service.rb +++ b/app/services/todos/destroy/base_service.rb @@ -4,37 +4,6 @@ module Todos module Destroy class BaseService def execute - return unless todos_to_remove? - - ::Gitlab::Database.allow_cross_joins_across_databases(url: - 'https://gitlab.com/gitlab-org/gitlab/-/issues/422045') do - without_authorized(todos).delete_all - end - end - - private - - # rubocop: disable CodeReuse/ActiveRecord - def without_authorized(items) - items.where.not('todos.user_id' => 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 diff --git a/app/services/todos/destroy/confidential_issue_service.rb b/app/services/todos/destroy/confidential_issue_service.rb index fadc76b1181..261def314d4 100644 --- a/app/services/todos/destroy/confidential_issue_service.rb +++ b/app/services/todos/destroy/confidential_issue_service.rb @@ -13,54 +13,57 @@ module Todos attr_reader :issues - # rubocop: disable CodeReuse/ActiveRecord def initialize(issue_id: nil, project_id: nil) @issues = if issue_id - Issue.where(id: issue_id) + Issue.id_in(issue_id) elsif project_id project_confidential_issues(project_id) end end - # rubocop: enable CodeReuse/ActiveRecord + + def execute + return unless todos_to_remove? + + ::Gitlab::Database.allow_cross_joins_across_databases( + url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/422045') do + delete_todos + end + end private + def delete_todos + authorized_users = ProjectAuthorization.select(:user_id) + .for_project(project_ids) + .non_guests + + todos.not_in_users(authorized_users).delete_all + end + def project_confidential_issues(project_id) project = Project.find(project_id) project.issues.confidential_only end - override :todos # rubocop: disable CodeReuse/ActiveRecord def todos Todo.joins_issue_and_assignees - .where(target: issues) - .where(issues: { confidential: true }) + .for_target(issues) + .merge(Issue.confidential_only) .where('todos.user_id != issues.author_id') .where('todos.user_id != issue_assignees.user_id') end # rubocop: enable CodeReuse/ActiveRecord - override :todos_to_remove? def todos_to_remove? issues&.any?(&:confidential?) end - override :project_ids def project_ids issues&.distinct&.select(:project_id) end - - override :authorized_users - # rubocop: disable CodeReuse/ActiveRecord - def authorized_users - ProjectAuthorization.select(:user_id) - .where(project_id: project_ids) - .where('access_level >= ?', Gitlab::Access::REPORTER) - end - # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/services/todos/destroy/group_private_service.rb b/app/services/todos/destroy/group_private_service.rb index 60599ca9ca4..4230d763209 100644 --- a/app/services/todos/destroy/group_private_service.rb +++ b/app/services/todos/destroy/group_private_service.rb @@ -7,30 +7,31 @@ 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 - # rubocop: enable CodeReuse/ActiveRecord - private + def execute + return unless todos_to_remove? - override :todos - # rubocop: disable CodeReuse/ActiveRecord - def todos - Todo.where(group_id: group.id) + delete_todos end - # rubocop: enable CodeReuse/ActiveRecord - override :authorized_users - def authorized_users - User.from_union([ + private + + def delete_todos + authorized_users = User.from_union([ group.project_users_with_descendants.select(:id), group.members_with_parents.select(:user_id) ], remove_duplicates: false) + + todos.not_in_users(authorized_users).delete_all + end + + def todos + Todo.for_group(group.id) end - override :todos_to_remove? def todos_to_remove? group&.private? end diff --git a/app/services/todos/destroy/project_private_service.rb b/app/services/todos/destroy/project_private_service.rb index e00d10c3780..a1ca0d8543c 100644 --- a/app/services/todos/destroy/project_private_service.rb +++ b/app/services/todos/destroy/project_private_service.rb @@ -7,27 +7,32 @@ module Todos attr_reader :project - # rubocop: disable CodeReuse/ActiveRecord def initialize(project_id) - @project = Project.find_by(id: project_id) + @project = Project.find_by_id(project_id) + end + + def execute + return unless todos_to_remove? + + delete_todos end - # rubocop: enable CodeReuse/ActiveRecord private - override :todos - # rubocop: disable CodeReuse/ActiveRecord + def delete_todos + authorized_users = ProjectAuthorization.select(:user_id).for_project(project_ids) + + todos.not_in_users(authorized_users).delete_all + end + def todos - Todo.where(project_id: project.id) + Todo.for_project(project.id) end - # rubocop: enable CodeReuse/ActiveRecord - override :project_ids def project_ids project.id end - override :todos_to_remove? def todos_to_remove? project&.private? end diff --git a/app/services/todos/destroy/unauthorized_features_service.rb b/app/services/todos/destroy/unauthorized_features_service.rb index 513def10575..22f7a0b2a37 100644 --- a/app/services/todos/destroy/unauthorized_features_service.rb +++ b/app/services/todos/destroy/unauthorized_features_service.rb @@ -27,6 +27,14 @@ module Todos private + def without_authorized(items) + items.not_in_users(authorized_users) + end + + def authorized_users + ProjectAuthorization.select(:user_id).for_project(project_ids) + end + def related_todos base_scope = Todo.for_project(project_id) base_scope = base_scope.for_user(user_id) if user_id |