decidim-assemblies 0.21.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/decidim/assemblies/assembly.svg +1 -3
  3. data/app/assets/javascripts/decidim/assemblies/orgchart.js.es6 +698 -0
  4. data/app/cells/decidim/assemblies/assembly_m/footer.erb +2 -2
  5. data/app/cells/decidim/assemblies/assembly_m_cell.rb +4 -0
  6. data/app/cells/decidim/assemblies/assembly_member/show.erb +4 -4
  7. data/app/cells/decidim/assemblies/content_blocks/highlighted_assemblies/show.erb +10 -11
  8. data/app/cells/decidim/assemblies/content_blocks/highlighted_assemblies_cell.rb +1 -0
  9. data/app/commands/decidim/assemblies/admin/create_assembly_admin.rb +2 -1
  10. data/app/commands/decidim/assemblies/admin/create_assembly_member.rb +12 -3
  11. data/app/commands/decidim/assemblies/admin/notify_role_assigned_to_assembly.rb +22 -0
  12. data/app/commands/decidim/assemblies/admin/update_assemblies_setting.rb +46 -0
  13. data/app/commands/decidim/assemblies/admin/update_assembly_admin.rb +2 -1
  14. data/app/controllers/decidim/assemblies/admin/assemblies_settings_controller.rb +49 -0
  15. data/app/controllers/decidim/assemblies/assemblies_controller.rb +5 -1
  16. data/app/events/decidim/assemblies/create_assembly_member_event.rb +17 -0
  17. data/app/events/decidim/role_assigned_to_assembly_event.rb +28 -0
  18. data/app/forms/decidim/assemblies/admin/assemblies_setting_form.rb +14 -0
  19. data/app/forms/decidim/assemblies/admin/assembly_form.rb +14 -4
  20. data/app/helpers/decidim/assemblies/assemblies_helper.rb +6 -3
  21. data/app/models/decidim/assemblies_setting.rb +17 -0
  22. data/app/permissions/decidim/assemblies/permissions.rb +30 -1
  23. data/app/presenters/decidim/assemblies/admin_log/assemblies_setting_presenter.rb +27 -0
  24. data/app/presenters/decidim/assemblies/assembly_stats_presenter.rb +1 -1
  25. data/app/queries/decidim/assemblies/parent_assemblies_for_select.rb +20 -1
  26. data/app/views/decidim/assemblies/_filter_by_type.html.erb +11 -9
  27. data/app/views/decidim/assemblies/admin/assemblies/index.html.erb +3 -2
  28. data/app/views/decidim/assemblies/admin/assemblies_settings/_form.html.erb +10 -0
  29. data/app/views/decidim/assemblies/admin/assemblies_settings/edit.html.erb +6 -0
  30. data/app/views/decidim/assemblies/admin/assembly_members/index.html.erb +2 -2
  31. data/app/views/decidim/assemblies/assemblies/_parent_assemblies.html.erb +2 -2
  32. data/app/views/decidim/assemblies/assemblies/_promoted_assembly.html.erb +3 -3
  33. data/app/views/decidim/assemblies/assemblies/index.html.erb +11 -8
  34. data/app/views/decidim/assemblies/assemblies/show.html.erb +9 -8
  35. data/app/views/decidim/assemblies/assembly_members/index.html.erb +1 -1
  36. data/app/views/layouts/decidim/admin/assemblies.html.erb +5 -0
  37. data/config/locales/bg-BG.yml +7 -0
  38. data/config/locales/ca.yml +46 -0
  39. data/config/locales/cs.yml +76 -30
  40. data/config/locales/da-DK.yml +1 -0
  41. data/config/locales/de.yml +69 -0
  42. data/config/locales/el.yml +455 -0
  43. data/config/locales/en.yml +46 -0
  44. data/config/locales/es-MX.yml +46 -0
  45. data/config/locales/es-PY.yml +46 -0
  46. data/config/locales/es.yml +46 -0
  47. data/config/locales/et-EE.yml +1 -0
  48. data/config/locales/fi-plain.yml +46 -0
  49. data/config/locales/fi.yml +47 -1
  50. data/config/locales/fr-CA.yml +456 -0
  51. data/config/locales/fr.yml +67 -0
  52. data/config/locales/ga-IE.yml +1 -0
  53. data/config/locales/hr-HR.yml +1 -0
  54. data/config/locales/hu.yml +35 -2
  55. data/config/locales/it.yml +134 -76
  56. data/config/locales/ja-JP.yml +452 -0
  57. data/config/locales/lt-LT.yml +1 -0
  58. data/config/locales/lv-LV.yml +454 -0
  59. data/config/locales/mt-MT.yml +1 -0
  60. data/config/locales/nl.yml +58 -0
  61. data/config/locales/no.yml +57 -10
  62. data/config/locales/pl.yml +212 -143
  63. data/config/locales/pt-BR.yml +1 -1
  64. data/config/locales/pt.yml +188 -119
  65. data/config/locales/ro-RO.yml +422 -0
  66. data/config/locales/sk-SK.yml +168 -0
  67. data/config/locales/sk.yml +172 -0
  68. data/config/locales/sl.yml +132 -0
  69. data/config/locales/sr-CS.yml +73 -0
  70. data/config/locales/sv.yml +156 -89
  71. data/db/migrate/20200320105906_index_foreign_keys_in_decidim_assemblies.rb +7 -0
  72. data/db/migrate/20200320105907_index_foreign_keys_in_decidim_assembly_user_roles.rb +7 -0
  73. data/db/migrate/20200416132109_remove_legacy_decidim_assembly_type.rb +8 -0
  74. data/db/migrate/20200430202456_create_decidim_assemblies_settings.rb +10 -0
  75. data/db/seeds/city.jpeg +0 -0
  76. data/db/seeds/city2.jpeg +0 -0
  77. data/lib/decidim/assemblies/admin_engine.rb +1 -0
  78. data/lib/decidim/assemblies/participatory_space.rb +6 -1
  79. data/lib/decidim/assemblies/test/factories.rb +5 -0
  80. data/lib/decidim/assemblies/version.rb +1 -1
  81. metadata +38 -8
@@ -2,14 +2,14 @@
2
2
  <div class="card__support">
3
3
  <% if has_assembly_type? %>
4
4
  <div class="card__support__data--left">
5
- <div class="text-uppercase"><%= t("assemblies.show.assembly_type", scope: "decidim") %></div>
5
+ <div><%= t("assemblies.show.assembly_type", scope: "decidim") %></div>
6
6
  <div class="text-ellipsis"><strong><%= assembly_type %></strong></div>
7
7
  </div>
8
8
  <% end %>
9
9
  <%= link_to(
10
10
  t(model.cta_button_text_key, scope: "layouts.decidim.assemblies.assembly"),
11
11
  resource_path,
12
- class: "card__button button button--sc secondary light small"
12
+ class: "card__button button button--sc small"
13
13
  ) %>
14
14
  </div>
15
15
  </div>
@@ -36,6 +36,10 @@ module Decidim
36
36
  [:creation_date, :follow, :children_count]
37
37
  end
38
38
 
39
+ def creation_date_status
40
+ l(model.creation_date, format: :decidim_short) if model.creation_date
41
+ end
42
+
39
43
  def children_count_status
40
44
  content_tag(
41
45
  :strong,
@@ -1,5 +1,5 @@
1
1
  <div class="column">
2
- <article class="card card--member">
2
+ <div class="card card--member">
3
3
  <div class="card__content">
4
4
  <div class="card__header collapse">
5
5
  <div class="author-data author-data--big">
@@ -7,7 +7,7 @@
7
7
  <div class="author author--flex">
8
8
  <% if has_profile? %>
9
9
  <%= link_to profile_url, class: "author__avatar" do %>
10
- <%= image_tag model.avatar_url(:big) %>
10
+ <%= image_tag model.avatar_url(:big), alt: "member-avatar" %>
11
11
  <% end %>
12
12
  <div>
13
13
  <div class="author__name--container">
@@ -24,7 +24,7 @@
24
24
  <% end %>
25
25
  </div>
26
26
  <% else %>
27
- <div class="author__avatar"><%= image_tag asset_path("decidim/default-avatar.svg") %></div>
27
+ <div class="author__avatar"><%= image_tag asset_path("decidim/default-avatar.svg"), alt: "member-avatar" %></div>
28
28
  <div>
29
29
  <div class="author__name--container">
30
30
  <div class="author__name">
@@ -49,5 +49,5 @@
49
49
  <div class="text-small mt-s"><%= personal_information %></div>
50
50
  </div>
51
51
  </div>
52
- </article>
52
+ </div>
53
53
  </div>
@@ -1,4 +1,4 @@
1
- <section class="wrapper-home home-section">
1
+ <section class="wrapper-home home-section" xmlns="http://www.w3.org/1999/xhtml">
2
2
  <div class="row" id="highlighted-assemblies">
3
3
  <h3 class="section-heading"><%= t("active_assemblies", scope: i18n_scope) %></h3>
4
4
  <div class="row collapse">
@@ -6,17 +6,13 @@
6
6
  large-up-4 card-grid">
7
7
  <% highlighted_assemblies.each do |assembly| %>
8
8
  <div class="column">
9
- <article class="card card--assembly card--mini">
10
- <%= link_to decidim_assemblies.assembly_path(assembly), class: "card__link" do %>
11
- <div class="card__image-top"
12
- style="background-image:url(<%= assembly.hero_image.url %>)"></div>
13
- <% end %>
9
+ <%= link_to decidim_assemblies.assembly_path(assembly), class: "card card--assembly card--mini" do %>
10
+ <div aria-hidden="true" class="card__image-top"
11
+ style="background-image:url(<%= assembly.hero_image.url %>)"></div>
14
12
  <div class="card__content">
15
- <%= link_to decidim_assemblies.assembly_path(assembly), class: "card__link" do %>
16
- <h4 class="card__title"><%= translated_attribute assembly.title %></h4>
17
- <% end %>
13
+ <span class="card__title card__link"><%= translated_attribute assembly.title %></span>
18
14
  </div>
19
- </article>
15
+ <% end %>
20
16
  </div>
21
17
  <% end %>
22
18
  </div>
@@ -25,7 +21,10 @@
25
21
  <div class="row" id="see-all-assemblies">
26
22
  <div class="columns small-centered small-12
27
23
  smallmedium-8 medium-6 large-4">
28
- <%= link_to t("see_all_assemblies", scope: i18n_scope), decidim_assemblies.assemblies_path, class: "button expanded hollow button--sc home-section__cta" %>
24
+ <%= link_to t("see_all_assemblies", scope: i18n_scope),
25
+ decidim_assemblies.assemblies_path,
26
+ class: "button expanded hollow button--sc home-section__cta",
27
+ title: t("assemblies_button_title", scope: i18n_scope) %>
29
28
  </div>
30
29
  </div>
31
30
  </section>
@@ -18,6 +18,7 @@ module Decidim
18
18
  @highlighted_assemblies ||= OrganizationPrioritizedAssemblies
19
19
  .new(current_organization, current_user)
20
20
  .query
21
+ .includes([:organization])
21
22
  .limit(max_results)
22
23
  end
23
24
 
@@ -5,7 +5,7 @@ module Decidim
5
5
  module Admin
6
6
  # A command with all the business logic when creating a new participatory
7
7
  # process admin in the system.
8
- class CreateAssemblyAdmin < Rectify::Command
8
+ class CreateAssemblyAdmin < NotifyRoleAssignedToAssembly
9
9
  # Public: Initializes the command.
10
10
  #
11
11
  # form - A form object with the params.
@@ -57,6 +57,7 @@ module Decidim
57
57
  assembly: @assembly
58
58
  )
59
59
  end
60
+ send_notification user
60
61
  end
61
62
 
62
63
  def existing_user
@@ -25,9 +25,8 @@ module Decidim
25
25
  def call
26
26
  return broadcast(:invalid) if form.invalid?
27
27
 
28
- transaction do
29
- create_assembly_member!
30
- end
28
+ create_assembly_member!
29
+ notify_assembly_member_about_new_membership
31
30
 
32
31
  broadcast(:ok)
33
32
  end
@@ -67,6 +66,16 @@ module Decidim
67
66
  log_info
68
67
  )
69
68
  end
69
+
70
+ def notify_assembly_member_about_new_membership
71
+ data = {
72
+ event: "decidim.events.assemblies.create_assembly_member",
73
+ event_class: Decidim::Assemblies::CreateAssemblyMemberEvent,
74
+ resource: assembly,
75
+ followers: [form.user]
76
+ }
77
+ Decidim::EventsManager.publish(data)
78
+ end
70
79
  end
71
80
  end
72
81
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # A command to notify users when a role is assigned for an assembly
7
+ class NotifyRoleAssignedToAssembly < Rectify::Command
8
+ def send_notification(user)
9
+ Decidim::EventsManager.publish(
10
+ event: "decidim.events.assembly.role_assigned",
11
+ event_class: Decidim::RoleAssignedToAssemblyEvent,
12
+ resource: form.current_participatory_space,
13
+ affected_users: [user],
14
+ extra: {
15
+ role: form.role
16
+ }
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # A command with all the business logic when updating assemblies
7
+ # settings in admin area.
8
+ class UpdateAssembliesSetting < Rectify::Command
9
+ # Public: Initializes the command.
10
+ #
11
+ # assemblies_setting - A assemblies_setting object to update.
12
+ # form - A form object with the params.
13
+ def initialize(assemblies_settings, form)
14
+ @assemblies_settings = assemblies_settings
15
+ @form = form
16
+ end
17
+
18
+ # Executes the command. Broadcasts these events:
19
+ #
20
+ # - :ok when everything is valid.
21
+ # - :invalid if the form or assemblies_settings isn't valid and we couldn't proceed.
22
+ #
23
+ # Returns nothing.
24
+ def call
25
+ return broadcast(:invalid) if form.invalid? || assemblies_settings.invalid?
26
+
27
+ update_assemblies_setting!
28
+
29
+ broadcast(:ok)
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :form, :assemblies_settings
35
+
36
+ def update_assemblies_setting!
37
+ Decidim.traceability.update!(
38
+ @assemblies_settings,
39
+ form.current_user,
40
+ enable_organization_chart: form.enable_organization_chart
41
+ )
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -5,7 +5,7 @@ module Decidim
5
5
  module Admin
6
6
  # A command with all the business logic when updated a participatory
7
7
  # process admin in the system.
8
- class UpdateAssemblyAdmin < Rectify::Command
8
+ class UpdateAssemblyAdmin < NotifyRoleAssignedToAssembly
9
9
  # Public: Initializes the command.
10
10
  #
11
11
  # form - A form object with the params.
@@ -45,6 +45,7 @@ module Decidim
45
45
  { role: form.role },
46
46
  log_info
47
47
  )
48
+ send_notification user_role.user
48
49
  end
49
50
  end
50
51
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # Controller used to manage the assemblies settings for the current
7
+ # organization.
8
+ class AssembliesSettingsController < Decidim::Assemblies::Admin::ApplicationController
9
+ layout "decidim/admin/assemblies"
10
+
11
+ # GET /admin/assemblies_settings/edit
12
+ def edit
13
+ enforce_permission_to :edit, :assemblies_setting, assemblies_settings: current_assemblies_settings
14
+ @form = assemblies_settings_form.from_model(current_assemblies_settings)
15
+ end
16
+
17
+ # PUT /admin/assemblies_settings/:id
18
+ def update
19
+ enforce_permission_to :update, :assemblies_setting, assemblies_settings: current_assemblies_settings
20
+
21
+ @form = assemblies_settings_form
22
+ .from_params(params, assemblies_settings: current_assemblies_settings)
23
+
24
+ UpdateAssembliesSetting.call(current_assemblies_settings, @form) do
25
+ on(:ok) do
26
+ flash[:notice] = I18n.t("assemblies_settings.update.success", scope: "decidim.admin")
27
+ redirect_to edit_assemblies_settings_path
28
+ end
29
+
30
+ on(:invalid) do
31
+ flash.now[:alert] = I18n.t("assemblies_settings.update.error", scope: "decidim.admin")
32
+ render :edit
33
+ end
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def current_assemblies_settings
40
+ @current_assemblies_settings ||= Decidim::AssembliesSetting.find_or_create_by!(decidim_organization_id: current_organization.id)
41
+ end
42
+
43
+ def assemblies_settings_form
44
+ form(Decidim::Assemblies::Admin::AssembliesSettingForm)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -8,7 +8,7 @@ module Decidim
8
8
  participatory_space_layout only: :show
9
9
  include FilterResource
10
10
 
11
- helper_method :parent_assemblies, :promoted_assemblies, :stats, :assembly_participatory_processes
11
+ helper_method :parent_assemblies, :promoted_assemblies, :stats, :assembly_participatory_processes, :current_assemblies_settings
12
12
 
13
13
  def index
14
14
  enforce_permission_to :list, :assembly
@@ -87,6 +87,10 @@ module Decidim
87
87
  def assembly_participatory_processes
88
88
  @assembly_participatory_processes ||= @current_participatory_space.linked_participatory_space_resources(:participatory_processes, "included_participatory_processes")
89
89
  end
90
+
91
+ def current_assemblies_settings
92
+ @current_assemblies_settings ||= Decidim::AssembliesSetting.find_or_create_by(decidim_organization_id: current_organization.id)
93
+ end
90
94
  end
91
95
  end
92
96
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ class CreateAssemblyMemberEvent < Decidim::Events::SimpleEvent
6
+ i18n_attributes :resource_name
7
+
8
+ def resource_name
9
+ @resource_name ||= translated_attribute(assembly.title)
10
+ end
11
+
12
+ def assembly
13
+ @assembly ||= resource
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ # frozen-string_literal: true
2
+
3
+ module Decidim
4
+ class RoleAssignedToAssemblyEvent < Decidim::Events::SimpleEvent
5
+ include Decidim::Events::NotificationEvent
6
+ include Decidim::Events::AuthorEvent
7
+
8
+ def notification_title
9
+ I18n.t("notification_title", i18n_options).html_safe
10
+ end
11
+
12
+ def i18n_role
13
+ I18n.t(extra["role"], "decidim.admin.models.assembly_user_role.roles", default: extra["role"])
14
+ end
15
+
16
+ def i18n_options
17
+ {
18
+ resource_path: resource_path,
19
+ resource_title: resource_title,
20
+ resource_url: resource_url,
21
+ scope: event_name,
22
+ participatory_space_title: participatory_space_title,
23
+ participatory_space_url: participatory_space_url,
24
+ role: i18n_role
25
+ }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # A form object used to create assembly setting from the admin dashboard.
7
+ class AssembliesSettingForm < Form
8
+ mimic :assemblies_setting
9
+
10
+ attribute :enable_organization_chart, Boolean
11
+ end
12
+ end
13
+ end
14
+ end
@@ -62,7 +62,10 @@ module Decidim
62
62
  attribute :remove_hero_image
63
63
 
64
64
  validates :area, presence: true, if: proc { |object| object.area_id.present? }
65
- validates :parent, presence: true, if: ->(form) { form.parent_id.present? }
65
+
66
+ validates :parent, presence: true, if: ->(form) { form.parent.present? }
67
+ validate :ensure_parent_cannot_be_child, if: ->(form) { form.parent.present? }
68
+
66
69
  validates :scope, presence: true, if: proc { |object| object.scope_id.present? }
67
70
  validates :slug, presence: true, format: { with: Decidim::Assembly.slug_format }
68
71
 
@@ -79,6 +82,13 @@ module Decidim
79
82
  file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } },
80
83
  file_content_type: { allow: ["image/jpeg", "image/png"] }
81
84
 
85
+ def ensure_parent_cannot_be_child
86
+ return if id.blank?
87
+
88
+ available_assemblies = Decidim::Assemblies::ParentAssembliesForSelect.for(current_organization, Assembly.find(id))
89
+ errors.add(:parent, :invalid) unless available_assemblies.include? parent
90
+ end
91
+
82
92
  def map_model(model)
83
93
  self.scope_id = model.decidim_scope_id
84
94
  end
@@ -93,7 +103,7 @@ module Decidim
93
103
 
94
104
  def assembly_types_for_select
95
105
  @assembly_types_for_select ||= organization_assembly_types
96
- &.map { |type| [translated_attribute(type.title), type.id] }
106
+ &.map { |type| [translated_attribute(type.title), type.id] }
97
107
  end
98
108
 
99
109
  def created_by_for_select
@@ -111,8 +121,8 @@ module Decidim
111
121
 
112
122
  def processes_for_select
113
123
  @processes_for_select ||= organization_participatory_processes
114
- &.map { |pp| [translated_attribute(pp.title), pp.id] }
115
- &.sort_by { |arr| arr[0] }
124
+ &.map { |pp| [translated_attribute(pp.title), pp.id] }
125
+ &.sort_by { |arr| arr[0] }
116
126
  end
117
127
 
118
128
  def assembly_type
@@ -45,9 +45,12 @@ module Decidim
45
45
  html += "<span class='definition-data__title'>#{t("assemblies.show.social_networks", scope: "decidim")}</span>".html_safe
46
46
  Decidim::Assembly::SOCIAL_HANDLERS.each do |handler|
47
47
  handler_name = "#{handler}_handler"
48
- if assembly.send(handler_name).present?
49
- html += link_to handler.capitalize, "https://#{handler}.com/#{assembly.send(handler_name)}", target: "_blank", class: "", title: handler.capitalize, rel: "noopener"
50
- end
48
+ next if assembly.send(handler_name).blank?
49
+
50
+ html += link_to handler.capitalize, "https://#{handler}.com/#{assembly.send(handler_name)}",
51
+ target: "_blank",
52
+ class: "",
53
+ title: t("assemblies.show.social_networks_title", scope: "decidim") << " " << handler.capitalize.to_s, rel: "noopener"
51
54
  end
52
55
  html += "</div>".html_safe
53
56
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # Assemblies setting.
5
+ class AssembliesSetting < ApplicationRecord
6
+ include Decidim::Traceable
7
+ include Decidim::Loggable
8
+
9
+ belongs_to :organization,
10
+ foreign_key: "decidim_organization_id",
11
+ class_name: "Decidim::Organization"
12
+
13
+ def self.log_presenter_class_for(_log)
14
+ Decidim::Assemblies::AdminLog::AssembliesSettingPresenter
15
+ end
16
+ end
17
+ end