decidim-admin 0.20.1 → 0.23.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.

Files changed (220) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -0
  3. data/app/assets/javascripts/decidim/admin/application.js.es6 +8 -0
  4. data/app/assets/javascripts/decidim/admin/budget_rule_toggler.component.js.es6 +52 -0
  5. data/app/assets/javascripts/decidim/admin/bundle.js +26 -32
  6. data/app/assets/javascripts/decidim/admin/bundle.js.map +1 -1
  7. data/app/assets/javascripts/decidim/admin/choose_language.js +12 -0
  8. data/app/assets/javascripts/decidim/admin/dynamic_fields.component.js.es6 +24 -5
  9. data/app/assets/javascripts/decidim/admin/form.js.es6 +24 -10
  10. data/app/assets/javascripts/decidim/admin/gallery.js.es6 +5 -0
  11. data/app/assets/javascripts/decidim/admin/newsletters.js.es6 +12 -0
  12. data/app/assets/javascripts/decidim/admin/officializations.js.es6 +20 -0
  13. data/app/assets/javascripts/decidim/admin/scope_picker_enabler.component.js.es6 +14 -0
  14. data/app/assets/stylesheets/decidim/admin/_decidim.scss +2 -0
  15. data/app/assets/stylesheets/decidim/admin/_variables.scss +2 -2
  16. data/app/assets/stylesheets/decidim/admin/extra/_action-icon.scss +6 -0
  17. data/app/assets/stylesheets/decidim/admin/extra/_cards.scss +11 -0
  18. data/app/assets/stylesheets/decidim/admin/extra/_newsletter-templates-gallery.scss +3 -0
  19. data/app/assets/stylesheets/decidim/admin/extra/_organization-appearance.scss +141 -0
  20. data/app/assets/stylesheets/decidim/admin/extra/_show_email.scss +31 -0
  21. data/app/assets/stylesheets/decidim/admin/extra/_title_bar.scss +4 -0
  22. data/app/assets/stylesheets/decidim/admin/modules/_buttons.scss +15 -1
  23. data/app/assets/stylesheets/decidim/admin/modules/_callouts.scss +11 -0
  24. data/app/assets/stylesheets/decidim/admin/modules/_cards.scss +13 -2
  25. data/app/assets/stylesheets/decidim/admin/modules/_filters.scss +78 -1
  26. data/app/assets/stylesheets/decidim/admin/modules/_forms.scss +16 -2
  27. data/app/assets/stylesheets/decidim/admin/modules/_import_result.scss +10 -0
  28. data/app/assets/stylesheets/decidim/admin/modules/_layout.scss +1 -1
  29. data/app/assets/stylesheets/decidim/admin/modules/_loading-spinner.scss +19 -0
  30. data/app/assets/stylesheets/decidim/admin/modules/_main-nav.scss +0 -1
  31. data/app/assets/stylesheets/decidim/admin/modules/_modules.scss +5 -1
  32. data/app/assets/stylesheets/decidim/admin/modules/_process-header.scss +0 -1
  33. data/app/assets/stylesheets/decidim/admin/modules/_secondary-nav.scss +5 -2
  34. data/app/assets/stylesheets/decidim/admin/modules/_table-list.scss +23 -7
  35. data/app/assets/stylesheets/decidim/admin/modules/_tabs.scss +7 -0
  36. data/app/assets/stylesheets/decidim/admin/modules/_users_statistics.scss +18 -0
  37. data/app/assets/stylesheets/decidim/admin/utils/_mixins.scss +42 -0
  38. data/app/assets/stylesheets/decidim/admin/utils/_settings.scss +4 -1
  39. data/app/cells/decidim/admin/content_block/show.erb +2 -2
  40. data/app/cells/decidim/admin/results_per_page/show.erb +16 -0
  41. data/app/cells/decidim/admin/results_per_page_cell.rb +14 -0
  42. data/app/commands/decidim/admin/create_attachment.rb +2 -2
  43. data/app/commands/decidim/admin/create_newsletter.rb +34 -9
  44. data/app/commands/decidim/admin/deliver_newsletter.rb +1 -1
  45. data/app/commands/decidim/admin/destroy_share_token.rb +46 -0
  46. data/app/commands/decidim/admin/reorder_content_blocks.rb +1 -1
  47. data/app/commands/decidim/admin/update_component.rb +27 -3
  48. data/app/commands/decidim/admin/update_content_block.rb +25 -1
  49. data/app/commands/decidim/admin/update_newsletter.rb +31 -9
  50. data/app/commands/decidim/admin/update_organization.rb +15 -1
  51. data/app/commands/decidim/admin/update_organization_appearance.rb +3 -1
  52. data/app/controllers/concerns/decidim/admin/filterable.rb +152 -0
  53. data/app/controllers/concerns/decidim/admin/officializations/filterable.rb +31 -0
  54. data/app/controllers/concerns/decidim/admin/paginable.rb +20 -0
  55. data/app/controllers/concerns/decidim/admin/participatory_space_export.rb +8 -2
  56. data/app/controllers/decidim/admin/admin_terms_controller.rb +20 -0
  57. data/app/controllers/decidim/admin/application_controller.rb +3 -0
  58. data/app/controllers/decidim/admin/authorization_workflows_controller.rb +6 -0
  59. data/app/controllers/decidim/admin/components/base_controller.rb +5 -1
  60. data/app/controllers/decidim/admin/components_controller.rb +30 -23
  61. data/app/controllers/decidim/admin/concerns/has_private_users.rb +4 -0
  62. data/app/controllers/decidim/admin/dashboard_controller.rb +33 -1
  63. data/app/controllers/decidim/admin/metrics_controller.rb +22 -0
  64. data/app/controllers/decidim/admin/newsletter_templates_controller.rb +41 -0
  65. data/app/controllers/decidim/admin/newsletters_controller.rb +43 -4
  66. data/app/controllers/decidim/admin/officializations_controller.rb +15 -6
  67. data/app/controllers/decidim/admin/organization_appearance_controller.rb +1 -0
  68. data/app/controllers/decidim/admin/organization_controller.rb +4 -3
  69. data/app/controllers/decidim/admin/organization_homepage_content_blocks_controller.rb +2 -1
  70. data/app/controllers/decidim/admin/share_tokens_controller.rb +30 -0
  71. data/app/forms/decidim/admin/attachment_form.rb +3 -0
  72. data/app/forms/decidim/admin/component_form.rb +5 -22
  73. data/app/forms/decidim/admin/newsletter_form.rb +15 -3
  74. data/app/forms/decidim/admin/organization_appearance_form.rb +7 -4
  75. data/app/forms/decidim/admin/organization_form.rb +27 -0
  76. data/app/forms/decidim/admin/participatory_space_private_user_csv_import_form.rb +14 -0
  77. data/app/forms/decidim/admin/participatory_space_private_user_form.rb +8 -2
  78. data/app/frontend/components/autocomplete.component.test.tsx +2 -1
  79. data/app/frontend/components/autocomplete.component.tsx +29 -0
  80. data/app/helpers/decidim/admin/admin_terms_helper.rb +47 -0
  81. data/app/helpers/decidim/admin/application_helper.rb +2 -0
  82. data/app/helpers/decidim/admin/dashboard_helper.rb +25 -0
  83. data/app/helpers/decidim/admin/filterable_helper.rb +129 -0
  84. data/app/helpers/decidim/admin/icon_link_helper.rb +1 -1
  85. data/app/helpers/decidim/admin/newsletters_helper.rb +20 -0
  86. data/app/helpers/decidim/admin/paginable/per_page_helper.rb +22 -0
  87. data/app/helpers/decidim/admin/resource_scope_helper.rb +43 -0
  88. data/app/helpers/decidim/admin/scopes_helper.rb +6 -0
  89. data/app/helpers/decidim/admin/settings_helper.rb +56 -47
  90. data/app/helpers/decidim/admin/uploader_image_dimensions_helper.rb +30 -0
  91. data/app/helpers/decidim/admin/user_roles_helper.rb +19 -0
  92. data/app/models/decidim/admin/fake_newsletter.rb +49 -0
  93. data/app/permissions/decidim/admin/permissions.rb +30 -7
  94. data/app/presenters/decidim/admin/dashboard_metric_charts_presenter.rb +57 -0
  95. data/app/queries/decidim/admin/active_users_counter.rb +35 -0
  96. data/app/queries/decidim/admin/newsletter_recipients.rb +20 -9
  97. data/app/views/decidim/admin/admin_terms/show.html.erb +26 -0
  98. data/app/views/decidim/admin/attachment_collections/index.html.erb +1 -1
  99. data/app/views/decidim/admin/authorization_workflows/index.html.erb +1 -0
  100. data/app/views/decidim/admin/categories/index.html.erb +1 -1
  101. data/app/views/decidim/admin/components/_component.html.erb +40 -33
  102. data/app/views/decidim/admin/components/_form.html.erb +4 -0
  103. data/app/views/decidim/admin/components/_settings_fields.html.erb +2 -2
  104. data/app/views/decidim/admin/components/index.html.erb +11 -8
  105. data/app/views/decidim/admin/dashboard/show.html.erb +49 -9
  106. data/app/views/decidim/admin/exports/_dropdown.html.erb +6 -2
  107. data/app/views/decidim/admin/impersonatable_users/index.html.erb +2 -2
  108. data/app/views/decidim/admin/metrics/_metrics.html.erb +21 -0
  109. data/app/views/decidim/admin/metrics/index.html.erb +7 -0
  110. data/app/views/decidim/admin/newsletter_templates/index.html.erb +28 -0
  111. data/app/views/decidim/admin/newsletter_templates/show.html.erb +12 -0
  112. data/app/views/decidim/admin/newsletters/_form.html.erb +1 -7
  113. data/app/views/decidim/admin/newsletters/edit.html.erb +1 -1
  114. data/app/views/decidim/admin/newsletters/index.html.erb +9 -3
  115. data/app/views/decidim/admin/newsletters/new.html.erb +1 -1
  116. data/app/views/decidim/admin/newsletters/select_recipients_to_deliver.html.erb +4 -4
  117. data/app/views/decidim/admin/officializations/_show_email_modal.html.erb +31 -0
  118. data/app/views/decidim/admin/officializations/index.html.erb +9 -41
  119. data/app/views/decidim/admin/officializations/show_email.html.erb +2 -0
  120. data/app/views/decidim/admin/organization/_form.html.erb +37 -0
  121. data/app/views/decidim/admin/organization_appearance/_form.html.erb +2 -72
  122. data/app/views/decidim/admin/organization_appearance/form/_colors.html.erb +23 -0
  123. data/app/views/decidim/admin/organization_appearance/form/_images.html.erb +38 -0
  124. data/app/views/decidim/admin/organization_appearance/form/_minimap.html.erb +46 -0
  125. data/app/views/decidim/admin/resource_permissions/_options_form.html.erb +1 -1
  126. data/app/views/decidim/admin/share_tokens/_share_tokens.html.erb +57 -0
  127. data/app/views/decidim/admin/shared/_filters.html.erb +40 -0
  128. data/app/views/decidim/admin/shared/_gallery.html.erb +21 -0
  129. data/app/views/decidim/admin/static_pages/_form.html.erb +1 -1
  130. data/app/views/decidim/admin/user_groups/index.html.erb +4 -4
  131. data/app/views/decidim/admin/users_statistics/_users_count.html.erb +39 -0
  132. data/app/views/layouts/decidim/admin/_application.html.erb +2 -1
  133. data/app/views/layouts/decidim/admin/_header.html.erb +3 -0
  134. data/app/views/layouts/decidim/admin/_title_bar.html.erb +20 -10
  135. data/app/views/layouts/decidim/admin/newsletters.erb +1 -1
  136. data/config/locales/am-ET.yml +1 -0
  137. data/config/locales/ar.yml +52 -47
  138. data/config/locales/bg-BG.yml +16 -0
  139. data/config/locales/bg.yml +135 -0
  140. data/config/locales/ca.yml +127 -48
  141. data/config/locales/cs.yml +182 -103
  142. data/config/locales/da-DK.yml +1 -0
  143. data/config/locales/da.yml +1 -0
  144. data/config/locales/de.yml +145 -47
  145. data/config/locales/el.yml +819 -0
  146. data/config/locales/en.yml +127 -48
  147. data/config/locales/eo-UY.yml +0 -1
  148. data/config/locales/eo.yml +51 -0
  149. data/config/locales/es-MX.yml +127 -48
  150. data/config/locales/es-PY.yml +127 -48
  151. data/config/locales/es.yml +127 -48
  152. data/config/locales/et-EE.yml +1 -0
  153. data/config/locales/et.yml +1 -0
  154. data/config/locales/eu.yml +21 -47
  155. data/config/locales/fi-plain.yml +127 -48
  156. data/config/locales/fi.yml +140 -61
  157. data/config/locales/fr-CA.yml +849 -0
  158. data/config/locales/fr.yml +133 -53
  159. data/config/locales/ga-IE.yml +1 -0
  160. data/config/locales/gl.yml +21 -47
  161. data/config/locales/hr-HR.yml +1 -0
  162. data/config/locales/hr.yml +1 -0
  163. data/config/locales/hu.yml +100 -48
  164. data/config/locales/id-ID.yml +21 -47
  165. data/config/locales/is-IS.yml +19 -45
  166. data/config/locales/is.yml +568 -0
  167. data/config/locales/it.yml +132 -83
  168. data/config/locales/ja-JP.yml +855 -0
  169. data/config/locales/ja.yml +849 -0
  170. data/config/locales/ko-KR.yml +1 -0
  171. data/config/locales/ko.yml +1 -0
  172. data/config/locales/lt-LT.yml +1 -0
  173. data/config/locales/lt.yml +1 -0
  174. data/config/locales/lv.yml +799 -0
  175. data/config/locales/mt-MT.yml +1 -0
  176. data/config/locales/mt.yml +1 -0
  177. data/config/locales/nl.yml +102 -48
  178. data/config/locales/no.yml +147 -84
  179. data/config/locales/om-ET.yml +1 -0
  180. data/config/locales/pl.yml +364 -238
  181. data/config/locales/pt-BR.yml +22 -48
  182. data/config/locales/pt.yml +334 -237
  183. data/config/locales/ro-RO.yml +814 -0
  184. data/config/locales/ru.yml +20 -46
  185. data/config/locales/sk-SK.yml +823 -0
  186. data/config/locales/sk.yml +806 -0
  187. data/config/locales/sl.yml +166 -0
  188. data/config/locales/so-SO.yml +1 -0
  189. data/config/locales/sr-CS.yml +590 -0
  190. data/config/locales/sv.yml +140 -55
  191. data/config/locales/ti-ER.yml +1 -0
  192. data/config/locales/tr-TR.yml +21 -47
  193. data/config/locales/uk.yml +19 -48
  194. data/config/locales/vi-VN.yml +1 -0
  195. data/config/locales/vi.yml +1 -0
  196. data/config/locales/zh-CN.yml +849 -0
  197. data/config/locales/zh-TW.yml +1 -0
  198. data/config/routes.rb +20 -3
  199. data/db/migrate/20191118112040_add_accepted_admin_terms_at_field_to_users.rb +7 -0
  200. data/lib/decidim/admin.rb +17 -0
  201. data/lib/decidim/admin/engine.rb +12 -9
  202. data/lib/decidim/admin/form_builder.rb +7 -2
  203. data/lib/decidim/admin/test.rb +2 -0
  204. data/lib/decidim/admin/test/filterable_examples.rb +129 -0
  205. data/lib/decidim/admin/test/manage_attachment_collections_examples.rb +1 -1
  206. data/lib/decidim/admin/test/manage_component_permissions_examples.rb +15 -15
  207. data/lib/decidim/admin/test/manage_paginated_collection_examples.rb +22 -0
  208. data/lib/decidim/admin/version.rb +1 -1
  209. data/vendor/assets/javascripts/jquery.serializejson.js +344 -0
  210. metadata +98 -30
  211. data/app/commands/decidim/admin/create_oauth_application.rb +0 -36
  212. data/app/commands/decidim/admin/destroy_oauth_application.rb +0 -39
  213. data/app/commands/decidim/admin/update_oauth_application.rb +0 -39
  214. data/app/controllers/decidim/admin/oauth_applications_controller.rb +0 -90
  215. data/app/forms/decidim/admin/oauth_application_form.rb +0 -32
  216. data/app/views/decidim/admin/oauth_applications/_form.html.erb +0 -19
  217. data/app/views/decidim/admin/oauth_applications/edit.html.erb +0 -13
  218. data/app/views/decidim/admin/oauth_applications/index.html.erb +0 -40
  219. data/app/views/decidim/admin/oauth_applications/new.html.erb +0 -13
  220. data/app/views/decidim/admin/oauth_applications/show.html.erb +0 -27
@@ -32,6 +32,12 @@ module Decidim
32
32
  Option.new(scope_type.id, translated_attribute(scope_type.name))
33
33
  end
34
34
  end
35
+
36
+ def organization_scope_depths(organization = current_organization)
37
+ organization.scope_types.map do |scope_type|
38
+ Option.new(scope_type.id, translated_attribute(scope_type.name))
39
+ end.reverse
40
+ end
35
41
  end
36
42
  end
37
43
  end
@@ -5,11 +5,15 @@ module Decidim
5
5
  # This class contains helpers needed in order for component settings to
6
6
  # properly render.
7
7
  module SettingsHelper
8
+ include Decidim::ScopesHelper
9
+
8
10
  TYPES = {
9
11
  boolean: :check_box,
10
12
  integer: :number_field,
11
13
  string: :text_field,
12
- text: :text_area
14
+ text: :text_area,
15
+ scope: :scope_field,
16
+ enum: :collection_radio_buttons
13
17
  }.freeze
14
18
 
15
19
  # Public: Renders a form field that matches a settings attribute's
@@ -22,41 +26,61 @@ module Decidim
22
26
  # options - Extra options to be passed to the field helper.
23
27
  #
24
28
  # Returns a rendered form field.
25
- def settings_attribute_input(form, attribute, name, options = {})
26
- if name == :amendments_visibility
27
- amendments_visibility_form_field(form, options)
28
- elsif attribute.translated?
29
- form.send(:translated, form_method_for_attribute(attribute), name, options.merge(tabs_id: "#{options[:tabs_prefix]}-#{name}-tabs"))
30
- else
31
- form.send(form_method_for_attribute(attribute), name, options.merge(extra_options_for(name)))
29
+ def settings_attribute_input(form, attribute, name, i18n_scope, options = {})
30
+ form_method = form_method_for_attribute(attribute)
31
+
32
+ container_class = "#{name}_container"
33
+ if options[:readonly]
34
+ container_class += " readonly_container"
35
+ help_text = text_for_setting(name, "readonly", i18n_scope)
32
36
  end
33
- end
37
+ help_text ||= text_for_setting(name, "help", i18n_scope)
38
+ help_text_options = help_text ? { help_text: help_text } : {}
34
39
 
35
- # Returns a translation or nil. If nil, ZURB Foundation won't add the help_text.
36
- def help_text_for_component_setting(field_name, settings_name, component_name)
37
- key = "decidim.components.#{component_name}.settings.#{settings_name}.#{field_name}_help"
38
- return t(key) if I18n.exists?(key)
40
+ options = { label: t(name, scope: i18n_scope) }
41
+ .merge(help_text_options)
42
+ .merge(extra_options_for_type(form_method))
43
+ .merge(options)
44
+
45
+ content_tag(:div, class: container_class) do
46
+ if attribute.translated?
47
+ options[:tabs_id] = "#{options.delete(:tabs_prefix)}-#{name}-tabs"
48
+ form.send(:translated, form_method, name, options)
49
+ elsif form_method == :collection_radio_buttons
50
+ render_enum_form_field(form, attribute, name, i18n_scope, options)
51
+ elsif form_method == :scope_field
52
+ scopes_picker_field(form, name)
53
+ else
54
+ form.send(form_method, name, options)
55
+ end
56
+ end.html_safe
39
57
  end
40
58
 
41
59
  private
42
60
 
43
- # Returns a radio buttons collection input for the component's step setting
44
- # :amendments_visibility; all wrap in a label tag and with help text.
45
- def amendments_visibility_form_field(form, options)
46
- html = label_tag(:amendments_visibility) do
61
+ # Returns a radio buttons collection input for the given attribute
62
+ def render_enum_form_field(form, attribute, name, i18n_scope, options)
63
+ html = label_tag(name) do
47
64
  concat options[:label]
48
65
  concat tag(:br)
49
- concat form.collection_radio_buttons(:amendments_visibility,
50
- Decidim::Amendment::VisibilityStepSetting.options,
66
+ concat form.collection_radio_buttons(name,
67
+ build_enum_choices(name, i18n_scope, attribute.build_choices),
51
68
  :last,
52
69
  :first,
53
- { checked: form.object.amendments_visibility },
54
- amendments_extra_options) { |b| b.label { b.radio_button + b.text } }
70
+ { checked: form.object.send(name) },
71
+ options) { |b| b.label { b.radio_button + b.text } }
55
72
  end
56
- html << content_tag(:p, help_text_for_component_setting(:amendments_visibility, :step, :proposals), class: "help-text")
57
- html.html_safe
73
+ html << content_tag(:p, options[:help_text], class: "help-text") if options[:help_text]
74
+ html
58
75
  end
59
76
 
77
+ # Returns a translation or nil. If nil, ZURB Foundation won't add the help_text.
78
+ def text_for_setting(name, suffix, i18n_scope)
79
+ key = "#{i18n_scope}.#{name}_#{suffix}"
80
+ return t(key) if I18n.exists?(key)
81
+ end
82
+
83
+ # Returns the FormBuilder's method used to render
60
84
  def form_method_for_attribute(attribute)
61
85
  return :editor if attribute.type.to_sym == :text && attribute.editor?
62
86
 
@@ -65,35 +89,20 @@ module Decidim
65
89
 
66
90
  # Handles special cases.
67
91
  # Returns an empty Hash or a Hash with extra HTML options.
68
- def extra_options_for(field_name)
69
- case field_name
70
- when :participatory_texts_enabled
71
- participatory_texts_extra_options
72
- when :amendment_creation_enabled,
73
- :amendment_reaction_enabled,
74
- :amendment_promotion_enabled
75
- amendments_extra_options
92
+ def extra_options_for_type(input_type)
93
+ case input_type
94
+ when :text_area
95
+ { rows: 6 }
76
96
  else
77
97
  {}
78
98
  end
79
99
  end
80
100
 
81
- # Marks :participatory_texts_enabled setting with a CSS class if the
82
- # Proposals component has existing proposals, so it can be identified
83
- # in "decidim/admin/form.js". Also, adds a help_text.
84
- def participatory_texts_extra_options
85
- return {} unless Decidim::Proposals::Proposal.where(component: @component).any?
86
-
87
- {
88
- class: "participatory_texts_disabled",
89
- help_text: help_text_for_component_setting(:participatory_texts_disabled, :global, :proposals)
90
- }
91
- end
92
-
93
- # Marks component_step_settings related to amendments with a CSS class,
94
- # so they can be identified in "decidim/admin/form.js".
95
- def amendments_extra_options
96
- { class: "amendments_step_settings" }
101
+ # Build options for enum attributes
102
+ def build_enum_choices(name, i18n_scope, choices)
103
+ choices.map do |choice|
104
+ [t("#{name}_choices.#{choice}", scope: i18n_scope), choice]
105
+ end
97
106
  end
98
107
  end
99
108
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # This class contains helpers needed to obtain information about
6
+ # image dimensions from the processors defined in the specific image's Uploader class
7
+ module UploaderImageDimensionsHelper
8
+ # Find the dimensions info of a model's image field and get the first value for dimensions ([w, h])
9
+ #
10
+ # model - The model to which the image belongs (An instance of `ActiveRecord`)
11
+ # image_name - The attribute name for the image (either a `symbol` or a `string`)
12
+ #
13
+ # Returns an integer array with [width, height]
14
+ def image_dimensions(model, image_name)
15
+ versions = model.send(image_name).dimensions_info
16
+ [:small, :medium, :default].map { |v| versions.dig(v, :dimensions) }.compact.first
17
+ end
18
+
19
+ # Find the first value for the processed image width
20
+ def image_width(model, image_name)
21
+ image_dimensions(model, image_name)[0]
22
+ end
23
+
24
+ # Find the first value for the processed image height
25
+ def image_height(model, image_name)
26
+ image_dimensions(model, image_name)[1]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ module UserRolesHelper
6
+ def user_role_config
7
+ return @user_role_config if @user_role_config
8
+
9
+ space = current_participatory_space
10
+ @user_role_config = if current_user.admin?
11
+ space.user_role_config_for(current_user, :organization_admin)
12
+ else
13
+ role = space.user_roles.find_by(user: current_user)
14
+ space.user_role_config_for(current_user, role&.role)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # This class is used to generate fake newsletters and data to preview
6
+ # newsletter templates.
7
+ class FakeNewsletter
8
+ def initialize(organization, manifest)
9
+ @organization = organization
10
+ @manifest = manifest
11
+ end
12
+
13
+ def id
14
+ 1
15
+ end
16
+
17
+ def template
18
+ @template ||= Decidim::ContentBlock.new(
19
+ in_preview: true,
20
+ manifest_name: manifest.name,
21
+ scope_name: :newsletter_template,
22
+ settings: manifest.settings.attributes.inject({}) do |acc, (name, attrs)|
23
+ value = if attrs.preview.respond_to?(:call)
24
+ attrs.preview.call
25
+ else
26
+ attrs.preview
27
+ end
28
+
29
+ acc.update(name => value)
30
+ end
31
+ )
32
+ end
33
+
34
+ def subject
35
+ organization.available_locales.inject({}) do |acc, locale|
36
+ acc.update(locale => "Lorem ipsum")
37
+ end
38
+ end
39
+
40
+ def sent_at
41
+ nil
42
+ end
43
+
44
+ private
45
+
46
+ attr_reader :organization, :manifest
47
+ end
48
+ end
49
+ end
@@ -16,15 +16,22 @@ module Decidim
16
16
  return permission_action
17
17
  end
18
18
 
19
- return user_manager_permissions if user_manager?
19
+ if user_manager?
20
+ begin
21
+ allow! if user_manager_permissions.allowed?
22
+ rescue Decidim::PermissionAction::PermissionNotSetError
23
+ nil
24
+ end
25
+ end
20
26
 
21
- allow! if user_can_enter_space_area?
27
+ allow! if user_can_enter_space_area?(require_admin_terms_accepted: true)
22
28
 
23
29
  read_admin_dashboard_action?
24
30
  apply_newsletter_permissions_for_admin!
25
31
 
26
- if user.admin?
32
+ if user.admin? && admin_terms_accepted?
27
33
  allow! if read_admin_log_action?
34
+ allow! if read_metrics_action?
28
35
  allow! if static_page_action?
29
36
  allow! if organization_action?
30
37
  allow! if user_action?
@@ -38,13 +45,13 @@ module Decidim
38
45
  allow! if permission_action.subject == :scope_type
39
46
  allow! if permission_action.subject == :area
40
47
  allow! if permission_action.subject == :area_type
41
- allow! if permission_action.subject == :oauth_application
42
48
  allow! if permission_action.subject == :user_group
43
49
  allow! if permission_action.subject == :officialization
44
50
  allow! if permission_action.subject == :authorization
45
51
  allow! if permission_action.subject == :authorization_workflow
46
52
  allow! if permission_action.subject == :static_page_topic
47
53
  allow! if permission_action.subject == :help_sections
54
+ allow! if permission_action.subject == :share_token
48
55
  end
49
56
 
50
57
  permission_action
@@ -66,6 +73,7 @@ module Decidim
66
73
  end
67
74
 
68
75
  def apply_newsletter_permissions_for_admin!
76
+ return unless admin_terms_accepted?
69
77
  return unless permission_action.subject == :newsletter
70
78
  return allow! if user.admin?
71
79
  return unless space_allows_admin_access?
@@ -89,6 +97,11 @@ module Decidim
89
97
  end
90
98
  end
91
99
 
100
+ def read_metrics_action?
101
+ permission_action.subject == :metrics &&
102
+ permission_action.action == :read
103
+ end
104
+
92
105
  def read_admin_log_action?
93
106
  permission_action.subject == :admin_log &&
94
107
  permission_action.action == :read
@@ -157,15 +170,19 @@ module Decidim
157
170
  @organization ||= context.fetch(:organization, nil) || context.fetch(:current_organization, nil)
158
171
  end
159
172
 
160
- def user_can_enter_space_area?
173
+ def user_can_enter_space_area?(**args)
161
174
  return unless permission_action.action == :enter &&
162
175
  permission_action.subject == :space_area
163
176
 
164
- space_allows_admin_access_to_current_action?
177
+ space_allows_admin_access_to_current_action?(args)
165
178
  end
166
179
 
167
- def space_allows_admin_access_to_current_action?
180
+ def space_allows_admin_access_to_current_action?(require_admin_terms_accepted: false)
168
181
  Decidim.participatory_space_manifests.any? do |manifest|
182
+ if manifest.name != :initiatives && require_admin_terms_accepted
183
+ next unless admin_terms_accepted?
184
+ end
185
+
169
186
  new_permission_action = Decidim::PermissionAction.new(
170
187
  action: permission_action.action,
171
188
  scope: permission_action.scope,
@@ -181,6 +198,12 @@ module Decidim
181
198
  Decidim::Admin::UserManagerPermissions.new(user, permission_action, context).permissions
182
199
  end
183
200
 
201
+ def admin_terms_accepted?
202
+ return unless permission_action.scope == :admin
203
+
204
+ user&.admin_terms_accepted?
205
+ end
206
+
184
207
  def available_authorization_handlers?
185
208
  user.organization.available_authorization_handlers.any?
186
209
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ class DashboardMetricChartsPresenter < Decidim::MetricChartsPresenter
6
+ attribute :summary, Boolean
7
+
8
+ def render_not_highlighted(metrics)
9
+ safe_join(
10
+ metrics.map do |metric|
11
+ render_metrics_data(metric.metric_name, klass: not_highlighted_classes, graph_klass: "small")
12
+ end
13
+ )
14
+ end
15
+
16
+ def highlighted_metrics
17
+ return super unless summary?
18
+
19
+ Decidim.metrics_registry.filtered(
20
+ highlight: true,
21
+ scope: "home"
22
+ ).select do |registry|
23
+ %w(users proposals).include? registry.metric_name
24
+ end
25
+ end
26
+
27
+ def not_highlighted_metrics
28
+ return super unless summary?
29
+
30
+ Decidim.metrics_registry.filtered(
31
+ highlight: false,
32
+ scope: "home"
33
+ ).select do |registry|
34
+ %w(comments meetings accepted_proposals results).include? registry.metric_name
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def highlighted_classes
41
+ return "cell medium-6" if summary?
42
+
43
+ "cell medium-4"
44
+ end
45
+
46
+ def not_highlighted_classes
47
+ return "cell medium-3" if summary?
48
+
49
+ "cell medium-2"
50
+ end
51
+
52
+ def not_highlighted_wrapper_classes
53
+ "grid-x grid-margin-x"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # Counts active users making a distinction between whether they are admins or participants
6
+ class ActiveUsersCounter < Rectify::Query
7
+ # Initializes the class.
8
+ #
9
+ # @param organization [Organization] Current organization
10
+ # @param date [Date] Period time to make users count check
11
+ # @param admin [boolean] Possible values : t for Admin or f for participant
12
+ def initialize(organization:, date:, admin: false)
13
+ @organization = organization
14
+ @date = date
15
+ @admin = admin
16
+ end
17
+
18
+ # Count the user's number who have logged in since given date
19
+ #
20
+ # Returns an ActiveRecord::Relation
21
+ def query
22
+ return Decidim::User.none unless organization && date
23
+
24
+ query = Decidim::User.left_outer_joins(:organization).where(decidim_organizations: { id: organization.id })
25
+ query = query.where("#{Decidim::User.table_name}.current_sign_in_at >= ?", date)
26
+ query = query.where(admin: admin)
27
+ query
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :organization, :date, :admin
33
+ end
34
+ end
35
+ end