#465 fix platform scopes

This commit is contained in:
Alexander Machehin 2015-04-20 14:00:05 +05:00
parent 9f8bbed7a2
commit 0cb43441ec
1 changed files with 28 additions and 0 deletions

View File

@ -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