Sha256: 9115ce1d1f02be802ce3531b898cd1371303ed3dfeb3daafa1cb82a14c25e040

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

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

        def new
          enforce_permission_to(:promote, :managed_user, user:)
          @form = form(ManagedUserPromotionForm).instance
        end

        def create
          enforce_permission_to(:promote, :managed_user, user:)
          @form = form(ManagedUserPromotionForm).from_params(params)

          PromoteManagedUser.call(@form, user) do
            on(:ok) do
              flash[:notice] = I18n.t("managed_users.promotion.success", scope: "decidim.admin")
              redirect_to impersonatable_users_path
            end

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

        private

        def user
          @user ||= current_organization.users.managed.find(params[:impersonatable_user_id])
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-admin-0.29.1 app/controllers/decidim/admin/managed_users/promotions_controller.rb
decidim-admin-0.29.0 app/controllers/decidim/admin/managed_users/promotions_controller.rb
decidim-admin-0.29.0.rc4 app/controllers/decidim/admin/managed_users/promotions_controller.rb
decidim-admin-0.29.0.rc3 app/controllers/decidim/admin/managed_users/promotions_controller.rb
decidim-admin-0.29.0.rc2 app/controllers/decidim/admin/managed_users/promotions_controller.rb
decidim-admin-0.29.0.rc1 app/controllers/decidim/admin/managed_users/promotions_controller.rb