Class: Decidim::Abilities::ParticipatoryProcessRoleAbility
- Inherits:
-
Object
- Object
- Decidim::Abilities::ParticipatoryProcessRoleAbility
- Includes:
- CanCan::Ability
- Defined in:
- lib/decidim/abilities/participatory_process_role_ability.rb
Overview
Base class used for any participatory process role ability.
Direct Known Subclasses
ParticipatoryProcessAdminAbility, ParticipatoryProcessCollaboratorAbility, ParticipatoryProcessModeratorAbility
Instance Method Summary collapse
-
#can_manage_process?(process) ⇒ Boolean
Whether the user can manage the given process or not.
- #current_participatory_process ⇒ Object
-
#define_abilities ⇒ Object
Grant access to admin panel by default.
- #define_participatory_process_abilities ⇒ Object
-
#has_manageable_processes? ⇒ Boolean
Whether the user has at least one process to manage or not.
-
#initialize(user, context) ⇒ ParticipatoryProcessRoleAbility
constructor
A new instance of ParticipatoryProcessRoleAbility.
-
#not_admin? ⇒ Boolean
Whether the user is an admin or not.
-
#participatory_processes_with_role_privileges ⇒ Object
Returns a collection of Participatory processes where the given user has the specific role privilege.
-
#role ⇒ Object
Abstract: A subclass must define this method returning a valid role.
Constructor Details
#initialize(user, context) ⇒ ParticipatoryProcessRoleAbility
Returns a new instance of ParticipatoryProcessRoleAbility.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/decidim/abilities/participatory_process_role_ability.rb', line 9 def initialize(user, context) @user = user @context = context # Define abilities if the user is not an admin and has at least one process to manage. if not_admin? && has_manageable_processes? define_abilities if current_participatory_process && can_manage_process?(current_participatory_process) define_participatory_process_abilities end end end |
Instance Method Details
#can_manage_process?(process) ⇒ Boolean
Whether the user can manage the given process or not.
53 54 55 |
# File 'lib/decidim/abilities/participatory_process_role_ability.rb', line 53 def can_manage_process?(process) participatory_processes_with_role_privileges.include? process end |
#current_participatory_process ⇒ Object
57 58 59 |
# File 'lib/decidim/abilities/participatory_process_role_ability.rb', line 57 def current_participatory_process @current_participatory_process ||= @context[:current_participatory_process] end |
#define_abilities ⇒ Object
Grant access to admin panel by default.
24 25 26 |
# File 'lib/decidim/abilities/participatory_process_role_ability.rb', line 24 def define_abilities can :read, :admin_dashboard end |
#define_participatory_process_abilities ⇒ Object
28 |
# File 'lib/decidim/abilities/participatory_process_role_ability.rb', line 28 def define_participatory_process_abilities; end |
#has_manageable_processes? ⇒ Boolean
Whether the user has at least one process to manage or not.
48 49 50 |
# File 'lib/decidim/abilities/participatory_process_role_ability.rb', line 48 def has_manageable_processes? participatory_processes_with_role_privileges.any? end |
#not_admin? ⇒ Boolean
Whether the user is an admin or not.
37 38 39 |
# File 'lib/decidim/abilities/participatory_process_role_ability.rb', line 37 def not_admin? @user && !@user.admin? end |
#participatory_processes_with_role_privileges ⇒ Object
Returns a collection of Participatory processes where the given user has the specific role privilege.
43 44 45 |
# File 'lib/decidim/abilities/participatory_process_role_ability.rb', line 43 def participatory_processes_with_role_privileges @participatory_processes ||= Decidim::ParticipatoryProcessesWithUserRole.for(@user, role) end |
#role ⇒ Object
Abstract: A subclass must define this method returning a valid role. See ParticipatoryProcessUserRoles::ROLES for more information.
32 33 34 |
# File 'lib/decidim/abilities/participatory_process_role_ability.rb', line 32 def role raise "Needs implementation" end |