Sha256: c1c1ad7a8e798ddaca132ed5285d72e704669c7cb436588182412f021dd9a5c0

Contents?: true

Size: 1.22 KB

Versions: 19

Compression:

Stored size: 1.22 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, :participatory_space
          allow!
        when :voting
          toggle_allow(voting.published? || user&.admin?)
        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.28.4 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.27.9 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.28.3 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.27.8 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.28.2 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.27.7 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.28.1 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.27.6 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.28.0 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.27.5 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.28.0.rc5 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.28.0.rc4 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.27.4 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.27.3 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.27.2 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.27.1 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.27.0 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.27.0.rc2 app/permissions/decidim/votings/permissions.rb
decidim-elections-0.27.0.rc1 app/permissions/decidim/votings/permissions.rb