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

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

#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

Returns:

  • (Boolean)


52
53
54
# File 'app/policies/pageflow/user_policy.rb', line 52

def 
  Pageflow.config.allow_multiaccount_users
end

#admin?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'app/policies/pageflow/user_policy.rb', line 76

def admin?
  @user.admin?
end

#create?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/policies/pageflow/user_policy.rb', line 43

def create?
  index?
end

#create_any?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/policies/pageflow/user_policy.rb', line 39

def create_any?
  index?
end

#delete_own_user?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


72
73
74
# File 'app/policies/pageflow/user_policy.rb', line 72

def destroy?
  deny_sign_in?
end

#index?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


64
65
66
# File 'app/policies/pageflow/user_policy.rb', line 64

def redirect_to_user?
  read?
end

#see_admin_status?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


80
81
82
# File 'app/policies/pageflow/user_policy.rb', line 80

def set_admin?
  admin?
end

#suspend?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'app/policies/pageflow/user_policy.rb', line 68

def suspend?
  deny_sign_in?
end