decidim-admin 0.15.2 → 0.16.0

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.

Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/decidim_admin_manifest.js +1 -0
  3. data/app/assets/javascripts/decidim/admin/welcome_notification.js.es6 +32 -0
  4. data/app/assets/stylesheets/decidim/admin/modules/_forms.scss +21 -0
  5. data/app/commands/decidim/admin/create_attachment.rb +1 -1
  6. data/app/commands/decidim/admin/create_static_page.rb +3 -0
  7. data/app/commands/decidim/admin/create_static_page_topic.rb +36 -0
  8. data/app/commands/decidim/admin/destroy_static_page_topic.rb +40 -0
  9. data/app/commands/decidim/admin/officialize_user.rb +1 -1
  10. data/app/commands/decidim/admin/process_user_group_verification_csv.rb +42 -0
  11. data/app/commands/decidim/admin/publish_component.rb +1 -1
  12. data/app/commands/decidim/admin/update_help_sections.rb +26 -0
  13. data/app/commands/decidim/admin/update_organization.rb +10 -1
  14. data/app/commands/decidim/admin/update_static_page.rb +3 -0
  15. data/app/commands/decidim/admin/update_static_page_topic.rb +51 -0
  16. data/app/commands/decidim/admin/verify_user_group.rb +4 -2
  17. data/app/controllers/concerns/decidim/admin/user_groups.rb +24 -0
  18. data/app/controllers/decidim/admin/help_sections_controller.rb +52 -0
  19. data/app/controllers/decidim/admin/impersonations_controller.rb +1 -1
  20. data/app/controllers/decidim/admin/static_page_topics_controller.rb +73 -0
  21. data/app/controllers/decidim/admin/static_pages_controller.rb +4 -1
  22. data/app/controllers/decidim/admin/user_groups_controller.rb +4 -0
  23. data/app/controllers/decidim/admin/user_groups_csv_verifications_controller.rb +36 -0
  24. data/app/events/decidim/attachment_created_event.rb +7 -0
  25. data/app/forms/decidim/admin/help_section_form.rb +25 -0
  26. data/app/forms/decidim/admin/help_sections_form.rb +11 -0
  27. data/app/forms/decidim/admin/organization_form.rb +9 -0
  28. data/app/forms/decidim/admin/static_page_form.rb +16 -0
  29. data/app/forms/decidim/admin/static_page_topic_form.rb +19 -0
  30. data/app/forms/decidim/admin/user_group_csv_verification_form.rb +13 -0
  31. data/app/jobs/decidim/admin/verify_user_group_from_csv_job.rb +29 -0
  32. data/app/permissions/decidim/admin/permissions.rb +2 -0
  33. data/app/views/decidim/admin/help_sections/_form.html.erb +21 -0
  34. data/app/views/decidim/admin/help_sections/show.erb +1 -0
  35. data/app/views/decidim/admin/help_sections/update.html.erb +1 -0
  36. data/app/views/decidim/admin/officializations/index.html.erb +1 -1
  37. data/app/views/decidim/admin/organization/_form.html.erb +22 -0
  38. data/app/views/decidim/admin/static_page_topics/_form.html.erb +15 -0
  39. data/app/views/decidim/admin/static_page_topics/edit.html.erb +13 -0
  40. data/app/views/decidim/admin/static_page_topics/new.html.erb +13 -0
  41. data/app/views/decidim/admin/static_pages/_form.html.erb +12 -0
  42. data/app/views/decidim/admin/static_pages/_topic.html.erb +61 -0
  43. data/app/views/decidim/admin/static_pages/index.html.erb +6 -48
  44. data/app/views/decidim/admin/user_groups/index.html.erb +4 -1
  45. data/app/views/decidim/admin/user_groups_csv_verifications/new.html.erb +19 -0
  46. data/app/views/layouts/decidim/admin/pages.html.erb +1 -0
  47. data/app/views/layouts/decidim/admin/settings.html.erb +3 -0
  48. data/app/views/layouts/decidim/admin/users.html.erb +3 -2
  49. data/config/locales/ca.yml +56 -3
  50. data/config/locales/de.yml +56 -3
  51. data/config/locales/en.yml +56 -3
  52. data/config/locales/es-PY.yml +56 -3
  53. data/config/locales/es.yml +56 -3
  54. data/config/locales/eu.yml +56 -3
  55. data/config/locales/fi-pl.yml +56 -3
  56. data/config/locales/fi.yml +56 -3
  57. data/config/locales/fr.yml +56 -3
  58. data/config/locales/gl.yml +56 -3
  59. data/config/locales/hu.yml +56 -3
  60. data/config/locales/id-ID.yml +56 -3
  61. data/config/locales/it.yml +56 -3
  62. data/config/locales/nl.yml +56 -3
  63. data/config/locales/pl.yml +56 -3
  64. data/config/locales/pt-BR.yml +56 -3
  65. data/config/locales/pt.yml +56 -3
  66. data/config/locales/ru.yml +0 -3
  67. data/config/locales/sv.yml +56 -3
  68. data/config/locales/tr-TR.yml +56 -3
  69. data/config/locales/uk.yml +0 -3
  70. data/config/routes.rb +6 -0
  71. data/lib/decidim/admin/engine.rb +4 -1
  72. data/lib/decidim/admin/version.rb +1 -1
  73. metadata +32 -11
  74. data/app/events/decidim/participatory_process_step_activated_event.rb +0 -23
  75. data/app/events/decidim/participatory_process_step_changed_event.rb +0 -23
@@ -80,7 +80,7 @@ module Decidim
80
80
  managed: true,
81
81
  name: params.dig(:impersonate_user, :name)
82
82
  ) do |u|
83
- u.nickname = User.nicknamize(u.name, organization: current_organization)
83
+ u.nickname = UserBaseEntity.nicknamize(u.name, organization: current_organization)
84
84
  u.admin = false
85
85
  u.tos_agreement = true
86
86
  end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class StaticPageTopicsController < Decidim::Admin::ApplicationController
6
+ layout "decidim/admin/pages"
7
+ helper_method :topic
8
+
9
+ def new
10
+ enforce_permission_to :create, :static_page_topic
11
+ @form = form(StaticPageTopicForm).instance
12
+ end
13
+
14
+ def create
15
+ enforce_permission_to :create, :static_page_topic
16
+ @form = form(StaticPageTopicForm).from_params(params["static_page_topic"])
17
+
18
+ CreateStaticPageTopic.call(@form) do
19
+ on(:ok) do
20
+ flash[:notice] = I18n.t("static_page_topics.create.success", scope: "decidim.admin")
21
+ redirect_to static_pages_path
22
+ end
23
+
24
+ on(:invalid) do
25
+ flash.now[:alert] = I18n.t("static_page_topics.create.error", scope: "decidim.admin")
26
+ render :new
27
+ end
28
+ end
29
+ end
30
+
31
+ def edit
32
+ enforce_permission_to :update, :static_page_topic, static_page_topic: topic
33
+ @form = form(StaticPageTopicForm).from_model(topic)
34
+ end
35
+
36
+ def update
37
+ enforce_permission_to :update, :static_page_topic, static_page_topic: topic
38
+ @form = form(StaticPageTopicForm).from_params(params["static_page_topic"])
39
+
40
+ UpdateStaticPageTopic.call(topic, @form) do
41
+ on(:ok) do
42
+ flash[:notice] = I18n.t("static_page_topics.update.success", scope: "decidim.admin")
43
+ redirect_to static_pages_path
44
+ end
45
+
46
+ on(:invalid) do
47
+ flash.now[:alert] = I18n.t("static_page_topics.update.error", scope: "decidim.admin")
48
+ render :edit
49
+ end
50
+ end
51
+ end
52
+
53
+ def destroy
54
+ enforce_permission_to :destroy, :static_page_topic, static_page_topic: topic
55
+
56
+ DestroyStaticPage.call(topic, current_user) do
57
+ on(:ok) do
58
+ flash[:notice] = I18n.t("static_page_topics.destroy.success", scope: "decidim.admin")
59
+ redirect_to static_pages_path
60
+ end
61
+ end
62
+ end
63
+
64
+ private
65
+
66
+ def topic
67
+ @topic ||= StaticPageTopic.where(
68
+ organization: current_organization
69
+ ).find(params[:id])
70
+ end
71
+ end
72
+ end
73
+ end
@@ -8,9 +8,12 @@ module Decidim
8
8
  layout "decidim/admin/pages"
9
9
  before_action :tos_version_formatted, only: [:index, :edit]
10
10
 
11
+ helper_method :topics
12
+
11
13
  def index
12
14
  enforce_permission_to :read, :static_page
13
- @pages = collection
15
+ @topics = Decidim::StaticPageTopic.where(organization: current_organization)
16
+ @orphan_pages = collection.where(topic: nil)
14
17
  end
15
18
 
16
19
  def new
@@ -5,6 +5,10 @@ module Decidim
5
5
  # Controller that allows managing user groups at the admin panel.
6
6
  #
7
7
  class UserGroupsController < Decidim::Admin::ApplicationController
8
+ include UserGroups
9
+
10
+ before_action :enforce_user_groups_enabled
11
+
8
12
  layout "decidim/admin/users"
9
13
 
10
14
  def index
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # Controller that allows batch verifying user groups by uploading a CSV file.
6
+ class UserGroupsCsvVerificationsController < Decidim::Admin::ApplicationController
7
+ include UserGroups
8
+
9
+ before_action :enforce_user_groups_enabled
10
+
11
+ layout "decidim/admin/users"
12
+
13
+ def new
14
+ enforce_permission_to :csv_verify, :user_group
15
+ @form = form(UserGroupCsvVerificationForm).instance
16
+ end
17
+
18
+ def create
19
+ enforce_permission_to :csv_verify, :user_group
20
+ @form = form(UserGroupCsvVerificationForm).from_params(params)
21
+
22
+ ProcessUserGroupVerificationCsv.call(@form) do
23
+ on(:ok) do
24
+ flash[:notice] = I18n.t("user_group.csv_verify.success", scope: "decidim.admin")
25
+ redirect_to decidim_admin.user_groups_path
26
+ end
27
+
28
+ on(:invalid) do
29
+ flash[:alert] = I18n.t("user_group.csv_verify.invalid", scope: "decidim.admin")
30
+ render :new
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -12,6 +12,13 @@ module Decidim
12
12
  @resource.url
13
13
  end
14
14
 
15
+ def resource_text
16
+ translated_attribute(
17
+ resource.try(:description) ||
18
+ resource.try(:body)
19
+ )
20
+ end
21
+
15
22
  private
16
23
 
17
24
  def attached_to_url
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # This form contains the presentational and validation logic to update
6
+ # ContextualHelpSections from the admin panel.
7
+ class HelpSectionForm < Decidim::Form
8
+ include TranslatableAttributes
9
+ include TranslationsHelper
10
+
11
+ attribute :id, String
12
+ translatable_attribute :content, String
13
+
14
+ def name
15
+ multi_translation("activerecord.models.#{manifest.model_class_name.underscore}.other")
16
+ end
17
+
18
+ private
19
+
20
+ def manifest
21
+ @manifest ||= Decidim.find_participatory_space_manifest(id)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # This form contains the presentational and validation logic to update
6
+ # ContextualHelpSections in batch from the admin panel.
7
+ class HelpSectionsForm < Decidim::Form
8
+ attribute :sections, Array[HelpSectionForm]
9
+ end
10
+ end
11
+ end
@@ -19,6 +19,15 @@ module Decidim
19
19
  attribute :github_handler, String
20
20
  attribute :default_locale, String
21
21
  attribute :badges_enabled, Boolean
22
+ attribute :user_groups_enabled, Boolean
23
+
24
+ attribute :send_welcome_notification, Boolean
25
+ attribute :customize_welcome_notification, Boolean
26
+
27
+ translatable_attribute :welcome_notification_subject, String
28
+ translatable_attribute :welcome_notification_body, String
29
+
30
+ validates :welcome_notification_subject, :welcome_notification_body, translatable_presence: true, if: proc { |form| form.customize_welcome_notification }
22
31
 
23
32
  validates :name, presence: true
24
33
  validates :default_locale, :reference_prefix, presence: true
@@ -10,6 +10,9 @@ module Decidim
10
10
  translatable_attribute :title, String
11
11
  translatable_attribute :content, String
12
12
  attribute :changed_notably, Boolean
13
+ attribute :show_in_footer, Boolean
14
+ attribute :weight, Integer
15
+ attribute :topic_id, Integer
13
16
 
14
17
  mimic :static_page
15
18
 
@@ -25,6 +28,19 @@ module Decidim
25
28
  super.to_s.downcase
26
29
  end
27
30
 
31
+ def topic
32
+ @topic ||= StaticPageTopic.find_by(
33
+ organization: organization,
34
+ id: topic_id
35
+ )
36
+ end
37
+
38
+ def topics
39
+ @topics ||= StaticPageTopic.where(
40
+ organization: current_organization
41
+ )
42
+ end
43
+
28
44
  private
29
45
 
30
46
  def slug_uniqueness
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A form object to create or update pages.
6
+ class StaticPageTopicForm < Form
7
+ include TranslatableAttributes
8
+
9
+ translatable_attribute :title, String
10
+ translatable_attribute :description, String
11
+ attribute :show_in_footer, Boolean
12
+ attribute :weight, Integer
13
+
14
+ mimic :static_page_topic
15
+
16
+ validates :title, translatable_presence: true
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A form object used to upload CSV to batch verify user groups.
6
+ #
7
+ class UserGroupCsvVerificationForm < Form
8
+ attribute :file
9
+
10
+ validates :file, presence: true
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # Custom ApplicationJob scoped to the admin panel.
6
+ #
7
+ class VerifyUserGroupFromCsvJob < ApplicationJob
8
+ queue_as :default
9
+
10
+ def perform(email, verifier, organization)
11
+ @organization = organization
12
+ @email = email.downcase.strip
13
+
14
+ return if email.blank?
15
+ return unless user_group
16
+ Decidim::Admin::VerifyUserGroup.call(user_group, verifier, true)
17
+ end
18
+
19
+ private
20
+
21
+ def user_group
22
+ @user_group ||= UserGroup.where(organization: @organization)
23
+ .where.not(confirmed_at: nil)
24
+ .not_verified
25
+ .find_by(email: @email)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -43,6 +43,8 @@ module Decidim
43
43
  allow! if permission_action.subject == :officialization
44
44
  allow! if permission_action.subject == :authorization
45
45
  allow! if permission_action.subject == :authorization_workflow
46
+ allow! if permission_action.subject == :static_page_topic
47
+ allow! if permission_action.subject == :help_sections
46
48
  end
47
49
 
48
50
  permission_action
@@ -0,0 +1,21 @@
1
+ <%= decidim_form_for(form, url: help_sections_path, method: :put) do |f| %>
2
+ <% f.object.sections.each do |section| %>
3
+ <%= f.fields_for "sections[]", section do |section_form| %>
4
+ <div class="card" id="area-types">
5
+ <div class="card-divider">
6
+ <h2 class="card-title">
7
+ <%= translated_attribute section.name %>
8
+ </h2>
9
+ </div>
10
+ <div class="card-section">
11
+ <%= section_form.hidden_field :id %>
12
+ <%= section_form.translated :editor, :content, tabs_id: "sections_#{section_form.object.id}_content" %>
13
+ </div>
14
+ </div>
15
+ <% end %>
16
+ <% end %>
17
+
18
+ <div class="button--double form-general-submit">
19
+ <%= f.submit t(".save") %>
20
+ </div>
21
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render partial: "form", object: @form %>
@@ -0,0 +1 @@
1
+ <%= render partial: "form", object: @form %>
@@ -37,7 +37,7 @@
37
37
 
38
38
  <div class="card" id='user-groups'>
39
39
  <div class="card-divider">
40
- <h2 class="card-title"><%= t "decidim.admin.titles.officializations" %></h2>
40
+ <h2 class="card-title"><%= t "decidim.admin.titles.participants" %></h2>
41
41
  </div>
42
42
  <div class="card-section">
43
43
  <div class="table-scroll">
@@ -43,3 +43,25 @@
43
43
  <%= form.check_box :badges_enabled %>
44
44
  </div>
45
45
  </div>
46
+
47
+ <div class="row">
48
+ <div class="columns xlarge-6">
49
+ <%= form.check_box :user_groups_enabled %>
50
+ </div>
51
+ </div>
52
+
53
+ <div class="row" id="welcome-notification-details">
54
+ <div class="columns xlarge-6">
55
+ <%= form.check_box :send_welcome_notification %>
56
+ <div class="send-welcome-notification-details">
57
+ <%= form.check_box :customize_welcome_notification %>
58
+
59
+ <div class="customize-welcome-notification-details">
60
+ <%= form.translated :text_field, :welcome_notification_subject %>
61
+ <%= form.translated :editor, :welcome_notification_body %>
62
+ </div>
63
+ </div>
64
+ </div>
65
+ </div>
66
+
67
+ <%= javascript_include_tag "decidim/admin/welcome_notification.js" %>
@@ -0,0 +1,15 @@
1
+ <div class="row column">
2
+ <%= form.translated :text_field, :title, autofocus: true %>
3
+ </div>
4
+
5
+ <div class="row column">
6
+ <%= form.translated :text_field, :description %>
7
+ </div>
8
+
9
+ <div class="row column">
10
+ <%= form.number_field :weight %>
11
+ </div>
12
+
13
+ <div class="row column">
14
+ <%= form.check_box :show_in_footer %>
15
+ </div>
@@ -0,0 +1,13 @@
1
+ <%= decidim_form_for(@form, html: { class: "form edit_static_page_topic" }) do |f| %>
2
+ <div class="card">
3
+ <div class="card-divider">
4
+ <h2 class="card-title"><%= t ".title" %></h2>
5
+ </div>
6
+ <div class="card-section">
7
+ <%= render partial: "form", object: f %>
8
+ </div>
9
+ </div>
10
+ <div class="button--double form-general-submit">
11
+ <%= f.submit t(".update") %>
12
+ </div>
13
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <%= decidim_form_for(@form, html: { class: "form new_static_page_topic" }) do |f| %>
2
+ <div class="card">
3
+ <div class="card-divider">
4
+ <h2 class="card-title"><%= t ".title" %></h2>
5
+ </div>
6
+ <div class="card-section">
7
+ <%= render partial: "form", object: f %>
8
+ </div>
9
+ </div>
10
+ <div class="button--double form-general-submit">
11
+ <%= f.submit t(".create") %>
12
+ </div>
13
+ <% end %>
@@ -12,4 +12,16 @@
12
12
  <%= form.translated :editor, :content, toolbar: :full, lines: 25 %>
13
13
  </div>
14
14
 
15
+ <div class="row column">
16
+ <%= form.select :topic_id, form.object.topics.map { |topic| [translated_attribute(topic.title), topic.id] }, include_blank: t(".none") %>
17
+ </div>
18
+
15
19
  <%= render partial: "form_notable_changes", locals: { form: form } %>
20
+
21
+ <div class="row column">
22
+ <%= form.number_field :weight %>
23
+ </div>
24
+
25
+ <div class="row column">
26
+ <%= form.check_box :show_in_footer %>
27
+ </div>