Class: Todos::Destroy::UnauthorizedFeaturesService
- Inherits:
-
BaseService
- Object
- BaseService
- Todos::Destroy::UnauthorizedFeaturesService
- Defined in:
- app/services/todos/destroy/unauthorized_features_service.rb
Constant Summary collapse
- BATCH_SIZE =
1000
Instance Attribute Summary collapse
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Instance Method Summary collapse
-
#execute ⇒ Object
rubocop: disable CodeReuse/ActiveRecord.
-
#initialize(project_id, user_id = nil) ⇒ UnauthorizedFeaturesService
constructor
A new instance of UnauthorizedFeaturesService.
Constructor Details
#initialize(project_id, user_id = nil) ⇒ UnauthorizedFeaturesService
Returns a new instance of UnauthorizedFeaturesService.
10 11 12 13 |
# File 'app/services/todos/destroy/unauthorized_features_service.rb', line 10 def initialize(project_id, user_id = nil) @project_id = project_id @user_id = user_id end |
Instance Attribute Details
#project_id ⇒ Object (readonly)
Returns the value of attribute project_id.
6 7 8 |
# File 'app/services/todos/destroy/unauthorized_features_service.rb', line 6 def project_id @project_id end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
6 7 8 |
# File 'app/services/todos/destroy/unauthorized_features_service.rb', line 6 def user_id @user_id end |
Instance Method Details
#execute ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/todos/destroy/unauthorized_features_service.rb', line 16 def execute return if user_id && .where(user_id: user_id).exists? .each_batch(of: BATCH_SIZE) do |batch| pending_delete = (batch).includes(:target, :user).reject do |todo| Ability.allowed?(todo.user, :read_todo, todo, scope: :user) end Todo.where(id: pending_delete).delete_all if pending_delete.present? end end |