Sha256: dfe3515a7641bfca7a6eb22bc711a253b55280e53d027bea9ed0742e68014dab

Contents?: true

Size: 1.67 KB

Versions: 10

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

require_dependency "decidim/admin/application_controller"

module Decidim
  module Admin
    # Controller that allows managing feature permissions.
    #
    class FeaturePermissionsController < ApplicationController
      include Concerns::ParticipatoryProcessAdmin
      helper_method :authorizations, :feature

      def edit
        authorize! :update, feature
        @permissions_form = PermissionsForm.new(
          permissions: permission_forms
        )
      end

      def update
        authorize! :update, feature
        @permissions_form = PermissionsForm.from_params(params)

        UpdateFeaturePermissions.call(@permissions_form, feature) do
          on(:ok) do
            flash[:notice] = t("feature_permissions.update.success", scope: "decidim.admin")
            redirect_to participatory_process_features_path(participatory_process)
          end

          on(:invalid) do
            render action: :edit
          end
        end
      end

      private

      def permission_forms
        permissions = feature.permissions || {}

        @permission_forms ||= feature.manifest.actions.inject({}) do |result, action|
          form = PermissionForm.new(
            authorization_handler_name: permissions.dig(action, "authorization_handler_name"),
            options: permissions.dig(action, "options").try(:to_json)
          )

          result.update(action => form)
        end
      end

      def authorizations
        current_organization.available_authorizations.map(&:constantize).map(&:handler_name)
      end

      def feature
        @feature ||= participatory_process.features.find(params[:feature_id])
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
decidim-admin-0.4.0 app/controllers/decidim/admin/feature_permissions_controller.rb
decidim-0.4.0 decidim-admin/app/controllers/decidim/admin/feature_permissions_controller.rb
decidim-admin-0.3.2 app/controllers/decidim/admin/feature_permissions_controller.rb
decidim-0.3.2 decidim-admin/app/controllers/decidim/admin/feature_permissions_controller.rb
decidim-admin-0.3.1 app/controllers/decidim/admin/feature_permissions_controller.rb
decidim-0.3.1 decidim-admin/app/controllers/decidim/admin/feature_permissions_controller.rb
decidim-admin-0.3.0 app/controllers/decidim/admin/feature_permissions_controller.rb
decidim-0.3.0 decidim-admin/app/controllers/decidim/admin/feature_permissions_controller.rb
decidim-admin-0.2.0 app/controllers/decidim/admin/feature_permissions_controller.rb
decidim-0.2.0 decidim-admin/app/controllers/decidim/admin/feature_permissions_controller.rb