decidim-core 0.12.2 → 0.13.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/decidim/modules/_order-by.scss +4 -1
  3. data/app/cells/decidim/author/comments.erb +2 -2
  4. data/app/cells/decidim/author/date.erb +1 -1
  5. data/app/cells/decidim/author_cell.rb +22 -38
  6. data/app/cells/decidim/card_m/authors.erb +9 -0
  7. data/app/cells/decidim/card_m/status.erb +1 -1
  8. data/app/cells/decidim/card_m_cell.rb +8 -0
  9. data/app/cells/decidim/collapsible_authors/show.erb +16 -0
  10. data/app/cells/decidim/collapsible_authors_cell.rb +32 -0
  11. data/app/cells/decidim/invitations_toggle/content.erb +1 -0
  12. data/app/cells/decidim/invitations_toggle/label.erb +1 -0
  13. data/app/cells/decidim/invitations_toggle_cell.rb +27 -0
  14. data/app/cells/decidim/toggle/show.erb +8 -0
  15. data/app/cells/decidim/toggle_cell.rb +42 -0
  16. data/app/cells/decidim/tos_page/refuse_btn_modal.erb +25 -14
  17. data/app/commands/decidim/create_omniauth_registration.rb +1 -1
  18. data/app/commands/decidim/create_registration.rb +1 -1
  19. data/app/commands/decidim/create_report.rb +10 -10
  20. data/app/commands/decidim/invite_friends.rb +48 -0
  21. data/app/commands/decidim/invite_user.rb +4 -2
  22. data/app/commands/decidim/unsubscribe_settings.rb +3 -3
  23. data/app/commands/decidim/update_notifications_settings.rb +1 -1
  24. data/app/controllers/concerns/decidim/needs_tos_accepted.rb +6 -1
  25. data/app/controllers/decidim/data_portability_controller.rb +55 -0
  26. data/app/controllers/decidim/devise/invitations_controller.rb +1 -0
  27. data/app/controllers/decidim/invitations_controller.rb +32 -0
  28. data/app/controllers/decidim/newsletters_opt_in_controller.rb +31 -0
  29. data/app/forms/decidim/account_form.rb +1 -1
  30. data/app/forms/decidim/invitations_form.rb +37 -0
  31. data/app/forms/decidim/notifications_settings_form.rb +5 -0
  32. data/app/forms/decidim/omniauth_registration_form.rb +1 -1
  33. data/app/forms/decidim/registration_form.rb +7 -1
  34. data/app/helpers/decidim/cells_helper.rb +44 -0
  35. data/app/jobs/decidim/data_portability_export_job.rb +21 -0
  36. data/app/jobs/decidim/newsletters_opt_in_job.rb +11 -0
  37. data/app/mailers/decidim/export_mailer.rb +13 -0
  38. data/app/mailers/decidim/newsletters_opt_in_mailer.rb +15 -0
  39. data/app/models/decidim/coauthorship.rb +23 -0
  40. data/app/models/decidim/follow.rb +10 -0
  41. data/app/models/decidim/identity.rb +10 -0
  42. data/app/models/decidim/messaging/conversation.rb +10 -0
  43. data/app/models/decidim/notification.rb +10 -0
  44. data/app/models/decidim/participatory_space_private_user.rb +10 -0
  45. data/app/models/decidim/report.rb +10 -0
  46. data/app/models/decidim/user.rb +16 -1
  47. data/app/models/decidim/user_group.rb +9 -0
  48. data/app/services/decidim/action_authorizer.rb +1 -1
  49. data/app/uploaders/decidim/avatar_uploader.rb +6 -2
  50. data/app/uploaders/decidim/data_portability_uploader.rb +19 -0
  51. data/app/views/decidim/data_portability/export.html.erb +1 -0
  52. data/app/views/decidim/data_portability/show.html.erb +5 -0
  53. data/app/views/decidim/devise/invitations/edit.html.erb +1 -1
  54. data/app/views/decidim/devise/shared/_newsletter_modal.html.erb +13 -13
  55. data/app/views/decidim/export_mailer/data_portability_export.html.erb +2 -0
  56. data/app/views/decidim/invitations/index.html.erb +48 -0
  57. data/app/views/decidim/newsletters_opt_in_mailer/notify.html.erb +23 -0
  58. data/app/views/decidim/profiles/_user.html.erb +1 -1
  59. data/app/views/devise/mailer/invite_friend.html.erb +27 -0
  60. data/app/views/devise/mailer/invite_friend.text.erb +19 -0
  61. data/app/views/layouts/decidim/_user_menu.html.erb +1 -0
  62. data/config/locales/ca.yml +68 -2
  63. data/config/locales/en.yml +73 -3
  64. data/config/locales/es-PY.yml +67 -1
  65. data/config/locales/es.yml +67 -1
  66. data/config/locales/eu.yml +68 -2
  67. data/config/locales/fi.yml +69 -3
  68. data/config/locales/fr.yml +136 -70
  69. data/config/locales/gl.yml +69 -3
  70. data/config/locales/it.yml +69 -3
  71. data/config/locales/nl.yml +69 -3
  72. data/config/locales/pl.yml +69 -3
  73. data/config/locales/pt-BR.yml +69 -3
  74. data/config/locales/pt.yml +69 -3
  75. data/config/locales/ru.yml +45 -2
  76. data/config/locales/sv.yml +69 -3
  77. data/config/locales/uk.yml +61 -2
  78. data/config/routes.rb +10 -0
  79. data/db/migrate/20171212103803_create_unique_nicknames.rb +1 -1
  80. data/db/migrate/20180221101934_fix_nickname_index.rb +3 -1
  81. data/db/migrate/20180427141253_create_coauthorships.rb +13 -0
  82. data/db/migrate/20180611121852_change_newsletter_notification_type_value.rb +21 -0
  83. data/lib/decidim/api/authorable_interface.rb +10 -1
  84. data/lib/decidim/authorable.rb +4 -1
  85. data/lib/decidim/coauthorable.rb +69 -0
  86. data/lib/decidim/component_manifest.rb +4 -0
  87. data/lib/decidim/core.rb +10 -0
  88. data/lib/decidim/core/engine.rb +5 -0
  89. data/lib/decidim/core/test.rb +1 -0
  90. data/lib/decidim/core/test/factories.rb +9 -1
  91. data/lib/decidim/core/test/shared_examples/coauthorable.rb +111 -0
  92. data/lib/decidim/core/test/shared_examples/coauthorable_interface_examples.rb +31 -0
  93. data/lib/decidim/core/test/shared_examples/simple_event.rb +7 -1
  94. data/lib/decidim/core/version.rb +1 -1
  95. data/lib/decidim/data_portability.rb +29 -0
  96. data/lib/decidim/data_portability_file_reader.rb +56 -0
  97. data/lib/decidim/data_portability_file_zipper.rb +55 -0
  98. data/lib/decidim/data_portability_serializers.rb +23 -0
  99. data/lib/decidim/data_portability_serializers/data_portability_conversation_serializer.rb +42 -0
  100. data/lib/decidim/data_portability_serializers/data_portability_follow_serializer.rb +23 -0
  101. data/lib/decidim/data_portability_serializers/data_portability_identity_serializer.rb +25 -0
  102. data/lib/decidim/data_portability_serializers/data_portability_notification_serializer.rb +26 -0
  103. data/lib/decidim/data_portability_serializers/data_portability_participatory_space_private_user_serializer.rb +25 -0
  104. data/lib/decidim/data_portability_serializers/data_portability_report_serializer.rb +36 -0
  105. data/lib/decidim/data_portability_serializers/data_portability_user_group_serializer.rb +21 -0
  106. data/lib/decidim/data_portability_serializers/data_portability_user_serializer.rb +55 -0
  107. data/lib/decidim/events.rb +1 -0
  108. data/lib/decidim/events/coauthor_event.rb +42 -0
  109. data/lib/decidim/exporters/csv.rb +0 -1
  110. data/lib/decidim/form_builder.rb +1 -2
  111. data/lib/decidim/nicknamizable.rb +15 -4
  112. data/lib/decidim/participable.rb +7 -0
  113. data/lib/decidim/participatory_space_manifest.rb +4 -0
  114. data/lib/devise/models/decidim_newsletterable.rb +60 -0
  115. data/lib/tasks/decidim_tasks.rake +29 -0
  116. metadata +73 -28
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This class generates the information needed to be read by DataPortability.
5
+ # It creates the file_name, file_path, check that the token is valid and generates the token if no exists. Originally
6
+ # meant for DataPortability functionality and adding user images to this file, but other usage can be found.
7
+ class DataPortabilityFileReader
8
+ # Public: Initialize the reader with a user, and token
9
+ #
10
+ # user - The user of data portability to be zipped.
11
+ # token - The token to be send by email, and return to controller.
12
+ def initialize(user, token = nil)
13
+ @user = user
14
+ @organization = user.organization
15
+ @token = token
16
+ end
17
+
18
+ # Returns a String with the filename of the file to be read or generate.
19
+ def file_name
20
+ name = ""
21
+ name += @user.nickname
22
+ name += "-"
23
+ name += @organization.name.parameterize
24
+ name += "-"
25
+ name += token
26
+ name + ".zip"
27
+ end
28
+
29
+ # Returns a String with the absolute file_path to be read or generate.
30
+ def file_path
31
+ directory_name = Rails.root.join(Decidim::DataPortabilityUploader.new.store_dir)
32
+ Dir.mkdir(directory_name) unless File.exist?(directory_name)
33
+ directory_name + file_name
34
+ end
35
+
36
+ def file_path_reader
37
+ Decidim::DataPortabilityUploader.new.retrieve_from_store!(file_name)
38
+ end
39
+
40
+ # Check if token is present and length equal 10
41
+ def valid_token?
42
+ token.present? && token.length == 10
43
+ end
44
+
45
+ # Returns a the token or generate a new one
46
+ def token
47
+ @token ||= generate_new_token
48
+ end
49
+
50
+ private
51
+
52
+ def generate_new_token
53
+ SecureRandom.base58(10)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "zip"
4
+
5
+ module Decidim
6
+ # This class performs a task: Creating a Zip file of all DataPortability classes. Originally
7
+ # meant for DataPortability functionality and adding user images to this file, but other usage can be found.
8
+ class DataPortabilityFileZipper < Decidim::DataPortabilityFileReader
9
+ # Public: Initializes the zipper with a user, data, and images to
10
+ # be zipped.
11
+ #
12
+ # user - The user of data portability to be zipped.
13
+ # data - An array of all data to be zipped.
14
+ # images - An array of image urls to be inclueded in the zipped file.
15
+ def initialize(user, data, images, token = nil)
16
+ super(user, token)
17
+ @export_data = data
18
+ @export_images = images
19
+ end
20
+
21
+ # Public: Zips the file.
22
+ #
23
+ # Returns a String with the zipped version of the file.
24
+ def make_zip
25
+ Zip::OutputStream.open(file_path) do |zos|
26
+ @export_data.each do |element|
27
+ filename_file = element.last.filename(element.first.parameterize)
28
+
29
+ zos.put_next_entry(filename_file)
30
+ if element.last.read.presence
31
+ zos.write element.last.read
32
+ else
33
+ zos.write "No data"
34
+ end
35
+ end
36
+ end
37
+
38
+ zipfile = Zip::File.open(file_path)
39
+ @export_images.each do |image_block|
40
+ next if image_block.last.nil?
41
+ image_block.last.each do |image|
42
+ next if image.file.nil?
43
+ folder_name = image_block.first.parameterize
44
+ uploader = Decidim::ApplicationUploader.new(image.model, image.mounted_as)
45
+ uploader.cache!(File.open(image.file.file))
46
+ uploader.retrieve_from_store!(image.file.filename)
47
+ my_image_path = File.open(image.file.file)
48
+ next unless File.exist?(my_image_path)
49
+ zipfile.add("#{folder_name}/#{image.file.filename}", my_image_path)
50
+ end
51
+ end
52
+ zipfile.close
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module DataPortabilitySerializers
5
+ autoload :DataPortabilityUserSerializer, "decidim/data_portability_serializers/data_portability_user_serializer"
6
+ autoload :DataPortabilityUserGroupSerializer, "decidim/data_portability_serializers/data_portability_user_group_serializer"
7
+ autoload :DataPortabilityConversationSerializer, "decidim/data_portability_serializers/data_portability_conversation_serializer"
8
+ autoload :DataPortabilityReportSerializer, "decidim/data_portability_serializers/data_portability_report_serializer"
9
+ autoload :DataPortabilityFollowSerializer, "decidim/data_portability_serializers/data_portability_follow_serializer"
10
+ autoload :DataPortabilityNotificationSerializer, "decidim/data_portability_serializers/data_portability_notification_serializer"
11
+ autoload :DataPortabilityIdentitySerializer, "decidim/data_portability_serializers/data_portability_identity_serializer"
12
+ autoload :DataPortabilityParticipatorySpacePrivateUserSerializer, "decidim/data_portability_serializers/data_portability_participatory_space_private_user_serializer"
13
+
14
+ def self.data_entities
15
+ ["Decidim::Follow", "Decidim::Identity",
16
+ "Decidim::Messaging::Conversation", "Decidim::Notification",
17
+ "Decidim::ParticipatorySpacePrivateUser", "Decidim::Report", "Decidim::User", "Decidim::UserGroup"] |
18
+ Decidim.component_manifests.map(&:data_portable_entities).flatten |
19
+ Decidim.participatory_space_manifests.map(&:data_portable_entities).flatten |
20
+ (Decidim::Comments.data_portable_entities.flatten if defined?(Decidim::Comments))
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This class serializes a Message so can be exported to CSV
5
+ module DataPortabilitySerializers
6
+ class DataPortabilityConversationSerializer < Decidim::Exporters::Serializer
7
+ include Decidim::ResourceHelper
8
+
9
+ # Public: Initializes the serializer with a conversation.
10
+ def initialize(conversation)
11
+ @conversation = conversation
12
+ end
13
+
14
+ # Public: Exports a hash with the serialized data for this conversation.
15
+ def serialize
16
+ {
17
+ id: conversation.id,
18
+ messages: messages,
19
+ created_at: conversation.created_at,
20
+ updated_at: conversation.updated_at
21
+ }
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :conversation
27
+
28
+ def messages
29
+ conversation.messages.map do |message|
30
+ {
31
+ message_id: message.id,
32
+ sender_id: message.sender.id,
33
+ sender_name: message.sender.name,
34
+ body: message.body,
35
+ created_at: message.created_at,
36
+ updated_at: message.updated_at
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This class serializes a Follow so can be exported to CSV
5
+ module DataPortabilitySerializers
6
+ class DataPortabilityFollowSerializer < Decidim::Exporters::Serializer
7
+ include Decidim::ResourceHelper
8
+
9
+ # Public: Exports a hash with the serialized data for follow.
10
+ def serialize
11
+ {
12
+ id: resource.id,
13
+ followable: {
14
+ id: resource.decidim_followable_id,
15
+ type: resource.decidim_followable_type
16
+ },
17
+ created_at: resource.created_at,
18
+ updated_at: resource.updated_at
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This class serializes a Identity so can be exported to CSV
5
+ module DataPortabilitySerializers
6
+ class DataPortabilityIdentitySerializer < Decidim::Exporters::Serializer
7
+ include Decidim::ResourceHelper
8
+
9
+ # Public: Exports a hash with the serialized data for this identities.
10
+ def serialize
11
+ {
12
+ id: resource.id,
13
+ provider: resource.provider,
14
+ uid: resource.uid,
15
+ user: {
16
+ id: resource.user.id,
17
+ name: resource.user.name
18
+ },
19
+ created_at: resource.created_at,
20
+ updated_at: resource.updated_at
21
+ }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This class serializes a Follow so can be exported to CSV
5
+ module DataPortabilitySerializers
6
+ class DataPortabilityNotificationSerializer < Decidim::Exporters::Serializer
7
+ include Decidim::ResourceHelper
8
+
9
+ # Public: Exports a hash with the serialized data for follow.
10
+ def serialize
11
+ {
12
+ id: resource.id,
13
+ resource_type: {
14
+ id: resource.decidim_resource_id,
15
+ type: resource.decidim_resource_type
16
+ },
17
+ event_name: resource.event_name,
18
+ event_class: resource.event_class,
19
+ created_at: resource.created_at,
20
+ updated_at: resource.updated_at,
21
+ extra: resource.extra
22
+ }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This class serializes a User so can be exported to CSV
5
+ module DataPortabilitySerializers
6
+ class DataPortabilityParticipatorySpacePrivateUserSerializer < Decidim::Exporters::Serializer
7
+ include Decidim::ResourceHelper
8
+
9
+ # Public: Exports a hash with the serialized data for this user.
10
+ def serialize
11
+ {
12
+ id: resource.id,
13
+ privatable_to: {
14
+ id: resource.privatable_to_id,
15
+ type: resource.privatable_to_type,
16
+ title: resource.privatable_to.title,
17
+ slug: resource.privatable_to.slug
18
+ },
19
+ created_at: resource.created_at,
20
+ updated_at: resource.updated_at
21
+ }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This class serializes a Report so can be exported to CSV
5
+ module DataPortabilitySerializers
6
+ class DataPortabilityReportSerializer < Decidim::Exporters::Serializer
7
+ include Decidim::ResourceHelper
8
+
9
+ # Public: Exports a hash with the serialized data for this conversation.
10
+ def serialize
11
+ {
12
+ id: resource.id,
13
+ moderation: {
14
+ id: resource.moderation.id,
15
+ participatory_space: {
16
+ id: resource.moderation.decidim_participatory_space_id,
17
+ type: resource.moderation.decidim_participatory_space_type,
18
+ title: resource.moderation.participatory_space.title
19
+ },
20
+ reportable_element: {
21
+ id: resource.moderation.decidim_reportable_id,
22
+ type: resource.moderation.decidim_reportable_type
23
+ },
24
+ hidden_at: resource.moderation.hidden_at,
25
+ created_at: resource.moderation.created_at,
26
+ updated_at: resource.moderation.updated_at
27
+ },
28
+ reason: resource.reason,
29
+ details: resource.details,
30
+ created_at: resource.created_at,
31
+ updated_at: resource.updated_at
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This class serializes a User so can be exported to CSV
5
+ module DataPortabilitySerializers
6
+ class DataPortabilityUserGroupSerializer < Decidim::Exporters::Serializer
7
+ include Decidim::ResourceHelper
8
+
9
+ # Public: Exports a hash with the serialized data for this user.
10
+ def serialize
11
+ {
12
+ id: resource.id,
13
+ name: resource.name,
14
+ document_number: resource.document_number,
15
+ phone: resource.phone,
16
+ verified_at: resource.verified_at
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This class serializes a User so can be exported to CSV
5
+ module DataPortabilitySerializers
6
+ class DataPortabilityUserSerializer < Decidim::Exporters::Serializer
7
+ include Decidim::ResourceHelper
8
+
9
+ # Public: Exports a hash with the serialized data for this user.
10
+ def serialize
11
+ {
12
+ id: resource.id,
13
+ email: resource.email,
14
+ name: resource.name,
15
+ nickname: resource.nickname,
16
+ locale: resource.locale,
17
+ organization: {
18
+ id: resource.organization.try(:id),
19
+ name: resource.organization.try(:name)
20
+ },
21
+ newsletter_notifications_at: resource.newsletter_notifications_at,
22
+ email_on_notification: resource.email_on_notification,
23
+ admin: resource.admin,
24
+ personal_url: resource.personal_url,
25
+ about: resource.about,
26
+ invitation_created_at: resource.invitation_created_at,
27
+ invitation_sent_at: resource.invitation_sent_at,
28
+ invitation_accepted_at: resource.invitation_accepted_at,
29
+ invited_by: {
30
+ id: resource.invited_by_id,
31
+ type: resource.invited_by_type
32
+ },
33
+ invitations_count: resource.invitations_count,
34
+ reset_password_sent_at: resource.reset_password_sent_at,
35
+ remember_created_at: resource.remember_created_at,
36
+ sign_in_count: resource.sign_in_count,
37
+ current_sign_in_at: resource.current_sign_in_at,
38
+ last_sign_in_at: resource.last_sign_in_at,
39
+ current_sign_in_ip: resource.current_sign_in_ip,
40
+ last_sign_in_ip: resource.last_sign_in_ip,
41
+ created_at: resource.created_at,
42
+ updated_at: resource.updated_at,
43
+ confirmed_at: resource.confirmed_at,
44
+ confirmation_sent_at: resource.confirmation_sent_at,
45
+ unconfirmed_email: resource.unconfirmed_email,
46
+ delete_reason: resource.delete_reason,
47
+ deleted_at: resource.deleted_at,
48
+ managed: resource.managed,
49
+ officialized_at: resource.officialized_at,
50
+ officialized_as: resource.officialized_as
51
+ }
52
+ end
53
+ end
54
+ end
55
+ end
@@ -7,5 +7,6 @@ module Decidim
7
7
  autoload :NotificationEvent, "decidim/events/notification_event"
8
8
  autoload :SimpleEvent, "decidim/events/simple_event"
9
9
  autoload :AuthorEvent, "decidim/events/author_event"
10
+ autoload :CoauthorEvent, "decidim/events/coauthor_event"
10
11
  end
11
12
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Events
5
+ # This module is used to be included in event classes inheriting from SimpleEvent
6
+ # whose resource is coauthorable.
7
+ #
8
+ # It adds the following methods related with the creator author: author_name, author_nickname, author_path and author_url to the i18n interpolations.
9
+ module CoauthorEvent
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ i18n_attributes :author_name, :author_nickname, :author_path, :author_url
14
+
15
+ def author_nickname
16
+ author_presenter&.nickname.to_s
17
+ end
18
+
19
+ def author_name
20
+ author_presenter&.name.to_s
21
+ end
22
+
23
+ def author_path
24
+ author_presenter&.profile_path.to_s
25
+ end
26
+
27
+ def author_url
28
+ author_presenter&.profile_url.to_s
29
+ end
30
+
31
+ def author_presenter
32
+ return unless author
33
+ @author_presenter ||= Decidim::UserPresenter.new(author)
34
+ end
35
+
36
+ def author
37
+ resource.creator_author if resource.respond_to?(:creator_author)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end