Class: Decidim::DecidimAwesome::Admin::ConfigController

Inherits:
ApplicationController
  • Object
show all
Includes:
ConfigConstraintsHelpers, NeedsAwesomeConfig
Defined in:
app/controllers/decidim/decidim_awesome/admin/config_controller.rb

Overview

Global configuration controller

Constant Summary

Constants included from ConfigConstraintsHelpers

Decidim::DecidimAwesome::Admin::ConfigConstraintsHelpers::OTHER_MANIFESTS

Instance Method Summary collapse

Methods included from ConfigConstraintsHelpers

#check, #component_manifests, #components_list, #enabled_configs, #md5, #participatory_space_manifests, #participatory_spaces_list, #translate_constraint_value

Methods included from NeedsAwesomeConfig

extended, included

Methods inherited from ApplicationController

#permission_class_chain

Instance Method Details

#rename_scope_labelObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/decidim/decidim_awesome/admin/config_controller.rb', line 58

def rename_scope_label
  RenameScopeLabel.call(params, current_organization) do
    on(:ok) do |result|
      render json: result.merge({
                                  html: render_to_string(partial: "decidim/decidim_awesome/admin/config/constraints",
                                                         locals: {
                                                           key: result[:scope],
                                                           constraints: constraints_for(result[:scope])
                                                         })
                                })
    end

    on(:invalid) do |message|
      render json: { error: message }, status: :unprocessable_entity
    end
  end
end

#showObject



17
18
19
20
21
# File 'app/controllers/decidim/decidim_awesome/admin/config_controller.rb', line 17

def show
  @form = form(ConfigForm).from_params(organization_awesome_config)

  redirect_to decidim_admin_decidim_awesome.checks_maintenance_index_path unless config_var
end

#updateObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/decidim/decidim_awesome/admin/config_controller.rb', line 23

def update
  @form = form(ConfigForm).from_params(params[:config])
  UpdateConfig.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("config.update.success", scope: "decidim.decidim_awesome.admin")
      redirect_to decidim_admin_decidim_awesome.config_path
    end

    on(:invalid) do |message, err|
      flash.now[:alert] = I18n.t("config.update.error", error: message, scope: "decidim.decidim_awesome.admin")
      render :show, locals: { errors: err.presence }
    end
  end
end

#usersObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/decidim/decidim_awesome/admin/config_controller.rb', line 38

def users
  respond_to do |format|
    format.json do
      if (term = params[:term].to_s).present?
        query = current_organization.users.order(name: :asc)
        query = query.where("name ILIKE :term OR nickname ILIKE :term OR email ILIKE :term", term: "%#{term}%")
        render json: query.all.collect { |u|
                       {
                         value: u.id,
                         text: format_user_name(u),
                         is_admin: u.read_attribute("admin")
                       }
                     }
      else
        render json: []
      end
    end
  end
end