Sha256: be85ac8cdf4fbd432e6f629a25f9678dfd61efe2067d8cd3cb826bd251e46432

Contents?: true

Size: 1.25 KB

Versions: 19

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Decidim
  module Votings
    class Permissions < Decidim::DefaultPermissions
      def permissions
        allowed_public_anonymous_action?

        return permission_action unless user

        return Decidim::Votings::Admin::Permissions.new(user, permission_action, context).permissions if admin_scope?

        # Delegate the polling_officer_zone permission checks to the polling officer zone permissions class
        return Decidim::Votings::PollingOfficerZone::Permissions.new(user, permission_action, context).permissions if permission_action.scope == :polling_officer_zone

        permission_action
      end

      private

      def voting
        @voting ||= context.fetch(:voting, nil)
      end

      def allowed_public_anonymous_action?
        return unless permission_action.action == :read
        return unless permission_action.scope == :public

        case permission_action.subject
        when :votings
          allow!
        when :voting
          toggle_allow(voting.published? || user&.admin?)
        when :participatory_space
          allow!
        end
      end

      def admin_scope?
        permission_action.scope == :admin || permission_action.subject == :admin_dashboard
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-elections-0.26.10 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.26.9 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.26.8 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.26.7 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.26.5 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.26.4 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.26.3 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.26.2 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.26.1 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.26.0 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.26.0.rc2 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.26.0.rc1 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.25.2 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.25.1 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.25.0 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.25.0.rc4 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.25.0.rc3 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.25.0.rc2 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.25.0.rc1 app/permissions/decidim/votings/permissions.rb