@@ -6,7 +6,6 @@ defmodule CodeCorps.Policy do
66 alias CodeCorps . { Category , Comment , DonationGoal , GithubAppInstallation , Organization , OrganizationInvite , OrganizationGithubAppInstallation , Preview , Project , ProjectCategory , ProjectGithubRepo , ProjectSkill , ProjectUser , Role , RoleSkill , Skill , StripeConnectAccount , StripeConnectPlan , StripeConnectSubscription , StripePlatformCard , StripePlatformCustomer , Task , TaskSkill , User , UserCategory , UserRole , UserSkill , UserTask }
77
88 alias CodeCorps.Policy
9- alias Ecto.Changeset
109
1110 @ doc ~S"""
1211 Determines if the specified user can perform the specified action on the
@@ -28,36 +27,40 @@ defmodule CodeCorps.Policy do
2827 defp can? ( % User { } = current_user , :update , % Category { } , % { } ) , do: Policy.Category . update? ( current_user )
2928 defp can? ( % User { } = current_user , :create , % Comment { } , % { } = params ) , do: Policy.Comment . create? ( current_user , params )
3029 defp can? ( % User { } = current_user , :update , % Comment { } = comment , % { } ) , do: Policy.Comment . update? ( current_user , comment )
30+ defp can? ( % User { } = current_user , :create , % DonationGoal { } , % { } = params ) , do: Policy.DonationGoal . create? ( current_user , params )
31+ defp can? ( % User { } = current_user , :update , % DonationGoal { } = donation_goal , % { } ) , do: Policy.DonationGoal . update? ( current_user , donation_goal )
32+ defp can? ( % User { } = current_user , :delete , % DonationGoal { } = donation_goal , % { } ) , do: Policy.DonationGoal . delete? ( current_user , donation_goal )
33+ defp can? ( % User { } = current_user , :create , % GithubAppInstallation { } , % { } = params ) , do: Policy.GithubAppInstallation . create? ( current_user , params )
3134 defp can? ( % User { } = current_user , :create , % Organization { } , % { } ) , do: Policy.Organization . create? ( current_user )
3235 defp can? ( % User { } = current_user , :update , % Organization { } = organization , % { } ) , do: Policy.Organization . update? ( current_user , organization )
33- defp can? ( % User { } = current_user , :update , % User { } = user , % { } ) , do: Policy.User . update? ( current_user , user )
34- defp can? ( % User { } = current_user , :create , % Task { } , % { } = params ) , do: Policy.Task . create? ( current_user , params )
35- defp can? ( % User { } = current_user , :update , % Task { } = task , % { } ) , do: Policy.Task . update? ( current_user , task )
36- defp can? ( % User { } = current_user , :create , % UserTask { } , % { } = params ) , do: Policy.UserTask . create? ( current_user , params )
37- defp can? ( % User { } = current_user , :update , % UserTask { } = user_task , % { } ) , do: Policy.UserTask . update? ( current_user , user_task )
38- defp can? ( % User { } = current_user , :delete , % UserTask { } = user_task , % { } ) , do: Policy.UserTask . delete? ( current_user , user_task )
39- defp can? ( % User { } = current_user , :create , % Project { } , % { } = params ) , do: Policy.Project . create? ( current_user , params )
40- defp can? ( % User { } = current_user , :update , % Project { } = project , % { } ) , do: Policy.Project . update? ( current_user , project )
41- defp can? ( % User { } = current_user , :create , % ProjectSkill { } , % { } = params ) , do: Policy.ProjectSkill . create? ( current_user , params )
42- defp can? ( % User { } = current_user , :delete , % ProjectSkill { } = project_skill , % { } ) , do: Policy.ProjectSkill . delete? ( current_user , project_skill )
43- defp can? ( % User { } = current_user , :create , % ProjectUser { } , % { } = params ) , do: Policy.ProjectUser . create? ( current_user , params )
44- defp can? ( % User { } = current_user , :update , % ProjectUser { } = project_user , % { } = params ) , do: Policy.ProjectUser . update? ( current_user , project_user , params )
45- defp can? ( % User { } = current_user , :delete , % ProjectUser { } = project_user , % { } ) , do: Policy.ProjectUser . delete? ( current_user , project_user )
36+ defp can? ( % User { } = current_user , :delete , % OrganizationGithubAppInstallation { } = organization_github_app_installation , % { } ) ,
37+ do: Policy.OrganizationGithubAppInstallation . delete? ( current_user , organization_github_app_installation )
38+ defp can? ( % User { } = current_user , :create , % OrganizationGithubAppInstallation { } , % { } = params ) , do: Policy.OrganizationGithubAppInstallation . create? ( current_user , params )
4639 defp can? ( % User { } = current_user , :create , % OrganizationInvite { } , % { } ) , do: Policy.OrganizationInvite . create? ( current_user )
47- defp can? ( % User { } = current_user , :update , % OrganizationInvite { } = _invite , % { } ) , do: Policy.OrganizationInvite . update? ( current_user )
48- defp can? ( % User { } = user , :delete ,
49- % OrganizationGithubAppInstallation { } = organization_github_app_installation , % { } ) ,
50- do: Policy.OrganizationGithubAppInstallation . delete? ( user , organization_github_app_installation )
51- defp can? ( % User { } = user , :create , % OrganizationGithubAppInstallation { } , % { } = params ) , do: Policy.OrganizationGithubAppInstallation . create? ( user , params )
40+ defp can? ( % User { } = current_user , :update , % OrganizationInvite { } , % { } ) , do: Policy.OrganizationInvite . update? ( current_user )
5241 defp can? ( % User { } = current_user , :create , % Preview { } , % { } = params ) , do: Policy.Preview . create? ( current_user , params )
42+ defp can? ( % User { } = current_user , :create , % Project { } , % { } = params ) , do: Policy.Project . create? ( current_user , params )
43+ defp can? ( % User { } = current_user , :update , % Project { } = project , % { } ) , do: Policy.Project . update? ( current_user , project )
5344 defp can? ( % User { } = current_user , :create , % ProjectCategory { } , % { } = params ) , do: Policy.ProjectCategory . create? ( current_user , params )
5445 defp can? ( % User { } = current_user , :delete , % ProjectCategory { } = project_category , % { } ) , do: Policy.ProjectCategory . delete? ( current_user , project_category )
5546 defp can? ( % User { } = current_user , :create , % ProjectGithubRepo { } , % { } = params ) , do: Policy.ProjectGithubRepo . create? ( current_user , params )
5647 defp can? ( % User { } = current_user , :delete , % ProjectGithubRepo { } = project_github_repo , % { } ) ,
5748 do: Policy.ProjectGithubRepo . delete? ( current_user , project_github_repo )
49+ defp can? ( % User { } = current_user , :create , % ProjectSkill { } , % { } = params ) , do: Policy.ProjectSkill . create? ( current_user , params )
50+ defp can? ( % User { } = current_user , :delete , % ProjectSkill { } = project_skill , % { } ) , do: Policy.ProjectSkill . delete? ( current_user , project_skill )
51+ defp can? ( % User { } = current_user , :create , % ProjectUser { } , % { } = params ) , do: Policy.ProjectUser . create? ( current_user , params )
52+ defp can? ( % User { } = current_user , :update , % ProjectUser { } = project_user , % { } = params ) , do: Policy.ProjectUser . update? ( current_user , project_user , params )
53+ defp can? ( % User { } = current_user , :delete , % ProjectUser { } = project_user , % { } ) , do: Policy.ProjectUser . delete? ( current_user , project_user )
5854 defp can? ( % User { } = current_user , :create , % Role { } , % { } ) , do: Policy.Role . create? ( current_user )
5955 defp can? ( % User { } = current_user , :create , % RoleSkill { } , % { } ) , do: Policy.RoleSkill . create? ( current_user )
6056 defp can? ( % User { } = current_user , :delete , % RoleSkill { } , % { } ) , do: Policy.RoleSkill . delete? ( current_user )
57+ defp can? ( % User { } = current_user , :create , % Skill { } , % { } ) , do: Policy.Skill . create? ( current_user )
58+ defp can? ( % User { } = current_user , :show , % StripeConnectAccount { } = stripe_connect_account , % { } ) ,
59+ do: Policy.StripeConnectAccount . show? ( current_user , stripe_connect_account )
60+ defp can? ( % User { } = current_user , :create , % StripeConnectAccount { } , % { } = params ) ,
61+ do: Policy.StripeConnectAccount . create? ( current_user , params )
62+ defp can? ( % User { } = current_user , :update , % StripeConnectAccount { } = stripe_connect_account , % { } ) ,
63+ do: Policy.StripeConnectAccount . update? ( current_user , stripe_connect_account )
6164 defp can? ( % User { } = current_user , :show , % StripeConnectPlan { } = stripe_connect_plan , % { } ) ,
6265 do: Policy.StripeConnectPlan . show? ( current_user , stripe_connect_plan )
6366 defp can? ( % User { } = current_user , :create , % StripeConnectPlan { } , % { } = params ) ,
@@ -66,45 +69,26 @@ defmodule CodeCorps.Policy do
6669 do: Policy.StripeConnectSubscription . show? ( current_user , stripe_connect_subscription )
6770 defp can? ( % User { } = current_user , :create , % StripeConnectSubscription { } , % { } = params ) ,
6871 do: Policy.StripeConnectSubscription . create? ( current_user , params )
69- defp can? ( % User { } = current_user , :create , % Skill { } , % { } ) , do: Policy.Skill . create? ( current_user )
7072 defp can? ( % User { } = current_user , :show , % StripePlatformCard { } = stripe_platform_card , % { } ) ,
7173 do: Policy.StripePlatformCard . show? ( current_user , stripe_platform_card )
7274 defp can? ( % User { } = current_user , :create , % StripePlatformCard { } , % { } = params ) ,
7375 do: Policy.StripePlatformCard . create? ( current_user , params )
76+ defp can? ( % User { } = current_user , :create , % StripePlatformCustomer { } , % { } = params ) ,
77+ do: Policy.StripePlatformCustomer . create? ( current_user , params )
78+ defp can? ( % User { } = current_user , :show , % StripePlatformCustomer { } = stripe_platform_customer , % { } ) ,
79+ do: Policy.StripePlatformCustomer . show? ( current_user , stripe_platform_customer )
80+ defp can? ( % User { } = current_user , :create , % Task { } , % { } = params ) , do: Policy.Task . create? ( current_user , params )
81+ defp can? ( % User { } = current_user , :update , % Task { } = task , % { } ) , do: Policy.Task . update? ( current_user , task )
7482 defp can? ( % User { } = current_user , :create , % TaskSkill { } , % { } = params ) , do: Policy.TaskSkill . create? ( current_user , params )
7583 defp can? ( % User { } = current_user , :delete , % TaskSkill { } = task_skill , % { } ) , do: Policy.TaskSkill . delete? ( current_user , task_skill )
84+ defp can? ( % User { } = current_user , :update , % User { } = user , % { } ) , do: Policy.User . update? ( current_user , user )
7685 defp can? ( % User { } = current_user , :create , % UserCategory { } = user_category , % { } ) , do: Policy.UserCategory . create? ( current_user , user_category )
7786 defp can? ( % User { } = current_user , :delete , % UserCategory { } = user_category , % { } ) , do: Policy.UserCategory . delete? ( current_user , user_category )
78- defp can? ( % User { } = current_user , :create , % UserSkill { } , % { } = params ) , do: Policy.UserSkill . create? ( current_user , params )
79- defp can? ( % User { } = current_user , :delete , % UserSkill { } = user_skill , % { } ) , do: Policy.UserSkill . delete? ( current_user , user_skill )
8087 defp can? ( % User { } = current_user , :create , % UserRole { } = user_role , % { } ) , do: Policy.UserRole . create? ( current_user , user_role )
8188 defp can? ( % User { } = current_user , :delete , % UserRole { } = user_role , % { } ) , do: Policy.UserRole . delete? ( current_user , user_role )
82- defp can? ( % User { } = user , :show , % StripeConnectAccount { } = stripe_connect_account , % { } ) , do: Policy.StripeConnectAccount . show? ( user , stripe_connect_account )
83- defp can? ( % User { } = user , :create , % StripeConnectAccount { } , % { } = params ) , do: Policy.StripeConnectAccount . create? ( user , params )
84- defp can? ( % User { } = user , :update , % StripeConnectAccount { } = stripe_connect_account , % { } ) , do: Policy.StripeConnectAccount . update? ( user , stripe_connect_account )
85- defp can? ( % User { } = current_user , :create , % StripePlatformCustomer { } , % { } = params ) ,
86- do: Policy.StripePlatformCustomer . create? ( current_user , params )
87- defp can? ( % User { } = current_user , :show , % StripePlatformCustomer { } = stripe_platform_customer , % { } ) ,
88- do: Policy.StripePlatformCustomer . show? ( current_user , stripe_platform_customer )
89- defp can? ( % User { } = user , :create , % GithubAppInstallation { } , % { } = params ) , do: Policy.GithubAppInstallation . create? ( user , params )
90-
91- defimpl Canada.Can , for: User do
92- # NOTE: Canary sets an :unauthorized and a :not_found handler on a config level
93- # The problem is, it will still go through the authorization process first and only call the
94- # not found handler after the unauthorized handler does its thing. This means that our
95- # unauthorized handler will halt the connection and respond, so the not_found handler
96- # will never do anything
97- #
98- # The only solution is to have a catch_all match for the resource being nil, which returns true
99-
100- # NOTE: other tests are using the User policy for the time being.
101- def can? ( % User { } , _action , nil ) , do: true
102-
103- def can? ( % User { } = user , :create , % Changeset { data: % DonationGoal { } } = changeset ) , do: Policy.DonationGoal . create? ( user , changeset )
104- def can? ( % User { } = user , :update , % DonationGoal { } = comment ) , do: Policy.DonationGoal . update? ( user , comment )
105- def can? ( % User { } = user , :delete , % DonationGoal { } = comment ) , do: Policy.DonationGoal . delete? ( user , comment )
106-
107-
108- def can? ( % User { } = user , :create , Role ) , do: Policy.Role . create? ( user )
109- end
89+ defp can? ( % User { } = current_user , :create , % UserSkill { } , % { } = params ) , do: Policy.UserSkill . create? ( current_user , params )
90+ defp can? ( % User { } = current_user , :delete , % UserSkill { } = user_skill , % { } ) , do: Policy.UserSkill . delete? ( current_user , user_skill )
91+ defp can? ( % User { } = current_user , :create , % UserTask { } , % { } = params ) , do: Policy.UserTask . create? ( current_user , params )
92+ defp can? ( % User { } = current_user , :update , % UserTask { } = user_task , % { } ) , do: Policy.UserTask . update? ( current_user , user_task )
93+ defp can? ( % User { } = current_user , :delete , % UserTask { } = user_task , % { } ) , do: Policy.UserTask . delete? ( current_user , user_task )
11094end
0 commit comments