Sha256: a2f2bf0d9848eafab6c4a89974d9156feb10f64695e26e0c46615fc3a0f2504c

Contents?: true

Size: 1.47 KB

Versions: 8

Compression:

Stored size: 1.47 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 moderated_users_path(blocked: true)
          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 moderated_users_path(blocked: false)
      end

      private

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-admin-0.27.9 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.27.8 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.27.7 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.27.6 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.27.5 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.27.4 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.27.3 app/controllers/decidim/admin/block_user_controller.rb
decidim-admin-0.27.2 app/controllers/decidim/admin/block_user_controller.rb