Class: Pageflow::UserPolicy
- Inherits:
-
ApplicationPolicy
- Object
- ApplicationPolicy
- Pageflow::UserPolicy
- Defined in:
- app/policies/pageflow/user_policy.rb
Defined Under Namespace
Classes: Scope
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #add_account_to? ⇒ Boolean
- #admin? ⇒ Boolean
- #create? ⇒ Boolean
- #create_any? ⇒ Boolean
- #delete_own_user? ⇒ Boolean
- #destroy? ⇒ Boolean
- #index? ⇒ Boolean
-
#initialize(user, managed_user) ⇒ UserPolicy
constructor
A new instance of UserPolicy.
- #read? ⇒ Boolean
- #redirect_to_user? ⇒ Boolean
- #see_admin_status? ⇒ Boolean
- #set_admin? ⇒ Boolean
- #suspend? ⇒ Boolean
Constructor Details
#initialize(user, managed_user) ⇒ UserPolicy
Returns a new instance of UserPolicy.
34 35 36 37 |
# File 'app/policies/pageflow/user_policy.rb', line 34 def initialize(user, managed_user) @user = user @managed_user = managed_user end |
Instance Attribute Details
#user ⇒ Object (readonly)
Returns the value of attribute user.
32 33 34 |
# File 'app/policies/pageflow/user_policy.rb', line 32 def user @user end |
Instance Method Details
#add_account_to? ⇒ Boolean
52 53 54 |
# File 'app/policies/pageflow/user_policy.rb', line 52 def add_account_to? Pageflow.config.allow_multiaccount_users end |
#admin? ⇒ Boolean
76 77 78 |
# File 'app/policies/pageflow/user_policy.rb', line 76 def admin? @user.admin? end |
#create? ⇒ Boolean
43 44 45 |
# File 'app/policies/pageflow/user_policy.rb', line 43 def create? index? end |
#create_any? ⇒ Boolean
39 40 41 |
# File 'app/policies/pageflow/user_policy.rb', line 39 def create_any? index? end |
#delete_own_user? ⇒ Boolean
92 93 94 |
# File 'app/policies/pageflow/user_policy.rb', line 92 def delete_own_user? Pageflow.config..call(@managed_user) == true end |
#destroy? ⇒ Boolean
72 73 74 |
# File 'app/policies/pageflow/user_policy.rb', line 72 def destroy? deny_sign_in? end |
#index? ⇒ Boolean
47 48 49 50 |
# File 'app/policies/pageflow/user_policy.rb', line 47 def index? @user.admin? || @user.memberships.on_accounts.where(role: 'manager').any? end |
#read? ⇒ Boolean
56 57 58 59 60 61 62 |
# File 'app/policies/pageflow/user_policy.rb', line 56 def read? manager_accounts = AccountPolicy::Scope .new(@user, Account).member_addable managed_user_accounts = AccountPolicy::Scope .new(@managed_user, Account).resolve (manager_accounts & managed_user_accounts).any? end |
#redirect_to_user? ⇒ Boolean
64 65 66 |
# File 'app/policies/pageflow/user_policy.rb', line 64 def redirect_to_user? read? end |
#see_admin_status? ⇒ Boolean
84 85 86 87 88 89 90 |
# File 'app/policies/pageflow/user_policy.rb', line 84 def see_admin_status? if .only_admins_may_see_admin_boolean admin? else read? end end |
#set_admin? ⇒ Boolean
80 81 82 |
# File 'app/policies/pageflow/user_policy.rb', line 80 def set_admin? admin? end |
#suspend? ⇒ Boolean
68 69 70 |
# File 'app/policies/pageflow/user_policy.rb', line 68 def suspend? deny_sign_in? end |