decidim-admin 0.0.1.alpha9 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of decidim-admin might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +33 -8
- data/Rakefile +0 -25
- data/app/assets/javascripts/decidim/admin/application.js.es6 +17 -10
- data/app/assets/javascripts/decidim/admin/sort_steps.js.es6 +20 -11
- data/app/assets/javascripts/decidim/admin/tab_focus.js.es6 +22 -0
- data/app/assets/stylesheets/decidim/admin/_forms.scss +10 -0
- data/app/assets/stylesheets/decidim/admin/_layout.scss +11 -0
- data/app/assets/stylesheets/decidim/admin/_tables.scss +4 -0
- data/app/assets/stylesheets/decidim/admin/application.scss +8 -2
- data/app/commands/decidim/admin/activate_participatory_process_step.rb +1 -1
- data/app/commands/decidim/admin/create_category.rb +44 -0
- data/app/commands/decidim/admin/create_feature.rb +48 -0
- data/app/commands/decidim/admin/create_participatory_process.rb +3 -6
- data/app/commands/decidim/admin/create_participatory_process_admin.rb +51 -0
- data/app/commands/decidim/admin/create_participatory_process_attachment.rb +44 -0
- data/app/commands/decidim/admin/create_participatory_process_step.rb +3 -3
- data/app/commands/decidim/admin/create_scope.rb +38 -0
- data/app/commands/decidim/admin/create_static_page.rb +40 -0
- data/app/commands/decidim/admin/destroy_category.rb +36 -0
- data/app/commands/decidim/admin/destroy_feature.rb +39 -0
- data/app/commands/decidim/admin/publish_participatory_process.rb +1 -1
- data/app/commands/decidim/admin/reorder_participatory_process_steps.rb +5 -2
- data/app/commands/decidim/admin/unpublish_participatory_process.rb +1 -1
- data/app/commands/decidim/admin/update_category.rb +48 -0
- data/app/commands/decidim/admin/update_organization.rb +49 -0
- data/app/commands/decidim/admin/update_participatory_process.rb +2 -2
- data/app/commands/decidim/admin/update_participatory_process_attachment.rb +49 -0
- data/app/commands/decidim/admin/update_participatory_process_step.rb +1 -1
- data/app/commands/decidim/admin/update_scope.rb +43 -0
- data/app/commands/decidim/admin/update_static_page.rb +45 -0
- data/app/constraints/decidim/admin/organization_dashboard_constraint.rb +5 -1
- data/app/controllers/decidim/admin/application_controller.rb +8 -0
- data/app/controllers/decidim/admin/categories_controller.rb +90 -0
- data/app/controllers/decidim/admin/concerns/participatory_process_admin.rb +31 -0
- data/app/controllers/decidim/admin/features_controller.rb +74 -0
- data/app/controllers/decidim/admin/organization_controller.rb +40 -0
- data/app/controllers/decidim/admin/participatory_process_attachments_controller.rb +84 -0
- data/app/controllers/decidim/admin/participatory_process_publications_controller.rb +2 -7
- data/app/controllers/decidim/admin/participatory_process_step_activations_controller.rb +6 -8
- data/app/controllers/decidim/admin/participatory_process_step_ordering_controller.rb +2 -4
- data/app/controllers/decidim/admin/participatory_process_steps_controller.rb +13 -11
- data/app/controllers/decidim/admin/participatory_process_user_roles_controller.rb +54 -0
- data/app/controllers/decidim/admin/participatory_processes_controller.rb +11 -6
- data/app/controllers/decidim/admin/scopes_controller.rb +79 -0
- data/app/controllers/decidim/admin/static_pages_controller.rb +94 -0
- data/app/forms/decidim/admin/category_form.rb +37 -0
- data/app/forms/decidim/admin/feature_form.rb +16 -0
- data/app/forms/decidim/admin/organization_form.rb +31 -0
- data/app/forms/decidim/admin/participatory_process_attachment_form.rb +19 -0
- data/app/forms/decidim/admin/participatory_process_form.rb +4 -7
- data/app/forms/decidim/admin/participatory_process_step_form.rb +12 -2
- data/app/forms/decidim/admin/participatory_process_user_role_form.rb +15 -0
- data/app/forms/decidim/admin/scope_form.rb +24 -0
- data/app/forms/decidim/admin/static_page_form.rb +30 -0
- data/app/helpers/decidim/admin/application_helper.rb +1 -0
- data/app/helpers/decidim/admin/aria_selected_link_to_helper.rb +28 -0
- data/app/helpers/decidim/admin/attributes_display_helper.rb +13 -5
- data/app/models/decidim/admin/abilities/admin_user.rb +34 -0
- data/app/models/decidim/admin/abilities/base.rb +19 -0
- data/app/models/decidim/admin/abilities/participatory_process_admin.rb +51 -0
- data/app/models/decidim/admin/participatory_process_user_role.rb +14 -0
- data/app/queries/decidim/admin/manageable_participatory_processes_for_user.rb +41 -0
- data/app/queries/decidim/admin/process_admin_roles_for_process.rb +35 -0
- data/app/views/decidim/admin/categories/_form.html.erb +12 -0
- data/app/views/decidim/admin/categories/edit.html.erb +9 -0
- data/app/views/decidim/admin/categories/index.html.erb +44 -0
- data/app/views/decidim/admin/categories/new.html.erb +9 -0
- data/app/views/decidim/admin/categories/show.html.erb +14 -0
- data/app/views/decidim/admin/features/_feature.html.erb +20 -0
- data/app/views/decidim/admin/features/_form.html.erb +3 -0
- data/app/views/decidim/admin/features/index.html.erb +23 -0
- data/app/views/decidim/admin/features/new.html.erb +9 -0
- data/app/views/decidim/admin/organization/_form.html.erb +23 -0
- data/app/views/decidim/admin/organization/edit.html.erb +11 -0
- data/app/views/decidim/admin/participatory_process_attachments/_form.html.erb +11 -0
- data/app/views/decidim/admin/participatory_process_attachments/edit.html.erb +9 -0
- data/app/views/decidim/admin/participatory_process_attachments/index.html.erb +37 -0
- data/app/views/decidim/admin/participatory_process_attachments/new.html.erb +9 -0
- data/app/views/decidim/admin/participatory_process_attachments/show.html.erb +25 -0
- data/app/views/decidim/admin/participatory_process_steps/_form.html.erb +2 -2
- data/app/views/decidim/admin/participatory_process_steps/edit.html.erb +1 -3
- data/app/views/decidim/admin/participatory_process_steps/{_table.html.erb → index.html.erb} +15 -11
- data/app/views/decidim/admin/participatory_process_steps/new.html.erb +1 -3
- data/app/views/decidim/admin/participatory_process_steps/show.html.erb +1 -4
- data/app/views/decidim/admin/participatory_process_user_roles/index.html.erb +34 -0
- data/app/views/decidim/admin/participatory_processes/_form.html.erb +2 -2
- data/app/views/decidim/admin/participatory_processes/edit.html.erb +13 -3
- data/app/views/decidim/admin/participatory_processes/index.html.erb +5 -14
- data/app/views/decidim/admin/participatory_processes/show.html.erb +19 -36
- data/app/views/decidim/admin/scopes/_form.html.erb +3 -0
- data/app/views/decidim/admin/scopes/edit.html.erb +11 -0
- data/app/views/decidim/admin/scopes/index.html.erb +38 -0
- data/app/views/decidim/admin/scopes/new.html.erb +11 -0
- data/app/views/decidim/admin/static_pages/_form.html.erb +13 -0
- data/app/views/decidim/admin/static_pages/edit.html.erb +11 -0
- data/app/views/decidim/admin/static_pages/index.html.erb +40 -0
- data/app/views/decidim/admin/static_pages/new.html.erb +11 -0
- data/app/views/decidim/admin/static_pages/show.html.erb +22 -0
- data/app/views/layouts/decidim/admin/_application.html.erb +40 -0
- data/app/views/layouts/decidim/admin/_sidebar.html.erb +5 -2
- data/app/views/layouts/decidim/admin/application.html.erb +3 -40
- data/app/views/layouts/decidim/admin/participatory_process.html.erb +54 -0
- data/config/i18n-tasks.yml +3 -2
- data/config/locales/ca.yml +138 -6
- data/config/locales/en.yml +191 -13
- data/config/locales/es.yml +139 -7
- data/config/routes.rb +23 -1
- data/db/migrate/20161102144648_add_admin_participatory_process_user_roles.rb +15 -0
- data/db/seeds.rb +21 -0
- data/lib/decidim/admin/engine.rb +10 -3
- data/lib/decidim/admin/features/base_controller.rb +33 -0
- data/lib/decidim/admin/features.rb +10 -0
- data/lib/decidim/admin.rb +1 -0
- data/vendor/assets/javascripts/html.sortable.js +691 -0
- metadata +98 -33
- data/LICENSE.txt +0 -619
- data/app/models/decidim/admin/abilities/admin.rb +0 -21
- data/vendor/assets/javascripts/html.sortable.min.js +0 -2
@@ -12,7 +12,7 @@ module Decidim
|
|
12
12
|
@order = order
|
13
13
|
end
|
14
14
|
|
15
|
-
# Executes the command.
|
15
|
+
# Executes the command. Broadcasts these events:
|
16
16
|
#
|
17
17
|
# - :ok when everything is valid.
|
18
18
|
# - :invalid if the data wasn't valid and we couldn't proceed.
|
@@ -34,7 +34,10 @@ module Decidim
|
|
34
34
|
hash.update(id => { position: index })
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
ParticipatoryProcessStep.transaction do
|
38
|
+
collection.update_all(position: nil)
|
39
|
+
collection.update(data.keys, data.values)
|
40
|
+
end
|
38
41
|
end
|
39
42
|
|
40
43
|
def order
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
# A command with all the business logic when updating a category in the
|
5
|
+
# system.
|
6
|
+
class UpdateCategory < Rectify::Command
|
7
|
+
attr_reader :category
|
8
|
+
|
9
|
+
# Public: Initializes the command.
|
10
|
+
#
|
11
|
+
# category - the Category to update
|
12
|
+
# form - A form object with the params.
|
13
|
+
def initialize(category, form)
|
14
|
+
@category = category
|
15
|
+
@form = form
|
16
|
+
end
|
17
|
+
|
18
|
+
# Executes the command. Broadcasts these events:
|
19
|
+
#
|
20
|
+
# - :ok when everything is valid.
|
21
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
def call
|
25
|
+
return broadcast(:invalid) if form.invalid?
|
26
|
+
|
27
|
+
update_category
|
28
|
+
broadcast(:ok)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :form
|
34
|
+
|
35
|
+
def update_category
|
36
|
+
category.update_attributes!(attributes)
|
37
|
+
end
|
38
|
+
|
39
|
+
def attributes
|
40
|
+
{
|
41
|
+
name: form.name,
|
42
|
+
parent_id: form.parent_id,
|
43
|
+
description: form.description
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
# A command with all the business logic for updating the current
|
5
|
+
# organization.
|
6
|
+
class UpdateOrganization < Rectify::Command
|
7
|
+
# Public: Initializes the command.
|
8
|
+
#
|
9
|
+
# organization - The Organization that will be updated.
|
10
|
+
# form - A form object with the params.
|
11
|
+
def initialize(organization, form)
|
12
|
+
@organization = organization
|
13
|
+
@form = form
|
14
|
+
end
|
15
|
+
|
16
|
+
# Executes the command. Broadcasts these events:
|
17
|
+
#
|
18
|
+
# - :ok when everything is valid.
|
19
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
20
|
+
#
|
21
|
+
# Returns nothing.
|
22
|
+
def call
|
23
|
+
return broadcast(:invalid) if form.invalid?
|
24
|
+
|
25
|
+
update_organization
|
26
|
+
broadcast(:ok)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :form, :organization
|
32
|
+
|
33
|
+
def update_organization
|
34
|
+
organization.update_attributes!(attributes)
|
35
|
+
end
|
36
|
+
|
37
|
+
def attributes
|
38
|
+
{
|
39
|
+
name: form.name,
|
40
|
+
description: form.description,
|
41
|
+
welcome_text: form.welcome_text,
|
42
|
+
homepage_image: form.homepage_image || organization.homepage_image,
|
43
|
+
logo: form.logo || organization.logo,
|
44
|
+
default_locale: form.default_locale
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -13,7 +13,7 @@ module Decidim
|
|
13
13
|
@form = form
|
14
14
|
end
|
15
15
|
|
16
|
-
# Executes the command.
|
16
|
+
# Executes the command. Broadcasts these events:
|
17
17
|
#
|
18
18
|
# - :ok when everything is valid.
|
19
19
|
# - :invalid if the form wasn't valid and we couldn't proceed.
|
@@ -45,7 +45,7 @@ module Decidim
|
|
45
45
|
promoted: form.promoted,
|
46
46
|
description: form.description,
|
47
47
|
short_description: form.short_description
|
48
|
-
}
|
48
|
+
}.compact
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
# A command with all the business logic to update an attachment from a
|
5
|
+
# participatory process.
|
6
|
+
class UpdateParticipatoryProcessAttachment < Rectify::Command
|
7
|
+
attr_reader :participatory_process_attachment
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# participatory_process_attachment - the ParticipatoryProcessAttachment to update
|
11
|
+
# form - A form object with the params.
|
12
|
+
def initialize(participatory_process_attachment, form)
|
13
|
+
@participatory_process_attachment = participatory_process_attachment
|
14
|
+
@form = form
|
15
|
+
end
|
16
|
+
|
17
|
+
# Executes the command. Broadcasts these events:
|
18
|
+
#
|
19
|
+
# - :ok when everything is valid.
|
20
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
21
|
+
#
|
22
|
+
# Returns nothing.
|
23
|
+
def call
|
24
|
+
return broadcast(:invalid) if form.invalid?
|
25
|
+
|
26
|
+
update_attachment
|
27
|
+
broadcast(:ok)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_reader :form
|
33
|
+
|
34
|
+
def update_attachment
|
35
|
+
participatory_process_attachment.update_attributes!(attributes)
|
36
|
+
end
|
37
|
+
|
38
|
+
def attributes
|
39
|
+
{
|
40
|
+
title: form.title,
|
41
|
+
file: form.file,
|
42
|
+
description: form.description
|
43
|
+
}.reject do |_attribute, value|
|
44
|
+
value.blank?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
# A command with all the business logic when updating a scope.
|
5
|
+
class UpdateScope < Rectify::Command
|
6
|
+
# Public: Initializes the command.
|
7
|
+
#
|
8
|
+
# scope - The Scope to update
|
9
|
+
# form - A form object with the params.
|
10
|
+
def initialize(scope, form)
|
11
|
+
@scope = scope
|
12
|
+
@form = form
|
13
|
+
end
|
14
|
+
|
15
|
+
# Executes the command. Broadcasts these events:
|
16
|
+
#
|
17
|
+
# - :ok when everything is valid.
|
18
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def call
|
22
|
+
return broadcast(:invalid) if form.invalid?
|
23
|
+
|
24
|
+
update_scope
|
25
|
+
broadcast(:ok)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :form
|
31
|
+
|
32
|
+
def update_scope
|
33
|
+
@scope.update_attributes!(attributes)
|
34
|
+
end
|
35
|
+
|
36
|
+
def attributes
|
37
|
+
{
|
38
|
+
name: form.name
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
# A command with all the business logic when updating a static page.
|
5
|
+
class UpdateStaticPage < Rectify::Command
|
6
|
+
# Public: Initializes the command.
|
7
|
+
#
|
8
|
+
# page - The StaticPage to update
|
9
|
+
# form - A form object with the params.
|
10
|
+
def initialize(page, form)
|
11
|
+
@page = page
|
12
|
+
@form = form
|
13
|
+
end
|
14
|
+
|
15
|
+
# Executes the command. Broadcasts these events:
|
16
|
+
#
|
17
|
+
# - :ok when everything is valid.
|
18
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def call
|
22
|
+
return broadcast(:invalid) if form.invalid?
|
23
|
+
|
24
|
+
update_page
|
25
|
+
broadcast(:ok)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :form
|
31
|
+
|
32
|
+
def update_page
|
33
|
+
@page.update_attributes!(attributes)
|
34
|
+
end
|
35
|
+
|
36
|
+
def attributes
|
37
|
+
{
|
38
|
+
title: form.title,
|
39
|
+
slug: form.slug,
|
40
|
+
content: form.content
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -15,7 +15,7 @@ module Decidim
|
|
15
15
|
#
|
16
16
|
# Returns boolean.
|
17
17
|
def matches?
|
18
|
-
user.organization == organization &&
|
18
|
+
user.organization == organization && ability.can?(:read, :admin_dashboard)
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
@@ -31,6 +31,10 @@ module Decidim
|
|
31
31
|
|
32
32
|
@user ||= request.env["warden"].user("user")
|
33
33
|
end
|
34
|
+
|
35
|
+
def ability
|
36
|
+
Decidim::Admin::Abilities::Base.new(user)
|
37
|
+
end
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
@@ -5,12 +5,20 @@ module Decidim
|
|
5
5
|
class ApplicationController < ActionController::Base
|
6
6
|
include NeedsOrganization
|
7
7
|
include NeedsAuthorization
|
8
|
+
include FormFactory
|
9
|
+
include LocaleSwitcher
|
8
10
|
|
9
11
|
protect_from_forgery with: :exception, prepend: true
|
10
12
|
|
11
13
|
def user_not_authorized_path
|
12
14
|
decidim_admin.root_path
|
13
15
|
end
|
16
|
+
|
17
|
+
# Overwrites `cancancan`'s method to point to the correct ability class,
|
18
|
+
# since the gem expects the ability class to be in the root namespace.
|
19
|
+
def current_ability
|
20
|
+
@current_ability ||= Decidim::Admin::Abilities::Base.new(current_user)
|
21
|
+
end
|
14
22
|
end
|
15
23
|
end
|
16
24
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_dependency "decidim/admin/application_controller"
|
3
|
+
|
4
|
+
module Decidim
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing all the Admins.
|
7
|
+
#
|
8
|
+
class CategoriesController < ApplicationController
|
9
|
+
include Concerns::ParticipatoryProcessAdmin
|
10
|
+
|
11
|
+
def index
|
12
|
+
authorize! :read, Decidim::Category
|
13
|
+
end
|
14
|
+
|
15
|
+
def new
|
16
|
+
authorize! :create, Decidim::Category
|
17
|
+
@form = form(CategoryForm).from_params({}, current_process: participatory_process)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
authorize! :create, Decidim::Category
|
22
|
+
@form = form(CategoryForm).from_params(params, current_process: participatory_process)
|
23
|
+
|
24
|
+
CreateCategory.call(@form, participatory_process) do
|
25
|
+
on(:ok) do
|
26
|
+
flash[:notice] = I18n.t("categories.create.success", scope: "decidim.admin")
|
27
|
+
redirect_to participatory_process_categories_path(participatory_process)
|
28
|
+
end
|
29
|
+
|
30
|
+
on(:invalid) do
|
31
|
+
flash.now[:alert] = I18n.t("categories.create.error", scope: "decidim.admin")
|
32
|
+
render :new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def edit
|
38
|
+
@category = collection.find(params[:id])
|
39
|
+
authorize! :update, @category
|
40
|
+
@form = form(CategoryForm).from_model(@category, current_process: participatory_process)
|
41
|
+
end
|
42
|
+
|
43
|
+
def update
|
44
|
+
@category = collection.find(params[:id])
|
45
|
+
authorize! :update, @category
|
46
|
+
@form = form(CategoryForm).from_params(params, current_process: participatory_process)
|
47
|
+
|
48
|
+
UpdateCategory.call(@category, @form) do
|
49
|
+
on(:ok) do
|
50
|
+
flash[:notice] = I18n.t("categories.update.success", scope: "decidim.admin")
|
51
|
+
redirect_to participatory_process_categories_path(participatory_process)
|
52
|
+
end
|
53
|
+
|
54
|
+
on(:invalid) do
|
55
|
+
flash.now[:alert] = I18n.t("categories.update.error", scope: "decidim.admin")
|
56
|
+
render :edit
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def show
|
62
|
+
@category = collection.find(params[:id])
|
63
|
+
authorize! :read, @category
|
64
|
+
end
|
65
|
+
|
66
|
+
def destroy
|
67
|
+
@category = collection.find(params[:id])
|
68
|
+
authorize! :destroy, @category
|
69
|
+
|
70
|
+
DestroyCategory.call(@category) do
|
71
|
+
on(:ok) do
|
72
|
+
flash[:notice] = I18n.t("categories.destroy.success", scope: "decidim.admin")
|
73
|
+
end
|
74
|
+
|
75
|
+
on(:invalid) do
|
76
|
+
flash[:alert] = I18n.t("categories.destroy.error", scope: "decidim.admin")
|
77
|
+
end
|
78
|
+
|
79
|
+
redirect_back(fallback_location: participatory_process_categories_path(participatory_process))
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def collection
|
86
|
+
@collection ||= participatory_process.categories.includes(:subcategories)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
module Concerns
|
5
|
+
# This concern is meant to be included in all controllers that are scoped
|
6
|
+
# into a participatory process' admin panel. It will override the layout
|
7
|
+
# so it shows the sidebar, preload the participatory process, etc.
|
8
|
+
module ParticipatoryProcessAdmin
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
helper_method :participatory_process
|
13
|
+
before_action :ensure_participatory_process
|
14
|
+
|
15
|
+
layout "decidim/admin/participatory_process"
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def participatory_process
|
21
|
+
@participatory_process ||=
|
22
|
+
current_organization.participatory_processes.find(params[:participatory_process_id])
|
23
|
+
end
|
24
|
+
|
25
|
+
def ensure_participatory_process
|
26
|
+
raise ActionController::RoutingError, "Not Found" unless participatory_process
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_dependency "decidim/admin/application_controller"
|
3
|
+
|
4
|
+
module Decidim
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing the Participatory Process' Features in the
|
7
|
+
# admin panel.
|
8
|
+
#
|
9
|
+
class FeaturesController < ApplicationController
|
10
|
+
include Concerns::ParticipatoryProcessAdmin
|
11
|
+
|
12
|
+
helper_method :manifest
|
13
|
+
|
14
|
+
def index
|
15
|
+
authorize! :read, Feature
|
16
|
+
@manifests = Decidim.feature_manifests
|
17
|
+
@features = participatory_process.features
|
18
|
+
end
|
19
|
+
|
20
|
+
def new
|
21
|
+
authorize! :create, Feature
|
22
|
+
|
23
|
+
@form = form(FeatureForm).instance(name: default_name(manifest))
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
@form = form(FeatureForm).from_params(params)
|
28
|
+
authorize! :create, Feature
|
29
|
+
|
30
|
+
CreateFeature.call(manifest, @form, participatory_process) do
|
31
|
+
on(:ok) do
|
32
|
+
flash[:notice] = I18n.t("features.create.success", scope: "decidim.admin")
|
33
|
+
redirect_to action: :index
|
34
|
+
end
|
35
|
+
|
36
|
+
on(:invalid) do
|
37
|
+
flash.now[:alert] = I18n.t("features.create.error", scope: "decidim.admin")
|
38
|
+
render action: "new"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def destroy
|
44
|
+
@feature = participatory_process.features.find(params[:id])
|
45
|
+
authorize! :destroy, @feature
|
46
|
+
|
47
|
+
DestroyFeature.call(@feature) do
|
48
|
+
on(:ok) do
|
49
|
+
flash[:notice] = I18n.t("features.destroy.success", scope: "decidim.admin")
|
50
|
+
redirect_to action: :index
|
51
|
+
end
|
52
|
+
|
53
|
+
on(:invalid) do
|
54
|
+
flash[:alert] = I18n.t("features.destroy.error", scope: "decidim.admin")
|
55
|
+
redirect_to action: :index
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def manifest
|
63
|
+
Decidim.find_feature_manifest(params[:type])
|
64
|
+
end
|
65
|
+
|
66
|
+
def default_name(manifest)
|
67
|
+
TranslationsHelper.multi_translation(
|
68
|
+
"decidim.features.#{manifest.name}.name",
|
69
|
+
current_organization.available_locales
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_dependency "decidim/admin/application_controller"
|
3
|
+
|
4
|
+
module Decidim
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing the user organization.
|
7
|
+
#
|
8
|
+
class OrganizationController < ApplicationController
|
9
|
+
def edit
|
10
|
+
authorize! :update, current_organization
|
11
|
+
@form = form(OrganizationForm).from_model(current_organization)
|
12
|
+
end
|
13
|
+
|
14
|
+
def update
|
15
|
+
authorize! :update, current_organization
|
16
|
+
@form = form(OrganizationForm).from_params(form_params)
|
17
|
+
|
18
|
+
UpdateOrganization.call(current_organization, @form) do
|
19
|
+
on(:ok) do
|
20
|
+
flash[:notice] = I18n.t("organization.update.success", scope: "decidim.admin")
|
21
|
+
redirect_to edit_organization_path
|
22
|
+
end
|
23
|
+
|
24
|
+
on(:invalid) do
|
25
|
+
flash.now[:alert] = I18n.t("organization.update.error", scope: "decidim.admin")
|
26
|
+
render :edit
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def form_params
|
34
|
+
params[:organization] ||= {}
|
35
|
+
params[:organization][:id] ||= current_organization.id
|
36
|
+
params
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_dependency "decidim/admin/application_controller"
|
3
|
+
|
4
|
+
module Decidim
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing all the attachments for a participatory
|
7
|
+
# process.
|
8
|
+
#
|
9
|
+
class ParticipatoryProcessAttachmentsController < ApplicationController
|
10
|
+
include Concerns::ParticipatoryProcessAdmin
|
11
|
+
|
12
|
+
def index
|
13
|
+
authorize! :read, ParticipatoryProcessAttachment
|
14
|
+
end
|
15
|
+
|
16
|
+
def new
|
17
|
+
authorize! :create, ParticipatoryProcessAttachment
|
18
|
+
@form = form(ParticipatoryProcessAttachmentForm).instance
|
19
|
+
end
|
20
|
+
|
21
|
+
def create
|
22
|
+
authorize! :create, ParticipatoryProcessAttachment
|
23
|
+
@form = form(ParticipatoryProcessAttachmentForm).from_params(params)
|
24
|
+
|
25
|
+
CreateParticipatoryProcessAttachment.call(@form, participatory_process) do
|
26
|
+
on(:ok) do
|
27
|
+
flash[:notice] = I18n.t("participatory_process_attachments.create.success", scope: "decidim.admin")
|
28
|
+
redirect_to participatory_process_attachments_path(participatory_process)
|
29
|
+
end
|
30
|
+
|
31
|
+
on(:invalid) do
|
32
|
+
flash.now[:alert] = I18n.t("participatory_process_attachments.create.error", scope: "decidim.admin")
|
33
|
+
render :new
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def edit
|
39
|
+
@participatory_process_attachment = collection.find(params[:id])
|
40
|
+
authorize! :update, @participatory_process_attachment
|
41
|
+
@form = form(ParticipatoryProcessAttachmentForm).from_model(@participatory_process_attachment)
|
42
|
+
end
|
43
|
+
|
44
|
+
def update
|
45
|
+
@participatory_process_attachment = collection.find(params[:id])
|
46
|
+
authorize! :update, @participatory_process_attachment
|
47
|
+
@form = form(ParticipatoryProcessAttachmentForm).from_params(params)
|
48
|
+
|
49
|
+
UpdateParticipatoryProcessAttachment.call(@participatory_process_attachment, @form) do
|
50
|
+
on(:ok) do
|
51
|
+
flash[:notice] = I18n.t("participatory_process_attachments.update.success", scope: "decidim.admin")
|
52
|
+
redirect_to participatory_process_attachments_path(participatory_process)
|
53
|
+
end
|
54
|
+
|
55
|
+
on(:invalid) do
|
56
|
+
flash.now[:alert] = I18n.t("participatory_process_attachments.update.error", scope: "decidim.admin")
|
57
|
+
render :edit
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def show
|
63
|
+
@participatory_process_attachment = collection.find(params[:id])
|
64
|
+
authorize! :read, @participatory_process_attachment
|
65
|
+
end
|
66
|
+
|
67
|
+
def destroy
|
68
|
+
@participatory_process_attachment = collection.find(params[:id])
|
69
|
+
authorize! :destroy, @participatory_process_attachment
|
70
|
+
@participatory_process_attachment.destroy!
|
71
|
+
|
72
|
+
flash[:notice] = I18n.t("participatory_process_attachments.destroy.success", scope: "decidim.admin")
|
73
|
+
|
74
|
+
redirect_to participatory_process_attachments_path(@participatory_process_attachment.participatory_process)
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def collection
|
80
|
+
@collection ||= participatory_process.attachments
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -6,6 +6,8 @@ module Decidim
|
|
6
6
|
# Controller that allows managing all the Admins.
|
7
7
|
#
|
8
8
|
class ParticipatoryProcessPublicationsController < ApplicationController
|
9
|
+
include Concerns::ParticipatoryProcessAdmin
|
10
|
+
|
9
11
|
def create
|
10
12
|
authorize! :publish, participatory_process
|
11
13
|
|
@@ -37,13 +39,6 @@ module Decidim
|
|
37
39
|
redirect_back(fallback_location: participatory_processes_path)
|
38
40
|
end
|
39
41
|
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def participatory_process
|
44
|
-
@participatory_process ||=
|
45
|
-
current_organization.participatory_processes.find(params[:participatory_process_id])
|
46
|
-
end
|
47
42
|
end
|
48
43
|
end
|
49
44
|
end
|