Class: Pageflow::AccountPolicy

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

Defined Under Namespace

Classes: Scope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, account) ⇒ AccountPolicy

Returns a new instance of AccountPolicy.



51
52
53
54
55
# File 'app/policies/pageflow/account_policy.rb', line 51

def initialize(user, )
  @user = user
  @account = 
  @query = AccountRoleQuery.new(user, )
end

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



49
50
51
# File 'app/policies/pageflow/account_policy.rb', line 49

def query
  @query
end

#userObject (readonly)

Returns the value of attribute user.



49
50
51
# File 'app/policies/pageflow/account_policy.rb', line 49

def user
  @user
end

Instance Method Details

#add_member_to?Boolean

Returns:

  • (Boolean)


85
86
87
88
89
# File 'app/policies/pageflow/account_policy.rb', line 85

def add_member_to?
  Pageflow.config.allow_multiaccount_users &&
    (user.admin? ||
     query.has_at_least_role?(:manager))
end

#admin?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'app/policies/pageflow/account_policy.rb', line 109

def admin?
  user.admin?
end

#configure_folder_on?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/policies/pageflow/account_policy.rb', line 61

def configure_folder_on?
  publish?
end

#destroy_membership_on?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'app/policies/pageflow/account_policy.rb', line 105

def destroy_membership_on?
  add_member_to?
end

#edit_role_on?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'app/policies/pageflow/account_policy.rb', line 101

def edit_role_on?
  user.admin? || query.has_at_least_role?(:manager)
end

#index?Boolean

Returns:

  • (Boolean)


119
120
121
122
123
# File 'app/policies/pageflow/account_policy.rb', line 119

def index?
  admin? ||
    (Pageflow.config.allow_multiaccount_users &&
     @user.memberships.on_accounts.as_manager.any?)
end

#publish?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/policies/pageflow/account_policy.rb', line 57

def publish?
  user.admin? || query.has_at_least_role?(:publisher)
end

#read?Boolean

Returns:

  • (Boolean)


69
70
71
72
73
# File 'app/policies/pageflow/account_policy.rb', line 69

def read?
  user.admin? ||
    (query.has_at_least_role?(:manager) &&
     Pageflow.config.allow_multiaccount_users)
end

#see_badge_belonging_to?Boolean

Returns:

  • (Boolean)


113
114
115
116
117
# File 'app/policies/pageflow/account_policy.rb', line 113

def see_badge_belonging_to?
  (@account.entries & user.entries).any? ||
    query.has_at_least_role?(:previewer) ||
    user.admin?
end

#see_entry_types?Boolean

Returns:

  • (Boolean)


96
97
98
99
# File 'app/policies/pageflow/account_policy.rb', line 96

def see_entry_types?
  user.admin? ||
    query.has_at_least_role?(:publisher)
end

#see_user_quota?Boolean

Returns:

  • (Boolean)


91
92
93
94
# File 'app/policies/pageflow/account_policy.rb', line 91

def see_user_quota?
  user.admin? ||
    query.has_at_least_role?(:manager)
end

#update?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'app/policies/pageflow/account_policy.rb', line 75

def update?
  read?
end

#update_feature_configuration_on?Boolean

Returns:

  • (Boolean)


79
80
81
82
83
# File 'app/policies/pageflow/account_policy.rb', line 79

def update_feature_configuration_on?
  user.admin? ||
    (!permissions_config.only_admins_may_update_features &&
     read?)
end

#update_site_on_entry_of?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/policies/pageflow/account_policy.rb', line 65

def update_site_on_entry_of?
  publish?
end