decidim-admin 0.0.1.alpha9 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 46d6185dd125a2294268f3ecd81a04bda650cd19
|
|
4
|
+
data.tar.gz: 7285fb73b6dc707318b4aa7e6521361bc3324e8a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3ea15149f26cb7988fd7493bd77f194b7a2eb7b2b52dfa8b1d77f68e9390a5a601ef37301d5694827fa90f93ef77b66161e245c6c7568209dbb9016053647213
|
|
7
|
+
data.tar.gz: 3b828b9ce5ba8de78d7340c1272f7fddace5f5221a2ce0c4f99369ba9338a7e12d9ff21dde3fc6300abc06b41e4a8b73b73fa3a45f4f64f4222a1c279e50c7c7
|
data/README.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# Decidim::Admin
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
This library adds and administration dashboard so users can manage their
|
|
4
|
+
organization, participatory processes and all other entities.
|
|
3
5
|
|
|
4
6
|
## Usage
|
|
5
|
-
|
|
7
|
+
This will add an admin dashboard to manage an organization an all its entities.
|
|
8
|
+
It's included by default with Decidim.
|
|
6
9
|
|
|
7
10
|
## Installation
|
|
8
11
|
Add this line to your application's Gemfile:
|
|
@@ -16,13 +19,35 @@ And then execute:
|
|
|
16
19
|
$ bundle
|
|
17
20
|
```
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
### Participatory process
|
|
25
|
+
|
|
26
|
+
Here you can manage participatory processes.
|
|
27
|
+
|
|
28
|
+
TODO: Elaborate on this.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Static pages
|
|
32
|
+
|
|
33
|
+
This feature allows an admin to create pages to serve static content. Some
|
|
34
|
+
example of this kind of pages could be:
|
|
35
|
+
|
|
36
|
+
* Terms and Conditions
|
|
37
|
+
* FAQ
|
|
38
|
+
* Accessibility guidelines
|
|
39
|
+
* About the project
|
|
40
|
+
|
|
41
|
+
All the pages can be created with I18n support and will be accessible as
|
|
42
|
+
`/pages/:page-slug`. You can link them at your website the same way you link
|
|
43
|
+
other Rails models: `pages_path("terms-and-conditions")`.
|
|
44
|
+
|
|
45
|
+
There are some pages that exist by default and cannot be deleted since there
|
|
46
|
+
are links to them inside the Decidim framework, see `Decidim::StaticPage` for
|
|
47
|
+
the default list.
|
|
23
48
|
|
|
24
49
|
## Contributing
|
|
25
|
-
|
|
50
|
+
See [Decidim](https://github.com/AjuntamentdeBarcelona/decidim).
|
|
26
51
|
|
|
27
52
|
## License
|
|
28
|
-
|
|
53
|
+
See [Decidim](https://github.com/AjuntamentdeBarcelona/decidim).
|
data/Rakefile
CHANGED
|
@@ -1,27 +1,2 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
2
|
require "decidim/common_rake"
|
|
4
|
-
require "rdoc/task"
|
|
5
|
-
|
|
6
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
|
7
|
-
rdoc.rdoc_dir = "rdoc"
|
|
8
|
-
rdoc.title = "Decidim::Admin"
|
|
9
|
-
rdoc.options << "--line-numbers"
|
|
10
|
-
rdoc.rdoc_files.include("README.md")
|
|
11
|
-
rdoc.rdoc_files.include("lib/**/*.rb")
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
load "rails/tasks/statistics.rake"
|
|
15
|
-
|
|
16
|
-
require "bundler/gem_tasks"
|
|
17
|
-
|
|
18
|
-
begin
|
|
19
|
-
require "rspec/core/rake_task"
|
|
20
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
21
|
-
ENV["ENGINE_PATH"] = File.dirname(__FILE__)
|
|
22
|
-
|
|
23
|
-
task default: :spec
|
|
24
|
-
|
|
25
|
-
Rake::Task["spec"].enhance ["common:test_app"]
|
|
26
|
-
rescue LoadError
|
|
27
|
-
end
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
//= require jquery_ujs
|
|
3
|
-
//= require foundation
|
|
4
|
-
//= require turbolinks
|
|
5
|
-
//= require html.sortable.min
|
|
6
|
-
//= require ./sort_steps
|
|
7
|
-
//= require_self
|
|
1
|
+
/* global sortSteps */
|
|
8
2
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
// = require jquery
|
|
4
|
+
// = require jquery_ujs
|
|
5
|
+
// = require foundation
|
|
6
|
+
// = require turbolinks
|
|
7
|
+
// = require html.sortable
|
|
8
|
+
// = require ./sort_steps
|
|
9
|
+
// = require ./tab_focus
|
|
10
|
+
// = require decidim/editor
|
|
11
|
+
// = require_self
|
|
12
12
|
|
|
13
|
+
const pageLoad = () => {
|
|
14
|
+
$(document).foundation();
|
|
15
|
+
sortSteps();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
$(document).on('turbolinks:load', pageLoad);
|
|
19
|
+
$(pageLoad);
|
|
@@ -1,21 +1,30 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
1
2
|
/* global sortable */
|
|
2
3
|
|
|
3
|
-
// consider removing from application.js file
|
|
4
|
-
//
|
|
5
4
|
// Needs a `tbody` element inside a `#steps` section. The `tbody` element
|
|
6
5
|
// should have a `data-sort-url` attribute with the URL where the data should
|
|
7
6
|
// be posted to.
|
|
8
|
-
|
|
9
|
-
const sortableElement = $('#steps tbody');
|
|
7
|
+
const sortSteps = () => {
|
|
8
|
+
const $sortableElement = $('#steps tbody');
|
|
10
9
|
|
|
11
|
-
if (sortableElement) {
|
|
12
|
-
const sortUrl = sortableElement.data('sort-url');
|
|
10
|
+
if ($sortableElement.length > 0) {
|
|
11
|
+
const sortUrl = $sortableElement.data('sort-url');
|
|
13
12
|
|
|
14
13
|
sortable('#steps tbody', {
|
|
15
|
-
placeholder: $('<tr style="border-style: dashed; border-color: #000"><td colspan="4"> </td></tr>')[0]
|
|
16
|
-
})[0].addEventListener('sortupdate', (
|
|
17
|
-
const order = $(
|
|
18
|
-
|
|
14
|
+
placeholder: $('<tr style="border-style: dashed; border-color: #000"><td colspan="4"> </td></tr>')[0]
|
|
15
|
+
})[0].addEventListener('sortupdate', (event) => {
|
|
16
|
+
const order = $(event.target).children()
|
|
17
|
+
.map((index, child) => $(child).data('id'))
|
|
18
|
+
.toArray();
|
|
19
|
+
|
|
20
|
+
$.ajax({
|
|
21
|
+
method: 'POST',
|
|
22
|
+
url: sortUrl,
|
|
23
|
+
contentType: 'application/json',
|
|
24
|
+
data: JSON.stringify({ items_ids: order }) },
|
|
25
|
+
);
|
|
19
26
|
});
|
|
20
27
|
}
|
|
21
|
-
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
window.sortSteps = sortSteps;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// = require_self
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* When switching tabs in i18n fields, autofocus on the input to save clicks #212
|
|
5
|
+
*/
|
|
6
|
+
$(document).on('turbolinks:load', () => {
|
|
7
|
+
// Event launched by foundation
|
|
8
|
+
$('[data-tabs]').on('change.zf.tabs', (event) => {
|
|
9
|
+
const $container = $(event.target).next('.tabs-content .tabs-panel.is-active');
|
|
10
|
+
// Detect quilljs editor inside the tabs-panel
|
|
11
|
+
let $content = $container.find('.editor .ql-editor');
|
|
12
|
+
if ($content.length > 0) {
|
|
13
|
+
$content.focus();
|
|
14
|
+
// Detect if inside the tabs-panel have an input
|
|
15
|
+
} else {
|
|
16
|
+
$content = $container.find('input:first');
|
|
17
|
+
if ($content.length > 0) {
|
|
18
|
+
$content.focus();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
@import 'https://fonts.googleapis.com/css?family=Montserrat:400,700';
|
|
2
|
-
|
|
3
1
|
@import "foundation_and_overrides";
|
|
4
2
|
@import "layout";
|
|
5
3
|
@import "login";
|
|
6
4
|
@import "sidebar";
|
|
7
5
|
@import "tables";
|
|
8
6
|
@import "actions";
|
|
7
|
+
@import "forms";
|
|
8
|
+
|
|
9
|
+
@import "decidim/editor";
|
|
10
|
+
@import "decidim/utils/fontface";
|
|
11
|
+
|
|
12
|
+
body {
|
|
13
|
+
font-family: 'Source Sans Pro', sans-serif;
|
|
14
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Decidim
|
|
3
|
+
module Admin
|
|
4
|
+
# A command with all the business logic to create a new category in the
|
|
5
|
+
# system.
|
|
6
|
+
class CreateCategory < 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
|
+
# category
|
|
12
|
+
def initialize(form, participatory_process)
|
|
13
|
+
@form = form
|
|
14
|
+
@participatory_process = participatory_process
|
|
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
|
+
create_category
|
|
27
|
+
broadcast(:ok)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
attr_reader :form
|
|
33
|
+
|
|
34
|
+
def create_category
|
|
35
|
+
Category.create!(
|
|
36
|
+
name: form.name,
|
|
37
|
+
description: form.description,
|
|
38
|
+
parent_id: form.parent_id,
|
|
39
|
+
participatory_process: @participatory_process
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Decidim
|
|
3
|
+
module Admin
|
|
4
|
+
# This command gets called when a feature is created from the admin panel.
|
|
5
|
+
class CreateFeature < Rectify::Command
|
|
6
|
+
attr_reader :form, :manifest, :participatory_process
|
|
7
|
+
|
|
8
|
+
# Public: Initializes the command.
|
|
9
|
+
#
|
|
10
|
+
# manifest - The feature's manifest to create a feature from.
|
|
11
|
+
# form - The form from which the data in this feature comes from.
|
|
12
|
+
# participatory_process - The participatory process that will hold this feature.
|
|
13
|
+
def initialize(manifest, form, participatory_process)
|
|
14
|
+
@manifest = manifest
|
|
15
|
+
@form = form
|
|
16
|
+
@participatory_process = participatory_process
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Public: Creates the Feature.
|
|
20
|
+
#
|
|
21
|
+
# Broadcasts :ok if created, :invalid otherwise.
|
|
22
|
+
def call
|
|
23
|
+
return broadcast(:invalid) if form.invalid?
|
|
24
|
+
|
|
25
|
+
transaction do
|
|
26
|
+
create_feature
|
|
27
|
+
run_hooks
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
broadcast(:ok)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def create_feature
|
|
36
|
+
@feature = Feature.create!(
|
|
37
|
+
manifest_name: manifest.name,
|
|
38
|
+
name: form.name,
|
|
39
|
+
participatory_process: participatory_process
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def run_hooks
|
|
44
|
+
manifest.run_hooks(:create, @feature)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -7,14 +7,11 @@ module Decidim
|
|
|
7
7
|
# Public: Initializes the command.
|
|
8
8
|
#
|
|
9
9
|
# form - A form object with the params.
|
|
10
|
-
|
|
11
|
-
# participatory process
|
|
12
|
-
def initialize(form, organization)
|
|
10
|
+
def initialize(form)
|
|
13
11
|
@form = form
|
|
14
|
-
@organization = organization
|
|
15
12
|
end
|
|
16
13
|
|
|
17
|
-
# Executes the command.
|
|
14
|
+
# Executes the command. Broadcasts these events:
|
|
18
15
|
#
|
|
19
16
|
# - :ok when everything is valid.
|
|
20
17
|
# - :invalid if the form wasn't valid and we couldn't proceed.
|
|
@@ -42,7 +39,7 @@ module Decidim
|
|
|
42
39
|
hero_image: form.hero_image,
|
|
43
40
|
banner_image: form.banner_image,
|
|
44
41
|
promoted: form.promoted,
|
|
45
|
-
organization:
|
|
42
|
+
organization: form.current_organization
|
|
46
43
|
)
|
|
47
44
|
end
|
|
48
45
|
end
|
|
@@ -0,0 +1,51 @@
|
|
|
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 admin in the system.
|
|
6
|
+
class CreateParticipatoryProcessAdmin < 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
|
+
# user role
|
|
12
|
+
def initialize(form, participatory_process)
|
|
13
|
+
@form = form
|
|
14
|
+
@participatory_process = participatory_process
|
|
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
|
+
return broadcast(:invalid) unless user
|
|
26
|
+
|
|
27
|
+
create_participatory_process_admin
|
|
28
|
+
broadcast(:ok)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
attr_reader :form, :participatory_process
|
|
34
|
+
|
|
35
|
+
def create_participatory_process_admin
|
|
36
|
+
ParticipatoryProcessUserRole.create!(
|
|
37
|
+
role: :admin,
|
|
38
|
+
user: user,
|
|
39
|
+
participatory_process: @participatory_process
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def user
|
|
44
|
+
User.where(
|
|
45
|
+
email: form.email,
|
|
46
|
+
organization: participatory_process.organization
|
|
47
|
+
).first
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Decidim
|
|
3
|
+
module Admin
|
|
4
|
+
# A command with all the business logic to add an attachment to a
|
|
5
|
+
# participatory process.
|
|
6
|
+
class CreateParticipatoryProcessAttachment < 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
|
+
# attachment
|
|
12
|
+
def initialize(form, participatory_process)
|
|
13
|
+
@form = form
|
|
14
|
+
@participatory_process = participatory_process
|
|
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
|
+
create_attachment
|
|
27
|
+
broadcast(:ok)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
attr_reader :form
|
|
33
|
+
|
|
34
|
+
def create_attachment
|
|
35
|
+
ParticipatoryProcessAttachment.create!(
|
|
36
|
+
title: form.title,
|
|
37
|
+
description: form.description,
|
|
38
|
+
file: form.file,
|
|
39
|
+
participatory_process: @participatory_process
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -14,7 +14,7 @@ module Decidim
|
|
|
14
14
|
@participatory_process = participatory_process
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
# Executes the command.
|
|
17
|
+
# Executes the command. Broadcasts these events:
|
|
18
18
|
#
|
|
19
19
|
# - :ok when everything is valid.
|
|
20
20
|
# - :invalid if the form wasn't valid and we couldn't proceed.
|
|
@@ -36,8 +36,8 @@ module Decidim
|
|
|
36
36
|
title: form.title,
|
|
37
37
|
description: form.description,
|
|
38
38
|
short_description: form.short_description,
|
|
39
|
-
start_date: form.start_date
|
|
40
|
-
end_date: form.end_date
|
|
39
|
+
start_date: form.start_date,
|
|
40
|
+
end_date: form.end_date,
|
|
41
41
|
participatory_process: @participatory_process
|
|
42
42
|
)
|
|
43
43
|
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Decidim
|
|
3
|
+
module Admin
|
|
4
|
+
# A command with all the business logic when creating a static scope.
|
|
5
|
+
class CreateScope < Rectify::Command
|
|
6
|
+
# Public: Initializes the command.
|
|
7
|
+
#
|
|
8
|
+
# form - A form object with the params.
|
|
9
|
+
def initialize(form)
|
|
10
|
+
@form = form
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Executes the command. Broadcasts these events:
|
|
14
|
+
#
|
|
15
|
+
# - :ok when everything is valid.
|
|
16
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
|
17
|
+
#
|
|
18
|
+
# Returns nothing.
|
|
19
|
+
def call
|
|
20
|
+
return broadcast(:invalid) if form.invalid?
|
|
21
|
+
|
|
22
|
+
create_scope
|
|
23
|
+
broadcast(:ok)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
attr_reader :form
|
|
29
|
+
|
|
30
|
+
def create_scope
|
|
31
|
+
Scope.create!(
|
|
32
|
+
name: form.name,
|
|
33
|
+
organization: form.organization
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Decidim
|
|
3
|
+
module Admin
|
|
4
|
+
# A command with all the business logic when creating a static page.
|
|
5
|
+
class CreateStaticPage < Rectify::Command
|
|
6
|
+
# Public: Initializes the command.
|
|
7
|
+
#
|
|
8
|
+
# form - A form object with the params.
|
|
9
|
+
def initialize(form)
|
|
10
|
+
@form = form
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Executes the command. Broadcasts these events:
|
|
14
|
+
#
|
|
15
|
+
# - :ok when everything is valid.
|
|
16
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
|
17
|
+
#
|
|
18
|
+
# Returns nothing.
|
|
19
|
+
def call
|
|
20
|
+
return broadcast(:invalid) if form.invalid?
|
|
21
|
+
|
|
22
|
+
create_page
|
|
23
|
+
broadcast(:ok)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
attr_reader :form
|
|
29
|
+
|
|
30
|
+
def create_page
|
|
31
|
+
StaticPage.create!(
|
|
32
|
+
title: form.title,
|
|
33
|
+
slug: form.slug,
|
|
34
|
+
content: form.content,
|
|
35
|
+
organization: form.organization
|
|
36
|
+
)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Decidim
|
|
3
|
+
module Admin
|
|
4
|
+
# A command with all the business logic to destroy a category in the
|
|
5
|
+
# system.
|
|
6
|
+
class DestroyCategory < Rectify::Command
|
|
7
|
+
# Public: Initializes the command.
|
|
8
|
+
#
|
|
9
|
+
# category - A Category that will be destroyed
|
|
10
|
+
def initialize(category)
|
|
11
|
+
@category = category
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Executes the command. Broadcasts 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 category.nil? || category.subcategories.any?
|
|
22
|
+
|
|
23
|
+
destroy_category
|
|
24
|
+
broadcast(:ok)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
attr_reader :category
|
|
30
|
+
|
|
31
|
+
def destroy_category
|
|
32
|
+
category.destroy!
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Decidim
|
|
3
|
+
module Admin
|
|
4
|
+
# This command deals with destroying a Feature from the admin panel.
|
|
5
|
+
class DestroyFeature < Rectify::Command
|
|
6
|
+
# Public: Initializes the command.
|
|
7
|
+
#
|
|
8
|
+
# feature - The Feature to be destroyed.
|
|
9
|
+
def initialize(feature)
|
|
10
|
+
@feature = feature
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Public: Executes the command.
|
|
14
|
+
#
|
|
15
|
+
# Broadcasts :ok if it got destroyed, raises an exception otherwise.
|
|
16
|
+
def call
|
|
17
|
+
begin
|
|
18
|
+
destroy_feature
|
|
19
|
+
rescue StandardError
|
|
20
|
+
return broadcast(:invalid)
|
|
21
|
+
end
|
|
22
|
+
broadcast(:ok)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def destroy_feature
|
|
28
|
+
transaction do
|
|
29
|
+
@feature.destroy!
|
|
30
|
+
run_hooks
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def run_hooks
|
|
35
|
+
@feature.manifest.run_hooks(:destroy, @feature)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|