Class: Decidim::Proposals::Abilities::CurrentUser

Inherits:
Object
  • Object
show all
Includes:
CanCan::Ability
Defined in:
decidim-proposals/app/models/decidim/proposals/abilities/current_user.rb

Overview

Defines the abilities related to proposals for a logged in user. Intended to be used with ‘cancancan`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, context) ⇒ CurrentUser

Returns a new instance of CurrentUser.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'decidim-proposals/app/models/decidim/proposals/abilities/current_user.rb', line 13

def initialize(user, context)
  return unless user

  @user = user
  @context = context

  can :vote, Proposal do |_proposal|
    authorized?(:vote) && voting_enabled? && remaining_votes.positive?
  end

  can :unvote, Proposal do |_proposal|
    authorized?(:vote) && voting_enabled?
  end

  can :create, Proposal if authorized?(:create) && creation_enabled?

  can :report, Proposal
  can :report, Decidim::Comments::Comment
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



11
12
13
# File 'decidim-proposals/app/models/decidim/proposals/abilities/current_user.rb', line 11

def context
  @context
end

#userObject (readonly)

Returns the value of attribute user.



11
12
13
# File 'decidim-proposals/app/models/decidim/proposals/abilities/current_user.rb', line 11

def user
  @user
end