Sha256: a15552a91d22d825d59c9f2466fe7cf26192a448ad53cbbe4cc253c5f1826100

Contents?: true

Size: 1.71 KB

Versions: 35

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

module Decidim
  module System
    # Controller to manage Organizations (tenants).
    #
    class OrganizationsController < Decidim::System::ApplicationController
      helper_method :current_organization

      def new
        @form = form(RegisterOrganizationForm).instance
      end

      def create
        @form = form(RegisterOrganizationForm).from_params(params)

        RegisterOrganization.call(@form) do
          on(:ok) do
            flash[:notice] = t("organizations.create.success", scope: "decidim.system")
            redirect_to organizations_path
          end

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

      def index
        @organizations = Organization.all
      end

      def show
        @organization = Organization.find(params[:id])
      end

      def edit
        organization = Organization.find(params[:id])
        @form = form(UpdateOrganizationForm).from_model(organization)
      end

      def update
        @form = form(UpdateOrganizationForm).from_params(params)

        UpdateOrganization.call(params[:id], @form) do
          on(:ok) do
            flash[:notice] = t("organizations.update.success", scope: "decidim.system")
            redirect_to organizations_path
          end

          on(:invalid) do
            flash.now[:alert] = I18n.t("organizations.update.error", scope: "decidim.system")
            render :edit
          end
        end
      end

      # The current organization for the request.
      #
      # Returns an Organization.
      def current_organization
        @organization
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
decidim-system-0.20.1 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.20.0 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.19.1 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.18.1 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.19.0 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.17.2 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.18.0 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.17.1 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.16.1 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.17.0 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.16.0 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.15.2 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.15.1 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.15.0 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.14.4 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.14.3 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.14.2 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.14.1 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.13.1 app/controllers/decidim/system/organizations_controller.rb
decidim-system-0.12.2 app/controllers/decidim/system/organizations_controller.rb