Class: Decidim::Proposals::Abilities::CurrentUser
- Inherits:
-
Object
- Object
- Decidim::Proposals::Abilities::CurrentUser
- Includes:
- CanCan::Ability
- Defined in:
- 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
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(user, context) ⇒ CurrentUser
constructor
A new instance of CurrentUser.
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 '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| (:vote) && voting_enabled? && remaining_votes.positive? end can :unvote, Proposal do |_proposal| (:vote) && voting_enabled? end can :create, Proposal if (:create) && creation_enabled? can :report, Proposal can :report, Decidim::Comments::Comment end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
11 12 13 |
# File 'app/models/decidim/proposals/abilities/current_user.rb', line 11 def context @context end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
11 12 13 |
# File 'app/models/decidim/proposals/abilities/current_user.rb', line 11 def user @user end |