From 0cb43441ec28e4b69c5656054c6a00a31a7f3a99 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Mon, 20 Apr 2015 14:00:05 +0500 Subject: [PATCH] #465 fix platform scopes --- app/policies/platform_policy.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/policies/platform_policy.rb b/app/policies/platform_policy.rb index 56c3a949b..d333b2557 100644 --- a/app/policies/platform_policy.rb +++ b/app/policies/platform_policy.rb @@ -72,6 +72,20 @@ class PlatformPolicy < ApplicationPolicy platforms.owner_type = 'User' AND platforms.owner_id = :user_id ) OR ( platforms.owner_type = 'Group' AND platforms.owner_id IN (:user_group_ids) + ) OR ( + platforms.id = ANY ( + ARRAY ( + SELECT target_id + FROM relations + INNER JOIN platforms ON platforms.id = relations.target_id + WHERE relations.target_type = 'Platform' AND + ( + platforms.owner_type = 'User' AND platforms.owner_id != :user_id + ) AND ( + relations.actor_type = 'User' AND relations.actor_id = :user_id + ) + ) + ) ) SQL end @@ -86,6 +100,20 @@ class PlatformPolicy < ApplicationPolicy platforms.owner_type = 'User' AND platforms.owner_id = :user_id ) OR ( platforms.owner_type = 'Group' AND platforms.owner_id IN (:user_group_ids) + ) OR ( + platforms.id = ANY ( + ARRAY ( + SELECT target_id + FROM relations + INNER JOIN platforms ON platforms.id = relations.target_id + WHERE relations.target_type = 'Platform' AND + ( + platforms.owner_type = 'User' AND platforms.owner_id != :user_id + ) AND ( + relations.actor_type = 'User' AND relations.actor_id = :user_id + ) + ) + ) ) SQL end