Class: Pageflow::UserPolicy

Inherits:
ApplicationPolicy show all
Defined in:
app/policies/pageflow/user_policy.rb

Defined Under Namespace

Classes: Scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, managed_user) ⇒ 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

#userObject (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 
  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.authorize_user_deletion.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, ).member_addable
  managed_user_accounts = AccountPolicy::Scope
                          .new(@managed_user, ).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 permissions_config.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