Sha256: 8e617e64674a3118f127261439483882065e308e38c2f8a36fd9ba78d004c402

Contents?: true

Size: 1.72 KB

Versions: 32

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

require_dependency "decidim/admin/application_controller"

module Decidim
  module Admin
    # Controller that allows managing managed users at the admin panel.
    #
    class ManagedUsersController < Admin::ApplicationController
      layout "decidim/admin/users"

      helper_method :available_authorizations, :more_than_one_authorization?

      def index
        authorize! :index, :managed_users
        @managed_users = collection.page(params[:page]).per(15)
      end

      def new
        authorize! :new, :managed_users

        if handler_name.present?
          @form = form(ManagedUserForm).from_params(
            authorization: {
              handler_name: handler_name
            }
          )
        end
      end

      def create
        authorize! :create, :managed_users

        @form = form(ManagedUserForm).from_params(params)

        CreateManagedUser.call(@form) do
          on(:ok) do
            flash[:notice] = I18n.t("managed_users.create.success", scope: "decidim.admin")
            redirect_to managed_users_path
          end

          on(:invalid) do
            flash.now[:alert] = I18n.t("managed_users.create.error", scope: "decidim.admin")
            render :new
          end
        end
      end

      private

      def collection
        @collection ||= current_organization.users.managed
      end

      def handler_name
        return params[:handler_name] if more_than_one_authorization?
        available_authorizations.first
      end

      def available_authorizations
        current_organization.available_authorizations.map(&:underscore)
      end

      def more_than_one_authorization?
        available_authorizations.length > 1
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
decidim-admin-0.8.4 app/controllers/decidim/admin/managed_users_controller.rb
decidim-admin-0.8.3 app/controllers/decidim/admin/managed_users_controller.rb
decidim-admin-0.8.2 app/controllers/decidim/admin/managed_users_controller.rb
decidim-admin-0.8.1 app/controllers/decidim/admin/managed_users_controller.rb
decidim-admin-0.8.0 app/controllers/decidim/admin/managed_users_controller.rb
decidim-admin-0.7.4 app/controllers/decidim/admin/managed_users_controller.rb
decidim-admin-0.7.3 app/controllers/decidim/admin/managed_users_controller.rb
decidim-admin-0.7.2 app/controllers/decidim/admin/managed_users_controller.rb
decidim-admin-0.7.1 app/controllers/decidim/admin/managed_users_controller.rb
decidim-admin-0.7.0 app/controllers/decidim/admin/managed_users_controller.rb
decidim-admin-0.6.8 app/controllers/decidim/admin/managed_users_controller.rb
decidim-0.6.8 decidim-admin/app/controllers/decidim/admin/managed_users_controller.rb
decidim-admin-0.6.7 app/controllers/decidim/admin/managed_users_controller.rb
decidim-0.6.7 decidim-admin/app/controllers/decidim/admin/managed_users_controller.rb
decidim-admin-0.6.6 app/controllers/decidim/admin/managed_users_controller.rb
decidim-0.6.6 decidim-admin/app/controllers/decidim/admin/managed_users_controller.rb
decidim-admin-0.6.5 app/controllers/decidim/admin/managed_users_controller.rb
decidim-0.6.5 decidim-admin/app/controllers/decidim/admin/managed_users_controller.rb
decidim-admin-0.6.4 app/controllers/decidim/admin/managed_users_controller.rb
decidim-0.6.4 decidim-admin/app/controllers/decidim/admin/managed_users_controller.rb