decidim-admin 0.21.0 → 0.23.2

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 (197) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim/admin/application.js.es6 +7 -0
  3. data/app/assets/javascripts/decidim/admin/budget_rule_toggler.component.js.es6 +52 -0
  4. data/app/assets/javascripts/decidim/admin/bundle.js +26 -32
  5. data/app/assets/javascripts/decidim/admin/bundle.js.map +1 -1
  6. data/app/assets/javascripts/decidim/admin/choose_language.js +12 -0
  7. data/app/assets/javascripts/decidim/admin/dynamic_fields.component.js.es6 +24 -5
  8. data/app/assets/javascripts/decidim/admin/form.js.es6 +24 -10
  9. data/app/assets/javascripts/decidim/admin/gallery.js.es6 +5 -0
  10. data/app/assets/javascripts/decidim/admin/newsletters.js.es6 +4 -0
  11. data/app/assets/javascripts/decidim/admin/officializations.js.es6 +20 -0
  12. data/app/assets/javascripts/decidim/admin/scope_picker_enabler.component.js.es6 +14 -0
  13. data/app/assets/stylesheets/decidim/admin/_decidim.scss +2 -0
  14. data/app/assets/stylesheets/decidim/admin/_variables.scss +1 -1
  15. data/app/assets/stylesheets/decidim/admin/extra/_newsletter-templates-gallery.scss +3 -0
  16. data/app/assets/stylesheets/decidim/admin/extra/_organization-appearance.scss +141 -0
  17. data/app/assets/stylesheets/decidim/admin/extra/_show_email.scss +31 -0
  18. data/app/assets/stylesheets/decidim/admin/extra/_title_bar.scss +4 -0
  19. data/app/assets/stylesheets/decidim/admin/modules/_buttons.scss +11 -1
  20. data/app/assets/stylesheets/decidim/admin/modules/_callouts.scss +11 -0
  21. data/app/assets/stylesheets/decidim/admin/modules/_cards.scss +2 -2
  22. data/app/assets/stylesheets/decidim/admin/modules/_filters.scss +2 -2
  23. data/app/assets/stylesheets/decidim/admin/modules/_forms.scss +16 -2
  24. data/app/assets/stylesheets/decidim/admin/modules/_import_result.scss +10 -0
  25. data/app/assets/stylesheets/decidim/admin/modules/_loading-spinner.scss +19 -0
  26. data/app/assets/stylesheets/decidim/admin/modules/_main-nav.scss +0 -1
  27. data/app/assets/stylesheets/decidim/admin/modules/_modules.scss +5 -1
  28. data/app/assets/stylesheets/decidim/admin/modules/_process-header.scss +0 -1
  29. data/app/assets/stylesheets/decidim/admin/modules/_secondary-nav.scss +0 -1
  30. data/app/assets/stylesheets/decidim/admin/modules/_table-list.scss +0 -5
  31. data/app/assets/stylesheets/decidim/admin/modules/_tabs.scss +7 -0
  32. data/app/assets/stylesheets/decidim/admin/modules/_users_statistics.scss +18 -0
  33. data/app/assets/stylesheets/decidim/admin/utils/_mixins.scss +42 -0
  34. data/app/assets/stylesheets/decidim/admin/utils/_settings.scss +4 -1
  35. data/app/cells/decidim/admin/content_block/show.erb +2 -2
  36. data/app/commands/decidim/admin/create_attachment.rb +2 -2
  37. data/app/commands/decidim/admin/create_newsletter.rb +34 -9
  38. data/app/commands/decidim/admin/destroy_share_token.rb +46 -0
  39. data/app/commands/decidim/admin/reorder_content_blocks.rb +1 -1
  40. data/app/commands/decidim/admin/update_component.rb +27 -3
  41. data/app/commands/decidim/admin/update_content_block.rb +25 -1
  42. data/app/commands/decidim/admin/update_newsletter.rb +31 -9
  43. data/app/commands/decidim/admin/update_organization.rb +11 -0
  44. data/app/commands/decidim/admin/update_organization_appearance.rb +3 -1
  45. data/app/controllers/concerns/decidim/admin/participatory_space_export.rb +8 -2
  46. data/app/controllers/decidim/admin/application_controller.rb +1 -0
  47. data/app/controllers/decidim/admin/authorization_workflows_controller.rb +6 -0
  48. data/app/controllers/decidim/admin/components_controller.rb +17 -6
  49. data/app/controllers/decidim/admin/dashboard_controller.rb +33 -1
  50. data/app/controllers/decidim/admin/metrics_controller.rb +22 -0
  51. data/app/controllers/decidim/admin/newsletter_templates_controller.rb +41 -0
  52. data/app/controllers/decidim/admin/newsletters_controller.rb +32 -4
  53. data/app/controllers/decidim/admin/officializations_controller.rb +8 -0
  54. data/app/controllers/decidim/admin/organization_appearance_controller.rb +1 -0
  55. data/app/controllers/decidim/admin/organization_controller.rb +4 -3
  56. data/app/controllers/decidim/admin/organization_homepage_content_blocks_controller.rb +2 -1
  57. data/app/controllers/decidim/admin/share_tokens_controller.rb +30 -0
  58. data/app/forms/decidim/admin/attachment_form.rb +3 -0
  59. data/app/forms/decidim/admin/component_form.rb +5 -22
  60. data/app/forms/decidim/admin/newsletter_form.rb +15 -3
  61. data/app/forms/decidim/admin/organization_appearance_form.rb +7 -4
  62. data/app/forms/decidim/admin/organization_form.rb +20 -0
  63. data/app/forms/decidim/admin/participatory_space_private_user_csv_import_form.rb +13 -0
  64. data/app/forms/decidim/admin/participatory_space_private_user_form.rb +3 -2
  65. data/app/forms/decidim/admin/selective_newsletter_form.rb +6 -0
  66. data/app/frontend/components/autocomplete.component.test.tsx +2 -1
  67. data/app/frontend/components/autocomplete.component.tsx +29 -0
  68. data/app/helpers/decidim/admin/application_helper.rb +1 -0
  69. data/app/helpers/decidim/admin/filterable_helper.rb +35 -27
  70. data/app/helpers/decidim/admin/icon_link_helper.rb +1 -1
  71. data/app/helpers/decidim/admin/newsletters_helper.rb +3 -1
  72. data/app/helpers/decidim/admin/resource_scope_helper.rb +43 -0
  73. data/app/helpers/decidim/admin/settings_helper.rb +52 -59
  74. data/app/helpers/decidim/admin/uploader_image_dimensions_helper.rb +30 -0
  75. data/app/models/decidim/admin/fake_newsletter.rb +49 -0
  76. data/app/permissions/decidim/admin/permissions.rb +7 -1
  77. data/app/presenters/decidim/admin/dashboard_metric_charts_presenter.rb +57 -0
  78. data/app/queries/decidim/admin/active_users_counter.rb +35 -0
  79. data/app/queries/decidim/admin/newsletter_recipients.rb +5 -8
  80. data/app/views/decidim/admin/attachment_collections/index.html.erb +1 -1
  81. data/app/views/decidim/admin/authorization_workflows/index.html.erb +1 -0
  82. data/app/views/decidim/admin/categories/index.html.erb +1 -1
  83. data/app/views/decidim/admin/components/_component.html.erb +5 -0
  84. data/app/views/decidim/admin/components/_form.html.erb +4 -0
  85. data/app/views/decidim/admin/components/_settings_fields.html.erb +2 -2
  86. data/app/views/decidim/admin/components/index.html.erb +1 -0
  87. data/app/views/decidim/admin/dashboard/show.html.erb +35 -10
  88. data/app/views/decidim/admin/exports/_dropdown.html.erb +6 -2
  89. data/app/views/decidim/admin/impersonatable_users/index.html.erb +2 -2
  90. data/app/views/decidim/admin/metrics/_metrics.html.erb +21 -0
  91. data/app/views/decidim/admin/metrics/index.html.erb +7 -0
  92. data/app/views/decidim/admin/newsletter_templates/index.html.erb +28 -0
  93. data/app/views/decidim/admin/newsletter_templates/show.html.erb +12 -0
  94. data/app/views/decidim/admin/newsletters/_form.html.erb +1 -7
  95. data/app/views/decidim/admin/newsletters/edit.html.erb +1 -1
  96. data/app/views/decidim/admin/newsletters/index.html.erb +1 -1
  97. data/app/views/decidim/admin/newsletters/new.html.erb +1 -1
  98. data/app/views/decidim/admin/officializations/_show_email_modal.html.erb +31 -0
  99. data/app/views/decidim/admin/officializations/index.html.erb +7 -3
  100. data/app/views/decidim/admin/officializations/show_email.html.erb +2 -0
  101. data/app/views/decidim/admin/organization/_form.html.erb +21 -0
  102. data/app/views/decidim/admin/organization_appearance/_form.html.erb +2 -72
  103. data/app/views/decidim/admin/organization_appearance/form/_colors.html.erb +23 -0
  104. data/app/views/decidim/admin/organization_appearance/form/_images.html.erb +38 -0
  105. data/app/views/decidim/admin/organization_appearance/form/_minimap.html.erb +46 -0
  106. data/app/views/decidim/admin/resource_permissions/_options_form.html.erb +1 -1
  107. data/app/views/decidim/admin/share_tokens/_share_tokens.html.erb +57 -0
  108. data/app/views/decidim/admin/shared/_filters.html.erb +3 -3
  109. data/app/views/decidim/admin/shared/_gallery.html.erb +21 -0
  110. data/app/views/decidim/admin/static_pages/_form.html.erb +1 -1
  111. data/app/views/decidim/admin/user_groups/index.html.erb +4 -4
  112. data/app/views/decidim/admin/users_statistics/_users_count.html.erb +39 -0
  113. data/app/views/layouts/decidim/admin/_application.html.erb +1 -0
  114. data/app/views/layouts/decidim/admin/_header.html.erb +3 -0
  115. data/app/views/layouts/decidim/admin/_title_bar.html.erb +20 -10
  116. data/app/views/layouts/decidim/admin/newsletters.erb +1 -1
  117. data/config/locales/am-ET.yml +1 -0
  118. data/config/locales/ar.yml +12 -45
  119. data/config/locales/bg-BG.yml +16 -0
  120. data/config/locales/bg.yml +131 -0
  121. data/config/locales/ca.yml +84 -46
  122. data/config/locales/cs.yml +175 -137
  123. data/config/locales/da-DK.yml +1 -0
  124. data/config/locales/da.yml +1 -0
  125. data/config/locales/de.yml +150 -56
  126. data/config/locales/el.yml +814 -0
  127. data/config/locales/en.yml +84 -46
  128. data/config/locales/eo-UY.yml +0 -1
  129. data/config/locales/eo.yml +51 -0
  130. data/config/locales/es-MX.yml +84 -46
  131. data/config/locales/es-PY.yml +84 -46
  132. data/config/locales/es.yml +84 -46
  133. data/config/locales/et-EE.yml +1 -0
  134. data/config/locales/et.yml +1 -0
  135. data/config/locales/eu.yml +30 -59
  136. data/config/locales/fi-plain.yml +84 -46
  137. data/config/locales/fi.yml +98 -60
  138. data/config/locales/fr-CA.yml +847 -0
  139. data/config/locales/fr.yml +126 -51
  140. data/config/locales/ga-IE.yml +1 -0
  141. data/config/locales/gl.yml +156 -42
  142. data/config/locales/hr-HR.yml +1 -0
  143. data/config/locales/hr.yml +1 -0
  144. data/config/locales/hu.yml +55 -46
  145. data/config/locales/id-ID.yml +12 -41
  146. data/config/locales/is-IS.yml +10 -42
  147. data/config/locales/is.yml +568 -0
  148. data/config/locales/it.yml +106 -85
  149. data/config/locales/ja-JP.yml +855 -0
  150. data/config/locales/ja.yml +847 -0
  151. data/config/locales/ko-KR.yml +1 -0
  152. data/config/locales/ko.yml +1 -0
  153. data/config/locales/lt-LT.yml +1 -0
  154. data/config/locales/lt.yml +1 -0
  155. data/config/locales/lv.yml +795 -0
  156. data/config/locales/mt-MT.yml +1 -0
  157. data/config/locales/mt.yml +1 -0
  158. data/config/locales/nl.yml +74 -46
  159. data/config/locales/no.yml +108 -83
  160. data/config/locales/om-ET.yml +1 -0
  161. data/config/locales/pl.yml +354 -233
  162. data/config/locales/pt-BR.yml +13 -42
  163. data/config/locales/pt.yml +321 -231
  164. data/config/locales/ro-RO.yml +810 -0
  165. data/config/locales/ru.yml +11 -44
  166. data/config/locales/si-LK.yml +1 -0
  167. data/config/locales/sk-SK.yml +823 -0
  168. data/config/locales/sk.yml +802 -0
  169. data/config/locales/sl.yml +162 -0
  170. data/config/locales/so-SO.yml +1 -0
  171. data/config/locales/sr-CS.yml +586 -0
  172. data/config/locales/sv.yml +134 -54
  173. data/config/locales/sw-KE.yml +1 -0
  174. data/config/locales/ti-ER.yml +1 -0
  175. data/config/locales/tr-TR.yml +139 -50
  176. data/config/locales/uk.yml +10 -42
  177. data/config/locales/vi-VN.yml +1 -0
  178. data/config/locales/vi.yml +1 -0
  179. data/config/locales/zh-CN.yml +845 -0
  180. data/config/locales/zh-TW.yml +1 -0
  181. data/config/routes.rb +14 -3
  182. data/lib/decidim/admin/engine.rb +12 -9
  183. data/lib/decidim/admin/form_builder.rb +2 -2
  184. data/lib/decidim/admin/test/manage_attachment_collections_examples.rb +1 -1
  185. data/lib/decidim/admin/test/manage_component_permissions_examples.rb +15 -15
  186. data/lib/decidim/admin/version.rb +1 -1
  187. metadata +85 -33
  188. data/app/commands/decidim/admin/create_oauth_application.rb +0 -36
  189. data/app/commands/decidim/admin/destroy_oauth_application.rb +0 -39
  190. data/app/commands/decidim/admin/update_oauth_application.rb +0 -39
  191. data/app/controllers/decidim/admin/oauth_applications_controller.rb +0 -90
  192. data/app/forms/decidim/admin/oauth_application_form.rb +0 -32
  193. data/app/views/decidim/admin/oauth_applications/_form.html.erb +0 -19
  194. data/app/views/decidim/admin/oauth_applications/edit.html.erb +0 -13
  195. data/app/views/decidim/admin/oauth_applications/index.html.erb +0 -40
  196. data/app/views/decidim/admin/oauth_applications/new.html.erb +0 -13
  197. data/app/views/decidim/admin/oauth_applications/show.html.erb +0 -27
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic to destroy a share token.
6
+ class DestroyShareToken < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # share_token - The share_token to destroy
10
+ # current_user - the user performing the action
11
+ def initialize(share_token, current_user)
12
+ @share_token = share_token
13
+ @current_user = current_user
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
+ begin
24
+ destroy_share_token
25
+ rescue StandardError
26
+ broadcast(:invalid)
27
+ end
28
+ broadcast(:ok)
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :current_user
34
+
35
+ def destroy_share_token
36
+ Decidim.traceability.perform_action!(
37
+ "delete",
38
+ @share_token,
39
+ current_user
40
+ ) do
41
+ @share_token.destroy!
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -77,7 +77,7 @@ module Decidim
77
77
  def create_content_block(manifest_name, weight)
78
78
  Decidim::ContentBlock.create!(
79
79
  organization: organization,
80
- scope: scope,
80
+ scope_name: scope,
81
81
  weight: weight,
82
82
  manifest_name: manifest_name
83
83
  )
@@ -33,13 +33,15 @@ module Decidim
33
33
  private
34
34
 
35
35
  def update_component
36
- @previous_settings = @component.attributes["settings"].dup
37
-
36
+ @previous_settings = @component.attributes["settings"].with_indifferent_access
38
37
  @component.name = form.name
38
+ @component.weight = form.weight
39
+
40
+ restore_readonly_settings!
41
+
39
42
  @component.settings = form.settings
40
43
  @component.default_step_settings = form.default_step_settings
41
44
  @component.step_settings = form.step_settings
42
- @component.weight = form.weight
43
45
 
44
46
  @settings_changed = @component.settings_changed?
45
47
 
@@ -57,6 +59,28 @@ module Decidim
57
59
  def current_settings
58
60
  @component.attributes["settings"]
59
61
  end
62
+
63
+ # Keep previous values for readonly settings
64
+ def restore_readonly_settings!
65
+ browse_readonly_settings("global") do |attribute|
66
+ form.settings[attribute] = @previous_settings.dig("global", attribute)
67
+ end
68
+
69
+ browse_readonly_settings("step") do |attribute|
70
+ form.default_step_settings[attribute] = @previous_settings.dig("default_step", attribute) if form.default_step_settings.present?
71
+ if form.step_settings.present?
72
+ form.step_settings.each do |step_name, step|
73
+ step[attribute] = @previous_settings.dig("steps", step_name, attribute)
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ def browse_readonly_settings(settings_name)
80
+ @component.manifest.settings(settings_name).attributes
81
+ .select { |_attribute, obj| obj.readonly?(component: @component) }
82
+ .each { |attribute, _obj| yield(attribute) }
83
+ end
60
84
  end
61
85
  end
62
86
  end
@@ -24,13 +24,37 @@ module Decidim
24
24
  def call
25
25
  return broadcast(:invalid) if form.invalid?
26
26
 
27
+ images_valid = true
28
+
27
29
  transaction do
28
30
  update_content_block_settings
31
+ content_block.save!
32
+
33
+ # Saving the images will cause the image file validations to run
34
+ # according to their uploader settings and the organization settings.
35
+ # The content block validation will fail in case there are processing
36
+ # errors on the image files.
37
+ #
38
+ # NOTE:
39
+ # The images can be only stored correctly if the content block is
40
+ # already persisted. This is not the case e.g. when creating a new
41
+ # newsletter which uses the content blocks through newsletter
42
+ # templates. This is why this needs to happen after the initial
43
+ # `content_block.save!` call.
29
44
  update_content_block_images
45
+ unless content_block.valid?
46
+ images_valid = false
47
+ raise ActiveRecord::Rollback
48
+ end
49
+
50
+ # The save method needs to be called another time in order to store
51
+ # the image information.
30
52
  content_block.save!
31
53
  end
32
54
 
33
- broadcast(:ok)
55
+ return broadcast(:invalid) unless images_valid
56
+
57
+ broadcast(:ok, content_block)
34
58
  end
35
59
 
36
60
  private
@@ -11,25 +11,47 @@ module Decidim
11
11
  # user - The user that updates the newsletter.
12
12
  def initialize(newsletter, form, user)
13
13
  @newsletter = newsletter
14
+ @content_block = newsletter.template
14
15
  @form = form
15
16
  @user = user
16
17
  @organization = user.organization
17
18
  end
18
19
 
19
20
  def call
20
- return broadcast(:invalid) unless @form.valid?
21
- return broadcast(:invalid) if @newsletter.sent?
22
- return broadcast(:invalid) unless @organization == @newsletter.organization
21
+ return broadcast(:invalid) unless form.valid?
22
+ return broadcast(:invalid) if newsletter.sent?
23
+ return broadcast(:invalid) unless organization == newsletter.organization
23
24
 
25
+ transaction do
26
+ update_newsletter
27
+ update_content_block
28
+ end
29
+
30
+ broadcast(:ok, newsletter)
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :user, :newsletter, :content_block, :organization, :form
36
+
37
+ def update_newsletter
24
38
  @newsletter = Decidim.traceability.update!(
25
- @newsletter,
26
- @user,
27
- subject: @form.subject,
28
- body: @form.body,
29
- author: @user
39
+ newsletter,
40
+ user,
41
+ subject: form.subject,
42
+ author: user
30
43
  )
44
+ end
31
45
 
32
- broadcast(:ok, @newsletter)
46
+ def update_content_block
47
+ UpdateContentBlock.call(form, content_block, user) do
48
+ on(:ok) do |content_block|
49
+ @content_block = content_block
50
+ end
51
+ on(:invalid) do
52
+ raise "There was a problem persisting the changes to the content block"
53
+ end
54
+ end
33
55
  end
34
56
  end
35
57
  end
@@ -53,9 +53,12 @@ module Decidim
53
53
  github_handler: form.github_handler,
54
54
  badges_enabled: form.badges_enabled,
55
55
  user_groups_enabled: form.user_groups_enabled,
56
+ comments_max_length: form.comments_max_length,
57
+ enable_machine_translations: form.enable_machine_translations,
56
58
  admin_terms_of_use_body: form.admin_terms_of_use_body,
57
59
  rich_text_editor_in_public_views: form.rich_text_editor_in_public_views
58
60
  }.merge(welcome_notification_attributes)
61
+ .merge(machine_translation_attributes || {})
59
62
  end
60
63
 
61
64
  def welcome_notification_attributes
@@ -65,6 +68,14 @@ module Decidim
65
68
  welcome_notification_body: form.customize_welcome_notification ? form.welcome_notification_body : nil
66
69
  }
67
70
  end
71
+
72
+ def machine_translation_attributes
73
+ return unless Decidim.config.enable_machine_translations
74
+
75
+ {
76
+ machine_translation_display_priority: form.machine_translation_display_priority
77
+ }
78
+ end
68
79
  end
69
80
  end
70
81
  end
@@ -102,7 +102,9 @@ module Decidim
102
102
  secondary: form.secondary_color,
103
103
  success: form.success_color,
104
104
  warning: form.warning_color,
105
- alert: form.alert_color
105
+ alert: form.alert_color,
106
+ highlight: form.highlight_color,
107
+ "highlight-alternative": form.highlight_alternative_color
106
108
  }
107
109
  }
108
110
  end
@@ -11,19 +11,25 @@ module Decidim
11
11
  def create
12
12
  enforce_permission_to :create, :export_space, participatory_space: exportable_space
13
13
 
14
- ExportParticipatorySpaceJob.perform_later(current_user, exportable_space, "participatory_processes", default_format)
14
+ ExportParticipatorySpaceJob.perform_later(current_user, exportable_space, manifest_name, default_format)
15
15
 
16
16
  flash[:notice] = t("decidim.admin.exports.notice")
17
17
 
18
18
  redirect_back(fallback_location: after_export_path)
19
19
  end
20
20
 
21
- # Public: The only method to be implemented at the controller. You need to
21
+ # Public: To be implemented at the controller. You need to
22
22
  # return the space that will be exported.
23
23
  def exportable_space
24
24
  raise NotImplementedError
25
25
  end
26
26
 
27
+ # Public: To be implemented at the controller. You need to
28
+ # return the plural of the name of the space that will be exported.
29
+ def manifest_name
30
+ raise NotImplementedError
31
+ end
32
+
27
33
  # Public: Returns a String or Object that will be passed to `redirect_to` after
28
34
  # exporing a space. By default it redirects to the root_path.
29
35
  #
@@ -6,6 +6,7 @@ module Decidim
6
6
  class ApplicationController < ::DecidimController
7
7
  include NeedsOrganization
8
8
  include NeedsPermission
9
+ include NeedsSnippets
9
10
  include FormFactory
10
11
  include LocaleSwitcher
11
12
  include UseOrganizationTimeZone
@@ -9,6 +9,12 @@ module Decidim
9
9
  enforce_permission_to :index, :authorization_workflow
10
10
 
11
11
  @workflows = Decidim::Verifications.admin_workflows
12
+
13
+ # Decidim::Verifications::Authorizations Query
14
+ @authorizations = Decidim::Verifications::Authorizations.new(
15
+ organization: current_organization,
16
+ granted: true
17
+ ).query
12
18
  end
13
19
  end
14
20
  end
@@ -20,14 +20,17 @@ module Decidim
20
20
  @component = Component.new(
21
21
  name: default_name(manifest),
22
22
  manifest_name: params[:type],
23
- participatory_space: current_participatory_space
23
+ participatory_space: current_participatory_space,
24
+ settings: {
25
+ scope_id: current_participatory_space.scope.try(:id)
26
+ }
24
27
  )
25
28
 
26
- @form = form(ComponentForm).from_model(@component)
29
+ @form = form(@component.form_class).from_model(@component)
27
30
  end
28
31
 
29
32
  def create
30
- @form = form(ComponentForm).from_params(component_params)
33
+ @form = form(manifest.component_form_class).from_params(component_params)
31
34
  enforce_permission_to :create, :component
32
35
 
33
36
  CreateComponent.call(@form) do
@@ -47,12 +50,12 @@ module Decidim
47
50
  @component = query_scope.find(params[:id])
48
51
  enforce_permission_to :update, :component, component: @component
49
52
 
50
- @form = form(ComponentForm).from_model(@component)
53
+ @form = form(@component.form_class).from_model(@component)
51
54
  end
52
55
 
53
56
  def update
54
57
  @component = query_scope.find(params[:id])
55
- @form = form(ComponentForm).from_params(component_params)
58
+ @form = form(@component.form_class).from_params(component_params)
56
59
  enforce_permission_to :update, :component, component: @component
57
60
 
58
61
  UpdateComponent.call(@form, @component) do
@@ -111,9 +114,16 @@ module Decidim
111
114
  end
112
115
  end
113
116
 
117
+ def share
118
+ @component = query_scope.find(params[:id])
119
+ share_token = @component.share_tokens.create!(user: current_user, organization: current_organization)
120
+
121
+ redirect_to share_token.url
122
+ end
123
+
114
124
  private
115
125
 
116
- # Processes the component params so Decidim::Admin::ComponentForm
126
+ # Processes the component params so the form object defined in the manifest (component_form_class_name)
117
127
  # can assign and validate the attributes when using #from_params.
118
128
  def component_params
119
129
  new_settings = proc { |name, data| Component.build_settings(manifest, name, data, current_organization) }
@@ -126,6 +136,7 @@ module Decidim
126
136
  if hsh[:default_step_settings]
127
137
  hsh[:default_step_settings] = new_settings.call(:step, hsh[:default_step_settings])
128
138
  else
139
+ hsh[:step_settings] ||= {}
129
140
  hsh[:step_settings].each do |key, value|
130
141
  hsh[:step_settings][key] = new_settings.call(:step, value)
131
142
  end
@@ -6,6 +6,8 @@ module Decidim
6
6
  #
7
7
  class DashboardController < Decidim::Admin::ApplicationController
8
8
  helper_method :latest_action_logs
9
+ helper_method :users_counter
10
+ helper_method :metrics_presenter
9
11
 
10
12
  def show
11
13
  enforce_permission_to :read, :admin_dashboard
@@ -19,7 +21,37 @@ module Decidim
19
21
  .includes(:participatory_space, :user, :resource, :component, :version)
20
22
  .for_admin
21
23
  .order(created_at: :desc)
22
- .first(20)
24
+ .first(5)
25
+ end
26
+
27
+ def metrics_presenter
28
+ @metrics_presenter ||= Decidim::Admin::DashboardMetricChartsPresenter.new(
29
+ summary: true,
30
+ organization: current_organization
31
+ )
32
+ end
33
+
34
+ def users_counter
35
+ last_day = Time.zone.yesterday
36
+ last_week = Time.zone.today.prev_week
37
+ last_month = Time.zone.today.prev_month
38
+
39
+ {
40
+ total_admins_last_24: users_count(last_day, true),
41
+ total_admins_last_week: users_count(last_week, true),
42
+ total_admins_last_month: users_count(last_month, true),
43
+ total_participants_last_24: users_count(last_day, false),
44
+ total_participants_last_week: users_count(last_week, false),
45
+ total_participants_last_month: users_count(last_month, false)
46
+ }
47
+ end
48
+
49
+ def users_count(date, admin)
50
+ @users_count = Decidim::Admin::ActiveUsersCounter.new(
51
+ organization: current_organization,
52
+ date: date,
53
+ admin: admin
54
+ ).query.count
23
55
  end
24
56
  end
25
57
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class MetricsController < Decidim::Admin::ApplicationController
6
+ helper_method :metrics_presenter
7
+
8
+ def index
9
+ enforce_permission_to :read, :metrics
10
+ end
11
+
12
+ private
13
+
14
+ def metrics_presenter
15
+ @metrics_presenter ||= Decidim::Admin::DashboardMetricChartsPresenter.new(
16
+ summary: false,
17
+ organization: current_organization
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # Controller that allows managing newsletters.
6
+ class NewsletterTemplatesController < Decidim::Admin::ApplicationController
7
+ helper_method :templates, :template_manifest
8
+
9
+ layout "decidim/admin/newsletters"
10
+
11
+ def index
12
+ enforce_permission_to :index, :newsletter
13
+ end
14
+
15
+ def show; end
16
+
17
+ def preview
18
+ email = NewsletterMailer.newsletter(current_user, fake_newsletter)
19
+ Premailer::Rails::Hook.perform(email)
20
+ render html: email.html_part.body.decoded.html_safe
21
+ end
22
+
23
+ private
24
+
25
+ def templates
26
+ @templates ||= Decidim.content_blocks.for(:newsletter_template)
27
+ end
28
+
29
+ def template_manifest
30
+ @template_manifest ||= Decidim
31
+ .content_blocks
32
+ .for(:newsletter_template)
33
+ .find { |manifest| manifest.name.to_s == params[:id] }
34
+ end
35
+
36
+ def fake_newsletter
37
+ @fake_newsletter ||= Decidim::Admin::FakeNewsletter.new(current_organization, template_manifest)
38
+ end
39
+ end
40
+ end
41
+ end