Sha256: b911f6f0c6bbed662224fd73586dd2ece603fd852945643d2ab0a457d7c90889

Contents?: true

Size: 1.09 KB

Versions: 20

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    class Permissions < Decidim::DefaultPermissions
      def permissions
        return permission_action unless user

        # Delegate the admin permission checks to the admin permissions class
        return Decidim::Budgets::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 != :project

        case permission_action.action
        when :vote
          can_vote_project?(project || order&.projects&.first)
        when :report
          permission_action.allow!
        end

        permission_action
      end

      private

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

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

      def can_vote_project?(a_project)
        is_allowed = a_project && authorized?(:vote, resource: project)

        toggle_allow(is_allowed)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
decidim-budgets-0.22.0 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.21.0 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.20.1 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.20.0 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.19.1 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.18.1 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.19.0 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.17.2 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.18.0 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.17.1 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.16.1 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.17.0 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.16.0 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.15.2 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.15.1 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.15.0 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.14.4 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.14.3 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.14.2 app/permissions/decidim/budgets/permissions.rb
decidim-budgets-0.14.1 app/permissions/decidim/budgets/permissions.rb