Sha256: d36c04708889540f2edc81b6f4fb40559205fafe8c91714b99d7a46a327db478

Contents?: true

Size: 840 Bytes

Versions: 11

Compression:

Stored size: 840 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Debates
    class Permissions < Decidim::DefaultPermissions
      def permissions
        # Delegate the admin permission checks to the admin permissions class
        return Decidim::Debates::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 != :debate

        case permission_action.action
        when :create
          toggle_allow(can_create_debate?)
        when :report
          allow!
        end

        permission_action
      end

      private

      def can_create_debate?
        authorized?(:create) &&
          current_settings&.creation_enabled?
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
decidim-debates-0.14.4 app/permissions/decidim/debates/permissions.rb
decidim-debates-0.14.3 app/permissions/decidim/debates/permissions.rb
decidim-debates-0.14.2 app/permissions/decidim/debates/permissions.rb
decidim-debates-0.14.1 app/permissions/decidim/debates/permissions.rb
decidim-debates-0.13.1 app/permissions/decidim/debates/permissions.rb
decidim-debates-0.12.2 app/permissions/decidim/debates/permissions.rb
decidim-debates-0.13.0 app/permissions/decidim/debates/permissions.rb
decidim-debates-0.12.1 app/permissions/decidim/debates/permissions.rb
decidim-debates-0.13.0.pre1 app/permissions/decidim/debates/permissions.rb
decidim-debates-0.12.0 app/permissions/decidim/debates/permissions.rb
decidim-debates-0.12.0.pre app/permissions/decidim/debates/permissions.rb