Class: Decidim::Elections::Permissions

Inherits:
DefaultPermissions show all
Defined in:
decidim-elections/app/permissions/decidim/elections/permissions.rb

Instance Method Summary collapse

Methods inherited from DefaultPermissions

#initialize

Constructor Details

This class inherits a constructor from Decidim::DefaultPermissions

Instance Method Details

#permissionsObject


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'decidim-elections/app/permissions/decidim/elections/permissions.rb', line 6

def permissions
  if permission_action.scope == :public && permission_action.subject == :election
    case permission_action.action
    when :preview
      toggle_allow(can_preview?)
    when :view
      toggle_allow(can_view?)
    when :vote
      toggle_allow(can_vote?)
    when :user_vote
      toggle_allow(can_vote_with_user?)
    end
  end

  return permission_action unless user

  # Delegate the admin permission checks to the admin permissions class
  return Decidim::Elections::Admin::Permissions.new(user, permission_action, context).permissions if permission_action.scope == :admin

  # Delegate the trustee_zone permission checks to the trustee zone permissions class
  return Decidim::Elections::TrusteeZone::Permissions.new(user, permission_action, context).permissions if permission_action.scope == :trustee_zone

  permission_action
end