Sha256: 3f701a17c295ba4c99cc92acaee72495deb20d9ccbbe4111694b3ec634140fd0

Contents?: true

Size: 1.56 KB

Versions: 24

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    class BlockUserController < Decidim::Admin::ApplicationController
      layout "decidim/admin/users"

      helper_method :user

      def new
        enforce_permission_to :block, :admin_user

        @form = form(BlockUserForm).from_model(user)
      end

      def create
        enforce_permission_to :block, :admin_user

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

        BlockUser.call(@form) do
          on(:ok) do
            flash[:notice] = I18n.t("officializations.block.success", scope: "decidim.admin")
            redirect_to officializations_path(q: { name_or_nickname_or_email_cont: user.name }), notice: notice
          end

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

      def destroy
        enforce_permission_to :block, :admin_user

        UnblockUser.call(user, current_user) do
          on(:ok) do
            flash[:notice] = I18n.t("officializations.unblock.success", scope: "decidim.admin")
          end

          on(:invalid) do
            flash[:alert] = I18n.t("officializations.unblock.error", scope: "decidim.admin")
          end
        end

        redirect_to officializations_path(q: { name_or_nickname_or_email_cont: user.name }), notice: notice
      end

      private

      def user
        @user ||= Decidim::User.find_by(
          id: params[:user_id],
          organization: current_organization
        )
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
decidim-admin-0.27.1 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.26.4 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.27.0 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.26.3 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.27.0.rc2 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.27.0.rc1 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.26.2 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.26.1 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.26.0 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.26.0.rc2 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.26.0.rc1 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.25.2 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.25.1 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.25.0 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.25.0.rc4 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.25.0.rc3 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.25.0.rc2 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.25.0.rc1 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.24.3 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.24.2 app/controllers/decidim/admin/block_user_controller.rb