Sha256: 938ff6695617f2ba840b2fd82465db27772d99900812c7c3c9ce1065a43b422c

Contents?: true

Size: 1.15 KB

Versions: 25

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    module Admin
      class Permissions < Decidim::DefaultPermissions
        def permissions
          return permission_action if permission_action.scope != :admin

          case permission_action.subject
          when :budget
            case permission_action.action
            when :create, :read, :export
              allow!
            when :update
              toggle_allow(budget)
            when :delete, :publish, :unpublish
              toggle_allow(budget && budget.projects.empty?)
            end
          when :project, :projects
            case permission_action.action
            when :create
              permission_action.allow!
            when :import_proposals
              permission_action.allow!
            when :update, :destroy
              permission_action.allow! if project.present?
            end
          end

          permission_action
        end

        private

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

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

Version data entries

25 entries across 25 versions & 1 rubygems

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