Sha256: 9e5d7f1a62195537a9072c790b5edf519ce6f20ae7a36e9d906b56148c34b3d8

Contents?: true

Size: 1.92 KB

Versions: 10

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    module Abilities
      # Defines the abilities for a participatory process admin in the admin
      # section. Intended to be used with `cancancan`. This is not intended to
      # extend the base `Decidim::Ability` class, it should only be used in the
      # Admin engine.
      #
      # This ability will not apply to organization admins.
      class ParticipatoryProcessAdmin
        include CanCan::Ability

        def initialize(user, _context)
          @user = user

          return unless user && !user.role?(:admin) && !user.role?(:collaborator)

          can :read, :admin_dashboard do
            participatory_processes.any?
          end

          can :manage, ParticipatoryProcess do |process|
            participatory_processes.include?(process)
          end

          cannot :create, ParticipatoryProcess
          cannot :destroy, ParticipatoryProcess

          cannot :manage, :admin_users

          can :manage, ParticipatoryProcessUserRole do |role|
            role.user != user
          end

          can :manage, Moderation do |moderation|
            participatory_processes.include?(moderation.participatory_process)
          end

          can :manage, Attachment do |attachment|
            participatory_processes.include?(attachment.attached_to)
          end

          can :manage, ParticipatoryProcessStep do |step|
            participatory_processes.include?(step.participatory_process)
          end

          can :manage, Feature do |feature|
            participatory_processes.include?(feature.participatory_process)
          end

          can :manage, Category do |category|
            participatory_processes.include?(category.participatory_process)
          end
        end

        def participatory_processes
          @participatory_processes ||= ManageableParticipatoryProcessesForUser.for(@user)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
decidim-admin-0.4.0 app/models/decidim/admin/abilities/participatory_process_admin.rb
decidim-0.4.0 decidim-admin/app/models/decidim/admin/abilities/participatory_process_admin.rb
decidim-admin-0.3.2 app/models/decidim/admin/abilities/participatory_process_admin.rb
decidim-0.3.2 decidim-admin/app/models/decidim/admin/abilities/participatory_process_admin.rb
decidim-admin-0.3.1 app/models/decidim/admin/abilities/participatory_process_admin.rb
decidim-0.3.1 decidim-admin/app/models/decidim/admin/abilities/participatory_process_admin.rb
decidim-admin-0.3.0 app/models/decidim/admin/abilities/participatory_process_admin.rb
decidim-0.3.0 decidim-admin/app/models/decidim/admin/abilities/participatory_process_admin.rb
decidim-admin-0.2.0 app/models/decidim/admin/abilities/participatory_process_admin.rb
decidim-0.2.0 decidim-admin/app/models/decidim/admin/abilities/participatory_process_admin.rb