Class: Decidim::Proposals::Permissions

Inherits:
DefaultPermissions
  • Object
show all
Defined in:
app/permissions/decidim/proposals/permissions.rb

Instance Method Summary collapse

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
30
31
32
33
34
35
# File 'app/permissions/decidim/proposals/permissions.rb', line 6

def permissions
  return permission_action unless user

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

  return permission_action if permission_action.subject != :proposal

  case permission_action.action
  when :create
    can_create_proposal?
  when :edit
    can_edit_proposal?
  when :withdraw
    can_withdraw_proposal?
  when :endorse
    can_endorse_proposal?
  when :unendorse
    can_unendorse_proposal?
  when :vote
    can_vote_proposal?
  when :unvote
    can_unvote_proposal?
  when :report
    true
  end

  permission_action
end