Sha256: 5b01d743ce8aa689c5294d2886242892ff4b84ca351983ed53c232fe02fab630

Contents?: true

Size: 1.74 KB

Versions: 15

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # Controller that allows managing the user organization.
    #
    class OrganizationController < Decidim::Admin::ApplicationController
      layout "decidim/admin/settings"

      def edit
        enforce_permission_to :update, :organization, organization: current_organization
        @form = form(OrganizationForm).from_model(current_organization)
      end

      def update
        enforce_permission_to :update, :organization, organization: current_organization
        @form = form(OrganizationForm).from_params(params)

        UpdateOrganization.call(current_organization, @form) do
          on(:ok) do
            flash[:notice] = I18n.t("organization.update.success", scope: "decidim.admin")
            redirect_to edit_organization_path
          end

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

      def users
        respond_to do |format|
          format.json do
            if (term = params[:term].to_s).present?
              query = current_organization.users.order(name: :asc)
              query = if term.start_with?("@")
                        query.where("nickname ILIKE ?", "#{term.delete("@")}%")
                      else
                        query.where("name ILIKE ?", "%#{term}%").or(
                          query.where("email ILIKE ?", "%#{term}%")
                        )
                      end
              render json: query.all.collect { |u| { value: u.id, label: "#{u.name} (@#{u.nickname}) #{u.email}" } }
            else
              render json: []
            end
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
decidim-admin-0.24.3 app/controllers/decidim/admin/organization_controller.rb
decidim-admin-0.23.6 app/controllers/decidim/admin/organization_controller.rb
decidim-admin-0.24.2 app/controllers/decidim/admin/organization_controller.rb
decidim-admin-0.23.5 app/controllers/decidim/admin/organization_controller.rb
decidim-admin-0.24.1 app/controllers/decidim/admin/organization_controller.rb
decidim-admin-0.24.0 app/controllers/decidim/admin/organization_controller.rb
decidim-admin-0.24.0.rc2 app/controllers/decidim/admin/organization_controller.rb
decidim-admin-0.23.4 app/controllers/decidim/admin/organization_controller.rb
decidim-admin-0.24.0.rc1 app/controllers/decidim/admin/organization_controller.rb
decidim-admin-0.23.3 app/controllers/decidim/admin/organization_controller.rb
decidim-admin-0.23.2 app/controllers/decidim/admin/organization_controller.rb
decidim-admin-0.23.1 app/controllers/decidim/admin/organization_controller.rb
decidim-admin-0.23.1.rc1 app/controllers/decidim/admin/organization_controller.rb
decidim-admin-0.23.0 app/controllers/decidim/admin/organization_controller.rb
decidim-admin-0.22.0 app/controllers/decidim/admin/organization_controller.rb