From b0f6a279206a4b0d117b58a7ad2d18f834ec84ea Mon Sep 17 00:00:00 2001 From: Mikk Romulus Date: Mon, 21 Oct 2024 13:09:25 +0300 Subject: [PATCH] fix: Sub-actors not appearing for Actor Developer roles --- app/policies/actor_policy.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/policies/actor_policy.rb b/app/policies/actor_policy.rb index 80720a64..91651178 100644 --- a/app/policies/actor_policy.rb +++ b/app/policies/actor_policy.rb @@ -29,16 +29,17 @@ def destroy? relation_scope(:vm_dev) do |relation| next relation if user.super_admin? - actor_dev = Actor.arel_table[:id].eq(RoleBinding.arel_table[:actor_id]).and( - RoleBinding.arel_table[:role].eq(:actor_dev) - ) + developer_actors = Actor.where( + id: RoleBinding.for_user(user).where(role: :actor_dev).pluck(:actor_id) + ).flat_map(&:subtree_ids) + is_env_role = Actor.arel_table[:exercise_id].eq(RoleBinding.arel_table[:exercise_id]) actor_admin = is_env_role.and(RoleBinding.arel_table[:role].in([:environment_admin])) relation .joins(:exercise) .merge(Exercise.for_user(user)) .where( - actor_dev + Actor.arel_table[:id].in(developer_actors) .or(actor_admin) ) end