decidim-admin 0.0.1.alpha7 → 0.0.1.alpha8
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/LICENSE.txt +619 -0
- data/README.md +1 -1
- data/app/assets/javascripts/decidim/admin/application.js.es6 +12 -0
- data/app/assets/javascripts/decidim/admin/sort_steps.js.es6 +21 -0
- data/app/assets/stylesheets/decidim/admin/_tables.scss +9 -0
- data/app/commands/decidim/admin/activate_participatory_process_step.rb +43 -0
- data/app/commands/decidim/admin/create_participatory_process.rb +1 -0
- data/app/commands/decidim/admin/create_participatory_process_step.rb +46 -0
- data/app/commands/decidim/admin/deactivate_participatory_process_step.rb +35 -0
- data/app/commands/decidim/admin/publish_participatory_process.rb +35 -0
- data/app/commands/decidim/admin/reorder_participatory_process_steps.rb +47 -0
- data/app/commands/decidim/admin/unpublish_participatory_process.rb +35 -0
- data/app/commands/decidim/admin/update_participatory_process.rb +1 -0
- data/app/commands/decidim/admin/update_participatory_process_step.rb +49 -0
- data/app/constraints/decidim/admin/organization_dashboard_constraint.rb +1 -1
- data/app/controllers/decidim/admin/application_controller.rb +4 -0
- data/app/controllers/decidim/admin/dashboard_controller.rb +1 -9
- data/app/controllers/decidim/admin/participatory_process_publications_controller.rb +49 -0
- data/app/controllers/decidim/admin/participatory_process_step_activations_controller.rb +56 -0
- data/app/controllers/decidim/admin/participatory_process_step_ordering_controller.rb +30 -0
- data/app/controllers/decidim/admin/participatory_process_steps_controller.rb +81 -0
- data/app/controllers/decidim/admin/participatory_processes_controller.rb +7 -12
- data/app/forms/decidim/admin/participatory_process_form.rb +1 -0
- data/app/forms/decidim/admin/participatory_process_step_form.rb +25 -0
- data/app/helpers/decidim/admin/application_helper.rb +1 -0
- data/app/mailers/decidim/admin/application_mailer.rb +1 -1
- data/app/models/decidim/admin/abilities/admin.rb +21 -0
- data/app/views/decidim/admin/participatory_process_steps/_form.html.erb +19 -0
- data/app/views/decidim/admin/participatory_process_steps/_table.html.erb +53 -0
- data/app/views/decidim/admin/participatory_process_steps/edit.html.erb +11 -0
- data/app/views/decidim/admin/participatory_process_steps/new.html.erb +11 -0
- data/app/views/decidim/admin/participatory_process_steps/show.html.erb +22 -0
- data/app/views/decidim/admin/participatory_processes/_form.html.erb +4 -0
- data/app/views/decidim/admin/participatory_processes/index.html.erb +22 -2
- data/app/views/decidim/admin/participatory_processes/show.html.erb +21 -2
- data/config/i18n-tasks.yml +2 -2
- data/config/locales/ca.yml +55 -2
- data/config/locales/en.yml +55 -2
- data/config/locales/es.yml +56 -3
- data/config/routes.rb +10 -1
- data/lib/decidim/admin/engine.rb +6 -1
- data/vendor/assets/javascripts/html.sortable.min.js +2 -0
- metadata +39 -37
- data/app/assets/javascripts/decidim/admin/application.js +0 -22
- data/app/controllers/concerns/decidim/needs_authorization.rb +0 -50
- data/app/policies/decidim/admin/application_policy.rb +0 -20
- data/app/policies/decidim/admin/dashboard_policy.rb +0 -15
- data/app/policies/decidim/admin/organization_policy.rb +0 -15
- data/app/policies/decidim/admin/participatory_process_policy.rb +0 -57
data/README.md
CHANGED
@@ -25,4 +25,4 @@ $ gem install decidim-admin
|
|
25
25
|
Contribution directions go here.
|
26
26
|
|
27
27
|
## License
|
28
|
-
The gem is available as open source under the terms of the [
|
28
|
+
The gem is available as open source under the terms of the [AGPLv3 License](https://opensource.org/licenses/AGPL-3.0).
|
@@ -0,0 +1,12 @@
|
|
1
|
+
//= require jquery
|
2
|
+
//= require jquery_ujs
|
3
|
+
//= require foundation
|
4
|
+
//= require turbolinks
|
5
|
+
//= require html.sortable.min
|
6
|
+
//= require ./sort_steps
|
7
|
+
//= require_self
|
8
|
+
|
9
|
+
$(document).on('turbolinks:load', () => {
|
10
|
+
$(() => { $(document).foundation(); });
|
11
|
+
});
|
12
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/* global sortable */
|
2
|
+
|
3
|
+
// consider removing from application.js file
|
4
|
+
//
|
5
|
+
// Needs a `tbody` element inside a `#steps` section. The `tbody` element
|
6
|
+
// should have a `data-sort-url` attribute with the URL where the data should
|
7
|
+
// be posted to.
|
8
|
+
$(() => {
|
9
|
+
const sortableElement = $('#steps tbody');
|
10
|
+
|
11
|
+
if (sortableElement) {
|
12
|
+
const sortUrl = sortableElement.data('sort-url');
|
13
|
+
|
14
|
+
sortable('#steps tbody', {
|
15
|
+
placeholder: $('<tr style="border-style: dashed; border-color: #000"><td colspan="4"> </td></tr>')[0],
|
16
|
+
})[0].addEventListener('sortupdate', (e) => {
|
17
|
+
const order = $(e.target).children().map(() => $(this).data('id')).toArray();
|
18
|
+
$.ajax({ method: 'POST', url: sortUrl, data: { items_ids: order } });
|
19
|
+
});
|
20
|
+
}
|
21
|
+
});
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
# A command that sets a step in a participatory process as active (and
|
5
|
+
# unsets a previous active step)
|
6
|
+
class ActivateParticipatoryProcessStep < Rectify::Command
|
7
|
+
# Public: Initializes the command.
|
8
|
+
#
|
9
|
+
# step - A ParticipatoryProcessStep that will be activated
|
10
|
+
def initialize(step)
|
11
|
+
@step = step
|
12
|
+
end
|
13
|
+
|
14
|
+
# Executes the command. Braodcasts these events:
|
15
|
+
#
|
16
|
+
# - :ok when everything is valid.
|
17
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
18
|
+
#
|
19
|
+
# Returns nothing.
|
20
|
+
def call
|
21
|
+
return broadcast(:invalid) if step.nil? || step.active?
|
22
|
+
|
23
|
+
Decidim::ParticipatoryProcessStep.transaction do
|
24
|
+
deactivate_active_steps
|
25
|
+
activate_step
|
26
|
+
end
|
27
|
+
broadcast(:ok)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_reader :step
|
33
|
+
|
34
|
+
def deactivate_active_steps
|
35
|
+
step.participatory_process.steps.where(active: true).update_all(active: false)
|
36
|
+
end
|
37
|
+
|
38
|
+
def activate_step
|
39
|
+
step.update_attribute(:active, true)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
# A command with all the business logic when creating a new participatory
|
5
|
+
# process in the system.
|
6
|
+
class CreateParticipatoryProcessStep < Rectify::Command
|
7
|
+
# Public: Initializes the command.
|
8
|
+
#
|
9
|
+
# form - A form object with the params.
|
10
|
+
# participatory_process - The ParticipatoryProcess that will hold the
|
11
|
+
# step
|
12
|
+
def initialize(form, participatory_process)
|
13
|
+
@form = form
|
14
|
+
@participatory_process = participatory_process
|
15
|
+
end
|
16
|
+
|
17
|
+
# Executes the command. Braodcasts 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
|
+
create_participatory_process_step
|
27
|
+
broadcast(:ok)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_reader :form
|
33
|
+
|
34
|
+
def create_participatory_process_step
|
35
|
+
ParticipatoryProcessStep.create!(
|
36
|
+
title: form.title,
|
37
|
+
description: form.description,
|
38
|
+
short_description: form.short_description,
|
39
|
+
start_date: form.start_date.at_midnight,
|
40
|
+
end_date: form.end_date.at_midnight,
|
41
|
+
participatory_process: @participatory_process
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
# A command that sets all steps in a participatory process as inactive
|
5
|
+
class DeactivateParticipatoryProcessStep < Rectify::Command
|
6
|
+
# Public: Initializes the command.
|
7
|
+
#
|
8
|
+
# step - A ParticipatoryProcessStep that will be deactivated
|
9
|
+
def initialize(step)
|
10
|
+
@step = step
|
11
|
+
end
|
12
|
+
|
13
|
+
# Executes the command. Broadcasts these events:
|
14
|
+
#
|
15
|
+
# - :ok when everything is valid.
|
16
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
17
|
+
#
|
18
|
+
# Returns nothing.
|
19
|
+
def call
|
20
|
+
return broadcast(:invalid) if step.nil? || !step.active?
|
21
|
+
|
22
|
+
deactivate_active_steps
|
23
|
+
broadcast(:ok)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :step
|
29
|
+
|
30
|
+
def deactivate_active_steps
|
31
|
+
step.participatory_process.steps.where(active: true).update_all(active: false)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
# A command that sets a participatory process as published.
|
5
|
+
class PublishParticipatoryProcess < Rectify::Command
|
6
|
+
# Public: Initializes the command.
|
7
|
+
#
|
8
|
+
# process - A ParticipatoryProcess that will be published
|
9
|
+
def initialize(process)
|
10
|
+
@process = process
|
11
|
+
end
|
12
|
+
|
13
|
+
# Executes the command. Braodcasts these events:
|
14
|
+
#
|
15
|
+
# - :ok when everything is valid.
|
16
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
17
|
+
#
|
18
|
+
# Returns nothing.
|
19
|
+
def call
|
20
|
+
return broadcast(:invalid) if process.nil? || process.published?
|
21
|
+
|
22
|
+
publish_process
|
23
|
+
broadcast(:ok)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :process
|
29
|
+
|
30
|
+
def publish_process
|
31
|
+
process.update_attribute(:published_at, Time.current)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
# A command that reorders the steps in a participatory process.
|
5
|
+
class ReorderParticipatoryProcessSteps < Rectify::Command
|
6
|
+
# Public: Initializes the command.
|
7
|
+
#
|
8
|
+
# collection - an ActiveRecord::Relation of steps
|
9
|
+
# order - an Array holding the order of IDs of steps
|
10
|
+
def initialize(collection, order)
|
11
|
+
@collection = collection
|
12
|
+
@order = order
|
13
|
+
end
|
14
|
+
|
15
|
+
# Executes the command. Braodcasts these events:
|
16
|
+
#
|
17
|
+
# - :ok when everything is valid.
|
18
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def call
|
22
|
+
return broadcast(:invalid) unless order.present?
|
23
|
+
|
24
|
+
reorder_steps
|
25
|
+
broadcast(:ok)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :collection
|
31
|
+
|
32
|
+
def reorder_steps
|
33
|
+
data = order.each_with_index.inject({}) do |hash, (id, index)|
|
34
|
+
hash.update(id => { position: index })
|
35
|
+
end
|
36
|
+
|
37
|
+
collection.update(data.keys, data.values)
|
38
|
+
end
|
39
|
+
|
40
|
+
def order
|
41
|
+
return nil unless @order.is_a?(Array) && @order.present?
|
42
|
+
|
43
|
+
@order
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
# A command that sets a participatory process as unpublished.
|
5
|
+
class UnpublishParticipatoryProcess < Rectify::Command
|
6
|
+
# Public: Initializes the command.
|
7
|
+
#
|
8
|
+
# process - A ParticipatoryProcess that will be unpublished
|
9
|
+
def initialize(process)
|
10
|
+
@process = process
|
11
|
+
end
|
12
|
+
|
13
|
+
# Executes the command. Braodcasts these events:
|
14
|
+
#
|
15
|
+
# - :ok when everything is valid.
|
16
|
+
# - :invalid if the data wasn't valid and we couldn't proceed.
|
17
|
+
#
|
18
|
+
# Returns nothing.
|
19
|
+
def call
|
20
|
+
return broadcast(:invalid) if process.nil? || !process.published?
|
21
|
+
|
22
|
+
unpublish_process
|
23
|
+
broadcast(:ok)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :process
|
29
|
+
|
30
|
+
def unpublish_process
|
31
|
+
process.update_attribute(:published_at, nil)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
# A command with all the business logic when creating a new participatory
|
5
|
+
# process in the system.
|
6
|
+
class UpdateParticipatoryProcessStep < Rectify::Command
|
7
|
+
attr_reader :participatory_process_step
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# participatory_process_step - the ParticipatoryProcessStep to update
|
11
|
+
# form - A form object with the params.
|
12
|
+
def initialize(participatory_process_step, form)
|
13
|
+
@participatory_process_step = participatory_process_step
|
14
|
+
@form = form
|
15
|
+
end
|
16
|
+
|
17
|
+
# Executes the command. Braodcasts 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_participatory_process_step
|
27
|
+
broadcast(:ok)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_reader :form
|
33
|
+
|
34
|
+
def update_participatory_process_step
|
35
|
+
participatory_process_step.update_attributes!(attributes)
|
36
|
+
end
|
37
|
+
|
38
|
+
def attributes
|
39
|
+
{
|
40
|
+
title: form.title,
|
41
|
+
start_date: form.start_date,
|
42
|
+
end_date: form.end_date,
|
43
|
+
description: form.description,
|
44
|
+
short_description: form.short_description
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -6,15 +6,7 @@ module Decidim
|
|
6
6
|
# Controller that shows a simple dashboard.
|
7
7
|
#
|
8
8
|
class DashboardController < ApplicationController
|
9
|
-
|
10
|
-
authorize :dashboard
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def policy_class
|
16
|
-
Decidim::Admin::DashboardPolicy
|
17
|
-
end
|
9
|
+
authorize_resource :admin_dashboard, class: false
|
18
10
|
end
|
19
11
|
end
|
20
12
|
end
|
@@ -0,0 +1,49 @@
|
|
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 ParticipatoryProcessPublicationsController < ApplicationController
|
9
|
+
def create
|
10
|
+
authorize! :publish, participatory_process
|
11
|
+
|
12
|
+
PublishParticipatoryProcess.call(participatory_process) do
|
13
|
+
on(:ok) do
|
14
|
+
flash[:notice] = I18n.t("participatory_process_publications.create.success", scope: "decidim.admin")
|
15
|
+
end
|
16
|
+
|
17
|
+
on(:invalid) do
|
18
|
+
flash.now[:alert] = I18n.t("participatory_process_publications.create.error", scope: "decidim.admin")
|
19
|
+
end
|
20
|
+
|
21
|
+
redirect_back(fallback_location: participatory_processes_path)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
authorize! :publish, participatory_process
|
27
|
+
|
28
|
+
UnpublishParticipatoryProcess.call(participatory_process) do
|
29
|
+
on(:ok) do
|
30
|
+
flash[:notice] = I18n.t("participatory_process_publications.destroy.success", scope: "decidim.admin")
|
31
|
+
end
|
32
|
+
|
33
|
+
on(:invalid) do
|
34
|
+
flash.now[:alert] = I18n.t("participatory_process_publications.destroy.error", scope: "decidim.admin")
|
35
|
+
end
|
36
|
+
|
37
|
+
redirect_back(fallback_location: participatory_processes_path)
|
38
|
+
end
|
39
|
+
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
|
+
end
|
48
|
+
end
|
49
|
+
end
|