summaryrefslogtreecommitdiff
path: root/app/services/todos
diff options
context:
space:
mode:
authorJarka Kadlecová <jarka@gitlab.com>2018-07-27 11:28:17 +0200
committerJarka Kadlecová <jarka@gitlab.com>2018-07-31 12:32:08 +0200
commitbdc8396e25e6eba6edcf2896daa49bb49695ef8c (patch)
treed08f569da8eaf56d192c631fa8dfd3ee791cb66b /app/services/todos
parent7934b91311a70d994c6700201979c6673160fd01 (diff)
downloadgitlab-ce-bdc8396e25e6eba6edcf2896daa49bb49695ef8c.tar.gz
Remove todos when project feature visibility changes
Diffstat (limited to 'app/services/todos')
-rw-r--r--app/services/todos/destroy/base_service.rb6
-rw-r--r--app/services/todos/destroy/entity_leave_service.rb20
-rw-r--r--app/services/todos/destroy/private_features_service.rb40
3 files changed, 56 insertions, 10 deletions
diff --git a/app/services/todos/destroy/base_service.rb b/app/services/todos/destroy/base_service.rb
index 71cd7921f32..dff5e1f30e5 100644
--- a/app/services/todos/destroy/base_service.rb
+++ b/app/services/todos/destroy/base_service.rb
@@ -18,15 +18,15 @@ module Todos
end
def todos
- # overridden in subclasses
+ raise NotImplementedError
end
def project_ids
- # overridden in subclasses
+ raise NotImplementedError
end
def todos_to_remove?
- # overridden in subclasses
+ raise NotImplementedError
end
end
end
diff --git a/app/services/todos/destroy/entity_leave_service.rb b/app/services/todos/destroy/entity_leave_service.rb
index 129e5505a21..2ff9f94b718 100644
--- a/app/services/todos/destroy/entity_leave_service.rb
+++ b/app/services/todos/destroy/entity_leave_service.rb
@@ -21,24 +21,30 @@ module Todos
if entity.private?
Todo.where(project_id: project_ids, user_id: user_id)
else
- Todo.where(target_id: confidential_issues.select(:id), target_type: Issue)
+ project_ids.each do |project_id|
+ TodosDestroyer::PrivateFeaturesWorker.perform_async(project_id, user_id)
+ end
+
+ Todo.where(
+ target_id: confidential_issues.select(:id), target_type: Issue, user_id: user_id
+ )
end
end
override :project_ids
def project_ids
- if entity.is_a?(Project)
- entity.id
- else
+ case entity
+ when Project
+ [entity.id]
+ when Namespace
Project.select(:id).where(namespace_id: entity.self_and_descendants.select(:id))
end
end
override :todos_to_remove?
def todos_to_remove?
- return unless entity
-
- entity.private? || confidential_issues.count > 0
+ # if an entity is provided we want to check always at least private features
+ !!entity
end
def confidential_issues
diff --git a/app/services/todos/destroy/private_features_service.rb b/app/services/todos/destroy/private_features_service.rb
new file mode 100644
index 00000000000..4d8e2877bfb
--- /dev/null
+++ b/app/services/todos/destroy/private_features_service.rb
@@ -0,0 +1,40 @@
+module Todos
+ module Destroy
+ class PrivateFeaturesService < ::Todos::Destroy::BaseService
+ attr_reader :project_ids, :user_id
+
+ def initialize(project_ids, user_id = nil)
+ @project_ids = project_ids
+ @user_id = user_id
+ end
+
+ def execute
+ ProjectFeature.where(project_id: project_ids).each do |project_features|
+ target_types = []
+ target_types << Issue if private?(project_features.issues_access_level)
+ target_types << MergeRequest if private?(project_features.merge_requests_access_level)
+ target_types << Commit if private?(project_features.repository_access_level)
+
+ next if target_types.empty?
+
+ remove_todos(project_features.project_id, target_types)
+ end
+ end
+
+ private
+
+ def private?(feature_level)
+ feature_level == ProjectFeature::PRIVATE
+ end
+
+ def remove_todos(project_id, target_types)
+ items = Todo.where(project_id: project_id)
+ items = items.where(user_id: user_id) if user_id
+
+ items.where('user_id NOT IN (?)', authorized_users)
+ .where(target_type: target_types)
+ .delete_all
+ end
+ end
+ end
+end