diff options
author | Jarka Kadlecová <jarka@gitlab.com> | 2018-07-27 11:28:17 +0200 |
---|---|---|
committer | Jarka Kadlecová <jarka@gitlab.com> | 2018-07-31 12:32:08 +0200 |
commit | bdc8396e25e6eba6edcf2896daa49bb49695ef8c (patch) | |
tree | d08f569da8eaf56d192c631fa8dfd3ee791cb66b /app/services/todos/destroy/private_features_service.rb | |
parent | 7934b91311a70d994c6700201979c6673160fd01 (diff) | |
download | gitlab-ce-bdc8396e25e6eba6edcf2896daa49bb49695ef8c.tar.gz |
Remove todos when project feature visibility changes
Diffstat (limited to 'app/services/todos/destroy/private_features_service.rb')
-rw-r--r-- | app/services/todos/destroy/private_features_service.rb | 40 |
1 files changed, 40 insertions, 0 deletions
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 |