@@ -3,7 +3,7 @@ defmodule CodeCorps.Policy do
33 Handles authorization for various API actions performed on objects in the database.
44 """
55
6- alias CodeCorps . { Category , Comment , DonationGoal , GithubAppInstallation , GithubEvent , GithubRepo , Organization , OrganizationInvite , OrganizationGithubAppInstallation , Preview , Project , ProjectCategory , ProjectSkill , ProjectUser , Role , RoleSkill , Skill , StripeConnectAccount , StripeConnectPlan , StripeConnectSubscription , StripePlatformCard , StripePlatformCustomer , Task , TaskSkill , User , UserCategory , UserRole , UserSkill , UserTask }
6+ alias CodeCorps . { Category , Comment , DonationGoal , GithubAppInstallation , GithubEvent , GithubRepo , Message , Organization , OrganizationInvite , OrganizationGithubAppInstallation , Preview , Project , ProjectCategory , ProjectSkill , ProjectUser , Role , RoleSkill , Skill , StripeConnectAccount , StripeConnectPlan , StripeConnectSubscription , StripePlatformCard , StripePlatformCustomer , Task , TaskSkill , User , UserCategory , UserRole , UserSkill , UserTask }
77
88 alias CodeCorps.Policy
99
@@ -22,6 +22,13 @@ defmodule CodeCorps.Policy do
2222 end
2323 end
2424
25+ @ doc ~S"""
26+ Scopes a queryable so it's only able to return those records the specified
27+ user is authorized to view.
28+ """
29+ @ spec scope ( module , User . t ) :: Ecto.Queryable . t
30+ def scope ( Message , % User { } = current_user ) , do: Message |> Policy.Message . scope ( current_user )
31+
2532 @ spec can? ( User . t , atom , struct , map ) :: boolean
2633
2734 # Category
@@ -41,13 +48,17 @@ defmodule CodeCorps.Policy do
4148 defp can? ( % User { } = current_user , :create , % GithubAppInstallation { } , % { } = params ) , do: Policy.GithubAppInstallation . create? ( current_user , params )
4249
4350 # GithubEvent
44- defp can? ( % User { } = current_user , :index , % GithubEvent { } , % { } ) , do: Policy.GithubEvent . index? ( current_user )
4551 defp can? ( % User { } = current_user , :show , % GithubEvent { } , % { } ) , do: Policy.GithubEvent . show? ( current_user )
52+ defp can? ( % User { } = current_user , :index , % GithubEvent { } , % { } ) , do: Policy.GithubEvent . index? ( current_user )
4653 defp can? ( % User { } = current_user , :update , % GithubEvent { } , % { } ) , do: Policy.GithubEvent . update? ( current_user )
4754
4855 # GithubRepo
4956 defp can? ( % User { } = current_user , :update , % GithubRepo { } = github_repo , % { } = params ) , do: Policy.GithubRepo . update? ( current_user , github_repo , params )
5057
58+ # Message
59+ defp can? ( % User { } = current_user , :show , % Message { } = message , % { } ) , do: Policy.Message . show? ( current_user , message )
60+ defp can? ( % User { } = current_user , :create , % Message { } , % { } = params ) , do: Policy.Message . create? ( current_user , params )
61+
5162 # Organization
5263 defp can? ( % User { } = current_user , :create , % Organization { } , % { } = params ) , do: Policy.Organization . create? ( current_user , params )
5364 defp can? ( % User { } = current_user , :update , % Organization { } = organization , % { } = params ) , do: Policy.Organization . update? ( current_user , organization , params )
0 commit comments