decidim-voca 0.0.6 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +161 -161
  3. data/README.md +42 -133
  4. data/Rakefile +46 -39
  5. data/app/cells/decidim/footer_topics/show_overrides.erb +8 -0
  6. data/app/cells/decidim/meetings/dates_and_map/show_overrides.erb +23 -0
  7. data/app/commands/decidim/voca/admin/code_census/save_code_list.rb +34 -0
  8. data/app/commands/decidim/voca/code_census/confirm_code_authorization.rb +16 -0
  9. data/app/commands/decidim/voca/create_editor_file.rb +36 -0
  10. data/app/commands/decidim/voca/rack_attack_configurator.rb +244 -0
  11. data/app/commands/decidim/voca/sync_redis_routing.rb +120 -0
  12. data/app/commands/decidim/voca/user_fields_configurator.rb +40 -0
  13. data/app/controllers/decidim/voca/admin/application_controller.rb +4 -6
  14. data/app/controllers/decidim/voca/admin/code_census/code_lists_controller.rb +40 -0
  15. data/app/controllers/decidim/voca/application_controller.rb +4 -6
  16. data/app/controllers/decidim/voca/code_census/authorizations_controller.rb +53 -0
  17. data/app/controllers/decidim/voca/editor_files_controller.rb +47 -0
  18. data/app/controllers/decidim/voca/geolocation_controller.rb +32 -0
  19. data/app/forms/decidim/voca/admin/code_census/code_list_form.rb +21 -0
  20. data/app/forms/decidim/voca/admin/organization_config_form.rb +24 -0
  21. data/app/forms/decidim/voca/code_census/code_form.rb +41 -0
  22. data/app/forms/decidim/voca/editor_file_form.rb +18 -0
  23. data/app/jobs/decidim/voca/machine_translate_awesome_menu_label_job.rb +63 -0
  24. data/app/jobs/decidim/voca/machine_translate_component_setting_job.rb +58 -0
  25. data/app/jobs/decidim/voca/machine_translate_content_block_setting_job.rb +85 -0
  26. data/app/models/decidim/voca/conversation_uuid.rb +18 -0
  27. data/app/models/decidim/voca/editor_file.rb +18 -0
  28. data/app/models/decidim/voca/validation_code.rb +13 -0
  29. data/app/overrides/admin_add_machine_translation_flag.rb +36 -0
  30. data/app/overrides/insert_assets.rb +26 -0
  31. data/app/overrides/insert_weglot_scripts.rb +36 -0
  32. data/app/overrides/proposal_camera.rb +18 -0
  33. data/app/overrides/show_votes.rb +27 -0
  34. data/app/overrides/voca_footer.rb +52 -0
  35. data/app/packs/entrypoints/admin-decidim-voca.js +2 -0
  36. data/app/packs/entrypoints/admin-decidim-voca.scss +1 -0
  37. data/app/packs/entrypoints/decidim-voca-fixes.scss +1 -0
  38. data/app/packs/entrypoints/decidim-voca.js +1 -0
  39. data/app/packs/entrypoints/decidim-voca.scss +1 -0
  40. data/app/packs/images/voca-logo-primary-x3.png +0 -0
  41. data/app/packs/src/decidim/direct_uploads/upload_field.js +150 -0
  42. data/app/packs/src/decidim/voca/admin/voca.js +16 -0
  43. data/app/packs/src/decidim/voca/proposal_better_ux/use_camera_button.js +39 -0
  44. data/app/packs/src/decidim/voca/proposal_better_ux/utils/get_current_position.js +21 -0
  45. data/app/packs/src/decidim/voca/proposal_better_ux/utils/get_proposal_form.js +13 -0
  46. data/app/packs/src/decidim/voca/proposal_better_ux/utils/loading.js +23 -0
  47. data/app/packs/src/decidim/voca/proposal_better_ux/utils/locate_coordinates.js +23 -0
  48. data/app/packs/src/decidim/voca/proposal_custom_fields/custom_field_renderer_override.js +152 -0
  49. data/app/packs/src/decidim/voca/proposal_custom_fields/editor_budget_field.js +329 -0
  50. data/app/packs/src/decidim/voca/proposal_custom_fields/editor_upload_field.js +85 -0
  51. data/app/packs/src/decidim/voca/proposal_custom_fields/proposal_custom_fields.js +96 -0
  52. data/app/packs/src/decidim/voca/proposal_custom_fields/render_budget_field.js +76 -0
  53. data/app/packs/src/decidim/voca/proposal_fields/render_budget_field.js +76 -0
  54. data/app/packs/src/decidim/voca/questionnaire/scroll_questionnaire_steps_to_top.js +18 -0
  55. data/app/packs/src/decidim/voca/voca.js +4 -0
  56. data/app/packs/src/decidim/voca/weglot/index.js +13 -0
  57. data/app/packs/src/decidim/voca/weglot/start_weglot.js +112 -0
  58. data/app/packs/src/decidim/voca/weglot/switcher.js +92 -0
  59. data/app/packs/src/decidim/voca/weglot/wait_for_weglot.js +10 -0
  60. data/app/packs/stylesheets/decidim/voca/_custom_proposal_fields.scss +111 -0
  61. data/app/packs/stylesheets/decidim/voca/_decidim_voca.scss +5 -0
  62. data/app/packs/stylesheets/decidim/voca/_decidim_voca_fixes.scss +25 -0
  63. data/app/packs/stylesheets/decidim/voca/_primary_footer.scss +77 -0
  64. data/app/packs/stylesheets/decidim/voca/_proposal_camera.scss +14 -0
  65. data/app/packs/stylesheets/decidim/voca/_weglot.scss +61 -0
  66. data/app/packs/stylesheets/decidim/voca/admin/_decidim_voca.scss +5 -0
  67. data/app/packs/stylesheets/decidim/voca/admin/_full_machine_translation.scss +34 -0
  68. data/app/permissions/decidim/voca/admin/permissions.rb +31 -0
  69. data/app/permissions/decidim/voca/permissions.rb +17 -0
  70. data/app/views/decidim/voca/admin/code_census/authorizations/new.html.erb +33 -0
  71. data/app/views/decidim/voca/admin/code_census/code_lists/edit.html.erb +27 -0
  72. data/app/views/decidim/voca/code_census/authorizations/new.html.erb +24 -0
  73. data/app/views/decidim/voca/deepl/overrides/_admin_machine_translation_alert.html.erb +14 -0
  74. data/app/views/decidim/voca/rack_attack/_blocked.html.erb +151 -0
  75. data/app/views/decidim/voca/weglot/_js_configuration.html.erb +14 -0
  76. data/app/views/decidim/voca/weglot/_locale_switcher.html.erb +14 -0
  77. data/app/views/decidim/voca/weglot/_locale_switcher_mobile.erb +14 -0
  78. data/app/views/decidim/voca/weglot/_topbar_locale_switcher.html.erb +14 -0
  79. data/config/assets.rb +12 -0
  80. data/config/i18n-tasks.yml +14 -5
  81. data/config/locales/cs.yml +94 -0
  82. data/config/locales/custom_fields.cs.yml +30 -0
  83. data/config/locales/custom_fields.en.yml +41 -0
  84. data/config/locales/custom_fields.fr.yml +30 -0
  85. data/config/locales/custom_fields.it.yml +30 -0
  86. data/config/locales/en.yml +97 -4
  87. data/config/locales/fr.yml +102 -0
  88. data/config/locales/it.yml +94 -0
  89. data/lib/decidim/voca/awesome_menu_label_machine_translation.rb +73 -0
  90. data/lib/decidim/voca/awesome_menu_labels.rb +28 -0
  91. data/lib/decidim/voca/cache_namespace.rb +21 -0
  92. data/lib/decidim/voca/code_census/admin_engine.rb +22 -0
  93. data/lib/decidim/voca/code_census/engine.rb +29 -0
  94. data/lib/decidim/voca/code_census/workflow.rb +7 -0
  95. data/lib/decidim/voca/code_census.rb +4 -0
  96. data/lib/decidim/voca/component_setting_manifest.rb +27 -0
  97. data/lib/decidim/voca/component_setting_pending_locales.rb +33 -0
  98. data/lib/decidim/voca/component_translated_settings_machine_translation.rb +86 -0
  99. data/lib/decidim/voca/configuration.rb +23 -0
  100. data/lib/decidim/voca/content_block_setting_manifest.rb +67 -0
  101. data/lib/decidim/voca/content_block_translated_settings_machine_translation.rb +100 -0
  102. data/lib/decidim/voca/deepl/deepl_active_job_context.rb +27 -0
  103. data/lib/decidim/voca/deepl/deepl_context.rb +78 -0
  104. data/lib/decidim/voca/deepl/deepl_form_builder_overrides.rb +82 -0
  105. data/lib/decidim/voca/deepl/deepl_machine_translator.rb +61 -0
  106. data/lib/decidim/voca/deepl/deepl_middleware.rb +83 -0
  107. data/lib/decidim/voca/deepl/engine_config.rb +179 -0
  108. data/lib/decidim/voca/deepl/translation_bar_overrides.rb +20 -0
  109. data/lib/decidim/voca/deepl.rb +9 -0
  110. data/lib/decidim/voca/engine.rb +318 -11
  111. data/lib/decidim/voca/export/comment_serializer_localized_csv.rb +34 -0
  112. data/lib/decidim/voca/export/csv_with_locale_transformer.rb +53 -0
  113. data/lib/decidim/voca/export/proposal_serializer_localized_csv.rb +45 -0
  114. data/lib/decidim/voca/export/user_answers_serializer_localized_csv.rb +54 -0
  115. data/lib/decidim/voca/good_job_settings.rb +74 -0
  116. data/lib/decidim/voca/installation.rb +33 -0
  117. data/lib/decidim/voca/machine_translation/translate_string.rb +121 -0
  118. data/lib/decidim/voca/machine_translation_human_source.rb +29 -0
  119. data/lib/decidim/voca/machine_translation_resource_job_voca.rb +65 -0
  120. data/lib/decidim/voca/organization_voca_extensions.rb +31 -0
  121. data/lib/decidim/voca/overrides/csv_export_serializers.rb +51 -0
  122. data/lib/decidim/voca/overrides/meetings/dates_and_map_cell_overrides.rb +20 -0
  123. data/lib/decidim/voca/overrides/menu_breadcrumb_last_activity_cache.rb +31 -0
  124. data/lib/decidim/voca/overrides/mod_secure/conversation_controller_overrides.rb +19 -0
  125. data/lib/decidim/voca/overrides/mod_secure/conversation_sanitize.rb +29 -0
  126. data/lib/decidim/voca/overrides/mod_secure/conversation_uuid.rb +34 -0
  127. data/lib/decidim/voca/overrides/mod_secure/user_conversations_redirect_overrides.rb +53 -0
  128. data/lib/decidim/voca/overrides/mod_secure/user_profile_verification_override.rb +31 -0
  129. data/lib/decidim/voca/overrides/newsletter_helper_overrides.rb +30 -0
  130. data/lib/decidim/voca/overrides/resource_presenter_overrides.rb +30 -0
  131. data/lib/decidim/voca/overrides/sanitize_helper_overrides.rb +39 -0
  132. data/lib/decidim/voca/sync_locales/README.md +13 -0
  133. data/lib/decidim/voca/sync_locales/awesome_menu_label_sync.rb +89 -0
  134. data/lib/decidim/voca/sync_locales/command.rb +54 -0
  135. data/lib/decidim/voca/sync_locales/component_setting_sync.rb +72 -0
  136. data/lib/decidim/voca/sync_locales/content_block_setting_sync.rb +86 -0
  137. data/lib/decidim/voca/sync_locales/field_hash_normalizer.rb +98 -0
  138. data/lib/decidim/voca/sync_locales/locale_context.rb +589 -0
  139. data/lib/decidim/voca/sync_locales/machine_translation_enqueuer.rb +60 -0
  140. data/lib/decidim/voca/sync_locales/relation_lint_runner.rb +55 -0
  141. data/lib/decidim/voca/sync_locales/runner.rb +352 -0
  142. data/lib/decidim/voca/sync_locales.rb +11 -0
  143. data/lib/decidim/voca/update_column_without_callbacks.rb +21 -0
  144. data/lib/decidim/voca/version.rb +13 -3
  145. data/lib/decidim/voca.rb +42 -13
  146. data/lib/decidim-voca.rb +5 -0
  147. data/lib/tasks/decidim/voca/voca_anonymize.rake +41 -0
  148. data/lib/tasks/decidim/voca/voca_clean_machine_translations.rake +22 -0
  149. data/lib/tasks/decidim/voca/voca_enhanced_invalid_record.rake +141 -0
  150. data/lib/tasks/decidim/voca/voca_install_migration.rake +45 -0
  151. data/lib/tasks/decidim/voca/voca_relation_lint.rake +12 -0
  152. data/lib/tasks/decidim/voca/voca_sync_locales.rake +10 -0
  153. data/lib/tasks/decidim/voca/voca_upgrade.rake +13 -0
  154. data/lib/tasks/decidim/voca/voca_webpacker.rake +58 -0
  155. metadata +248 -55
  156. data/app/assets/config/voca_manifest.js +0 -0
  157. data/app/assets/images/decidim/voca/icon.svg +0 -1
  158. data/app/commands/decidim/voca/organization/command.rb +0 -16
  159. data/app/commands/decidim/voca/organization/organization_command.rb +0 -17
  160. data/app/commands/decidim/voca/organization/update_color_command.rb +0 -35
  161. data/app/commands/decidim/voca/organization/update_environment_command.rb +0 -23
  162. data/app/commands/decidim/voca/organization/update_feature_command.rb +0 -32
  163. data/app/commands/decidim/voca/organization/update_file_upload_command.rb +0 -45
  164. data/app/commands/decidim/voca/organization/update_locale_command.rb +0 -53
  165. data/app/commands/decidim/voca/organization/update_naming_command.rb +0 -30
  166. data/app/commands/decidim/voca/organization/update_permission_command.rb +0 -31
  167. data/app/commands/decidim/voca/organization/update_smtp_command.rb +0 -51
  168. data/app/jobs/decidim/voca/command_job.rb +0 -36
  169. data/app/jobs/decidim/voca/webhook_notifier_job.rb +0 -57
  170. data/app/rpc/decidim/voca/decidim_service_controller.rb +0 -68
  171. data/app/rpc/decidim/voca/rpc/enum_casting.rb +0 -58
  172. data/app/rpc/decidim/voca/rpc/get_settings.rb +0 -144
  173. data/app/rpc/decidim/voca/rpc/health.rb +0 -18
  174. data/app/rpc/decidim/voca/rpc/seed_admin.rb +0 -75
  175. data/app/rpc/decidim/voca/rpc/set_settings.rb +0 -56
  176. data/app/rpc/decidim/voca/rpc/setup_db.rb +0 -38
  177. data/config/environments/development.rb +0 -6
  178. data/config/spring.rb +0 -2
  179. data/lib/decidim/voca/admin.rb +0 -10
  180. data/lib/decidim/voca/admin_engine.rb +0 -27
  181. data/lib/decidim/voca/backup/app_backup.rb +0 -169
  182. data/lib/decidim/voca/backup/app_decrypt_backup_file.rb +0 -50
  183. data/lib/decidim/voca/backup/app_encrypt_backup_file.rb +0 -49
  184. data/lib/decidim/voca/backup/app_upload_to_s3.rb +0 -49
  185. data/lib/decidim/voca/middleware/dynamic_config_middleware.rb +0 -42
  186. data/lib/decidim/voca/rpc/decidim_pb.rb +0 -134
  187. data/lib/decidim/voca/rpc/decidim_services_pb.rb +0 -30
  188. data/lib/decidim/voca/test/factories.rb +0 -9
  189. data/lib/decidim/voca/updater.rb +0 -50
  190. data/lib/tasks/voca.rake +0 -88
@@ -1,144 +0,0 @@
1
-
2
-
3
- module Decidim
4
- module Voca
5
- module Rpc
6
- class GetSettings
7
- include ::VocaDecidim
8
- attr_reader :message, :organization
9
- def initialize(message, organization)
10
- @message = message
11
- @organization = organization
12
- end
13
-
14
- # get all the settings linked to the organization.
15
- # @returns GetSettingsResponse
16
- def get_settings
17
- GetSettingsResponse.new(
18
- id: organization.id,
19
- permission_settings: permission_settings,
20
- naming_settings: naming_settings,
21
- locale_settings: locale_settings,
22
- smtp_settings: smtp_settings,
23
- color_settings: color_settings,
24
- file_upload_settings: file_upload_settings,
25
- feature_settings: feature_settings
26
- )
27
- end
28
-
29
- private
30
- def feature_settings
31
- DecidimOrganizationFeatureFlagSettings.new(
32
- available_authorizations: organization.available_authorizations,
33
- badges_enabled: organization.badges_enabled,
34
- user_groups_enabled: organization.user_groups_enabled,
35
- enable_machine_translations: organization.enable_machine_translations,
36
- machine_translation_display_priority: EnumCasting.machine_translation_display_priority.decidim_to_rpc(
37
- organization.machine_translation_display_priority || "original"
38
- )
39
- )
40
- end
41
-
42
- def file_upload_settings
43
- upload_settings = ::Decidim::OrganizationSettings.for(organization).upload
44
- DecidimOrganizationFileUploadSettings.new(
45
- maximum_file_size_avatar: upload_settings.maximum_file_size.avatar,
46
- maximum_file_size_default: upload_settings.maximum_file_size.default,
47
- allowed_content_types_admin: upload_settings.allowed_content_types.admin,
48
- allowed_content_types_default: upload_settings.allowed_content_types.default,
49
- allowed_file_extensions_admin: upload_settings.allowed_file_extensions.admin,
50
- allowed_file_extensions_default: upload_settings.allowed_file_extensions.default
51
- )
52
- end
53
-
54
- def color_settings
55
- default_colors = {
56
- "alert": "#ec5840",
57
- "primary": "#cb3c29",
58
- "success": "#57d685",
59
- "warning": "#ffae00",
60
- "highlight": "#be6400",
61
- "secondary": "#39747f",
62
- "highlight-alternative": "#be6400"
63
- }
64
- settings = default_colors.merge((organization.colors || {}).deep_symbolize_keys) { |_k, o, v| v.presence || o }.delete_if { |_k, v| v.blank? }
65
- DecidimOrganizationColorSettings.new(
66
- alert: settings[:alert],
67
- primary: settings[:primary],
68
- success: settings[:success],
69
- warning: settings[:warning],
70
- highlight: settings[:highlight],
71
- secondary: settings[:secondary],
72
- highlight_alternative: settings["highlight-alternative".to_sym]
73
- )
74
- end
75
-
76
- def smtp_settings
77
- active_mailer_config = Rails.configuration.action_mailer.smtp_settings || {}
78
- tenant_config = organization.smtp_settings || {}
79
- from = tenant_config.fetch("from", active_mailer_config.fetch(:from, ""))
80
-
81
- email = Mail::Address.new(from)
82
- current_settings = active_mailer_config.merge({
83
- password: tenant_config["password"],
84
- user_name: tenant_config["user_name"],
85
- port: tenant_config["port"],
86
- address: tenant_config["address"],
87
- from_label: email.present? ? email.display_name : nil,
88
- from_email: email.present? ? email.address : nil
89
- }) { |_k, o, v| v.presence || o }.delete_if { |_k, v| v.blank? }
90
-
91
- DecidimOrganizationSMTPSettings.new(
92
- from_label: current_settings[:from_label],
93
- from_email: current_settings[:from_email],
94
- address: current_settings[:address],
95
- port: current_settings[:port],
96
- authentication: EnumCasting.smtp_authentication.decidim_to_rpc(
97
- current_settings[:authentication] || "plain"
98
- ),
99
- username: current_settings[:user_name],
100
- password: current_settings[:password],
101
- domain: current_settings[:domain],
102
- enable_starttls_auto: current_settings[:enable_starttls_auto],
103
- openssl_verify_mode: EnumCasting.smtp_openssl_verify_mode.decidim_to_rpc(
104
- current_settings[:openssl_verify_mode] || "peer"
105
- )
106
- )
107
- end
108
-
109
- def permission_settings
110
- DecidimOrganizationPermissionSettings.new(
111
- force_users_to_authenticate_before_access_organization:
112
- organization.force_users_to_authenticate_before_access_organization,
113
- users_registration_mode: EnumCasting.users_registration_mode.decidim_to_rpc(
114
- organization.users_registration_mode || "enabled"
115
- )
116
- )
117
- end
118
-
119
-
120
- def locale_settings
121
- redis_client = Redis.new(
122
- url: ENV.fetch("REDIS_CONFIG_URL", "redis://127.0.0.1:6379/2"),
123
- );
124
- globals_config = redis_client.hgetall("config")
125
- DecidimOrganizationLocaleSettings.new(
126
- default_locale: organization.default_locale,
127
- available_locales: organization.available_locales,
128
- currency_unit: globals_config["currency_unit"],
129
- timezone: globals_config["timezone"]
130
- )
131
- end
132
-
133
- def naming_settings
134
- DecidimOrganizationNamingSettings.new(
135
- host: organization.host,
136
- secondary_hosts: organization.secondary_hosts,
137
- name: organization.name,
138
- reference_prefix: organization.reference_prefix
139
- )
140
- end
141
- end
142
- end
143
- end
144
- end
@@ -1,18 +0,0 @@
1
- require "rake"
2
- module Decidim
3
- module Voca
4
- module Rpc
5
- class Health
6
- include ::VocaDecidim
7
-
8
- ##
9
- # Return just a string without any caculations.
10
- # This is done to test succesfull interaction through RPC
11
- def ping
12
- "pong"
13
- end
14
-
15
- end
16
- end
17
- end
18
- end
@@ -1,75 +0,0 @@
1
- module Decidim
2
- module Voca
3
- module Rpc
4
- class SeedAdmin
5
- include ::VocaDecidim
6
- attr_reader :message, :organization, :password
7
-
8
- def initialize(message)
9
- @message = message
10
- @organization = ::Decidim::Organization.first!
11
- @password = ::Devise.friendly_token.first(23)
12
- end
13
-
14
- # migrate the database and insert default values.
15
- # @returns nil
16
- def seed
17
- seed_system_admin!
18
- seed_admin!
19
- end
20
-
21
- private
22
- def seed_system_admin!
23
- return if ::Decidim::System::Admin.count > 0
24
- ::Decidim::System::Admin.create!(
25
- email: message.system_email,
26
- password: message.system_password,
27
- password_confirmation: message.system_password,
28
- )
29
- end
30
-
31
- def seed_admin!
32
- return update_password! if ::Decidim::User.where(admin: true).count > 0
33
- email = message.admin_email
34
- matches = email[/[^@]+/].split(".").map { |n| n.gsub(/[^[:alnum:]]/, "") }
35
- name = matches.map(&:capitalize).join(" ")
36
- nickname = matches.map(&:downcase).join("_").truncate(19, omission: "")
37
- user = ::Decidim::User.create!(
38
- email: email,
39
- name: name,
40
- nickname: nickname,
41
- password: password,
42
- password_confirmation: password,
43
- organization: organization,
44
- confirmed_at: Time.current,
45
- locale: organization.default_locale,
46
- admin: true,
47
- tos_agreement: true,
48
- personal_url: "",
49
- about: "",
50
- accepted_tos_version: organization.tos_version,
51
- admin_terms_accepted_at: Time.current
52
- )
53
- end
54
-
55
- def update_password!
56
- user = ::Decidim::User.where(admin: true).first!
57
- email = message.admin_email
58
- matches = email[/[^@]+/].split(".").map { |n| n.gsub(/[^[:alnum:]]/, "") }
59
- name = matches.map(&:capitalize).join(" ")
60
- nickname = matches.map(&:downcase).join("_").truncate(19, omission: "")
61
- user.skip_confirmation_notification!
62
- user.skip_confirmation!
63
- user.update(
64
- email: email,
65
- name: name,
66
- nickname: nickname,
67
- password: password,
68
- password_confirmation: password,
69
- )
70
- user.confirm
71
- end
72
- end
73
- end
74
- end
75
- end
@@ -1,56 +0,0 @@
1
-
2
- module Decidim
3
- module Voca
4
- module Rpc
5
- class SetSettings
6
- include ::VocaDecidim
7
- attr_reader :message, :organization
8
- def initialize(message, organization)
9
- @message = message
10
- @organization = organization
11
- end
12
- def set_settings
13
- response = []
14
- response << [
15
- "naming_settings",
16
- ::Decidim::Voca::Organization::UpdateNamingCommand.call(message.naming_settings)
17
- ] unless message.naming_settings.nil?
18
- response << [
19
- "permission_settings",
20
- ::Decidim::Voca::Organization::UpdatePermissionCommand.call(message.permission_settings)
21
- ] unless message.permission_settings.nil?
22
- response << [
23
- "locale_settings",
24
- ::Decidim::Voca::Organization::UpdateLocaleCommand.call(message.locale_settings)
25
- ] unless message.locale_settings.nil?
26
- response << [
27
- "smtp_settings",
28
- ::Decidim::Voca::Organization::UpdateSmtpCommand.call(message.smtp_settings)
29
- ] unless message.smtp_settings.nil?
30
- response << [
31
- "color_settings",
32
- ::Decidim::Voca::Organization::UpdateColorCommand.call(message.color_settings)
33
- ] unless message.color_settings.nil?
34
- response << [
35
- "file_upload_settings",
36
- ::Decidim::Voca::Organization::UpdateFileUploadCommand.call(message.file_upload_settings)
37
- ] unless message.file_upload_settings.nil?
38
- response << [
39
- "feature_settings",
40
- ::Decidim::Voca::Organization::UpdateFeatureCommand.call(message.feature_settings)
41
- ] unless message.feature_settings.nil?
42
- error_string = response.delete_if { |k, v| v.key? :ok }.map(&:first).join(", ")
43
- unless error_string.empty?
44
- raise error_string
45
- end
46
-
47
- if ::Decidim::StaticPage.count < ::Decidim::StaticPage::DEFAULT_PAGES.length
48
- ::Decidim::System::PopulateHelp.new(organization).call
49
- ::Decidim::System::CreateDefaultPages.new(organization).call
50
- end
51
-
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,38 +0,0 @@
1
- module Decidim
2
- module Voca
3
- module Rpc
4
- class SetupDb
5
- include ::VocaDecidim
6
-
7
- # migrate the database and insert default values.
8
- # @returns nil
9
- def seed
10
- # If an organization is already present, should not seed.
11
- return if ::Decidim::Organization.count > 0
12
- seed_organization!
13
- end
14
-
15
- private
16
-
17
- def seed_organization!
18
- organization = ::Decidim::Organization.create!(
19
- host: "localhost",
20
- name: "parked instance",
21
- default_locale: :en,
22
- available_locales: [:en],
23
- reference_prefix: "DOC",
24
- available_authorizations: [],
25
- users_registration_mode: :enabled,
26
- tos_version: Time.current,
27
- badges_enabled: true,
28
- user_groups_enabled: true,
29
- send_welcome_notification: true,
30
- file_upload_settings: ::Decidim::OrganizationSettings.default(:upload)
31
- )
32
-
33
- ::Decidim::System::CreateDefaultContentBlocks.call(organization)
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,6 +0,0 @@
1
- Rails.application.configure do
2
- Rails.logger = Logger.new(STDOUT)
3
- config.logger = ActiveSupport::Logger.new("log/#{Rails.env}.log")
4
- Rails.logger.level = Logger::DEBUG
5
- Rails.logger.datetime_format = "%Y-%m-%d %H:%M:%S"
6
- end
data/config/spring.rb DELETED
@@ -1,2 +0,0 @@
1
-
2
- Spring.application_root = './spec/dummy'
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Voca
5
- # This module contains all the domain logic associated to Decidim's Voca
6
- # component admin panel.
7
- module Admin
8
- end
9
- end
10
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Voca
5
- # This is the engine that runs on the public interface of `Voca`.
6
- class AdminEngine < ::Rails::Engine
7
- isolate_namespace Decidim::Voca::Admin
8
-
9
- paths["db/migrate"] = nil
10
- paths["lib/tasks"] = nil
11
-
12
- routes do
13
- # Add admin engine routes here
14
- # resources :voca do
15
- # collection do
16
- # resources :exports, only: [:create]
17
- # end
18
- # end
19
- # root to: "voca#index"
20
- end
21
-
22
- def load_seed
23
- nil
24
- end
25
- end
26
- end
27
- end
@@ -1,169 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Voca
5
- class AppBackup
6
- def initialize
7
- logger.info "⚙️ starts backup (##{now})"
8
- end
9
-
10
- ##
11
- # Run a backup of :
12
- # public/uploads
13
- # current database
14
- # And store it in a .tar.gz file.
15
- # @return [String] the absolute path of the backuped file
16
- def run!
17
- Dir.mktmpdir do |dir|
18
- logger.debug "Prepare backup in tmp dir '#{dir}'"
19
- dump_database(dir)
20
- compress_source_path(uploads_path, dir)
21
- compress_source_path(logs_path, dir)
22
- generate_metadatas(dir)
23
- with_backup_dir do |backup_dir|
24
- backup_file = "#{backup_dir}/#{now}-backup.tar.gz"
25
- compress_tar!("#{dir}/", backup_file)
26
- backup_file
27
- end
28
- end
29
- end
30
-
31
- private
32
- ##
33
- # Generates a metadata.json file that will be included in the
34
- # given dir. Give information about date, instance identification,
35
- # timezone and decidim version.
36
- # @returns [String] the filename of the generate file
37
- def generate_metadatas(dir)
38
- filename = "#{dir}/metadatas.json"
39
- metadatas = {
40
- date: now,
41
- decidim_version: ENV.fetch("DECIDIM_VERSION", nil),
42
- instance_uuid: ENV.fetch("INSTANCE_UUID", nil),
43
- timezone: ENV.fetch("TZ", nil),
44
- }
45
- File.open(filename, "w") do |f|
46
- f.write(JSON.pretty_generate(metadatas))
47
- end
48
- filename
49
- end
50
-
51
- ##
52
- # Compress a directory in a tar.gz file.
53
- def compress_source_path(source_path, destination_dir)
54
- logger.debug "Running compress_dir for #{source_path}"
55
- source_path_name = File.basename(source_path)
56
- compressed_file = "#{destination_dir}/#{source_path_name}-#{now}.tar.gz"
57
- compress_tar!("#{source_path}/", "#{compressed_file}")
58
- logger.info "⚙️ backup #{source_path_name}: #{compressed_file}"
59
- compressed_file
60
- rescue Exception => e
61
- logger.error e.message
62
- raise e
63
- end
64
-
65
- ##
66
- # Dump the posgres database.
67
- def dump_database(destination_dir)
68
- with_pg_pass do
69
- logger.debug "Running dump_database"
70
- db_host = ENV.fetch("DATABASE_HOST")
71
- db_user = ENV.fetch("DATABASE_USERNAME")
72
- db_pass = ENV.fetch("DATABASE_PASSWORD")
73
- db_name = ENV.fetch("DATABASE_DATABASE")
74
-
75
- dump_file = "#{destination_dir}/#{db_name}-#{now}.dump"
76
- exec_command!("pg_dump -Fc \
77
- -d #{db_name} -h #{db_host} -U #{db_user} -w \
78
- -f #{dump_file}")
79
-
80
- logger.info "⚙️ backup db: #{dump_file}"
81
- dump_file
82
- rescue Exception => e
83
- logger.error e.message
84
- raise e
85
- end
86
- end
87
-
88
- ##
89
- # Create if not exists a .pgpass file.
90
- # Needed to be able to use pg_dump from this image.
91
- def with_pg_pass(&block)
92
- # Check /root/.pgpass exists if not create it
93
- File.open("/root/.pgpass", "w") do |f|
94
- db_host = ENV.fetch("DATABASE_HOST")
95
- db_user = ENV.fetch("DATABASE_USERNAME")
96
- db_pass = ENV.fetch("DATABASE_PASSWORD")
97
- db_name = ENV.fetch("DATABASE_DATABASE")
98
- f.write("#{db_host}:*:#{db_name}:#{db_user}:#{db_pass}")
99
- f.chmod(0600)
100
- end unless File.exists?("/root/.pgpass")
101
- block.call()
102
- end
103
-
104
- ##
105
- # exec a system command.
106
- def exec_command!(command)
107
- logger.debug "exec '#{command}'"
108
- command_output = system(command)
109
- if command_output == true
110
- logger.debug "exec worked: #{command}"
111
- else
112
- raise "exec failed: #{command}"
113
- end
114
- rescue Exception => e
115
- logger.error e.message
116
- raise e
117
- end
118
-
119
- ##
120
- # Ensure backup directory exists and then run the given block with
121
- # backup directory path as argument.
122
- def with_backup_dir(&block)
123
- @backup_dir ||= "#{ENV.fetch('RAILS_ROOT')}/decidim-module-voca/backup_dir"
124
- backup_dir = @backup_dir
125
- Dir.mkdir(backup_dir) unless Dir.exists?(backup_dir)
126
- if Dir.exists?(backup_dir)
127
- block.call(backup_dir)
128
- else
129
- raise "Fails to create #{backup_dir}"
130
- end
131
- end
132
-
133
- ##
134
- # tar a source directory into a destination file.
135
- # the compressed file will have the source directory content only
136
- def compress_tar!(source, destination)
137
- exec_command! "tar -czf #{destination} . -C #{source}"
138
- rescue Exception => e
139
- logger.error "can not tar file."
140
- logger.error e.message
141
- raise e
142
- end
143
-
144
- ##
145
- # Define logger for the class.
146
- def logger
147
- @logger ||= Rails.logger
148
- end
149
-
150
- ##
151
- # Time at the start of the backup task
152
- def now
153
- @now ||= Time.new.strftime("%Y-%m-%d_%H-%M-%S")
154
- end
155
-
156
- ##
157
- # Directory where the user's uploads are.
158
- def uploads_path
159
- @uploads_path ||= "#{ENV.fetch('RAILS_ROOT')}/public/uploads"
160
- end
161
-
162
- ##
163
- # Directory where the app's logs are.
164
- def logs_path
165
- @logs_path ||= "#{ENV.fetch('RAILS_ROOT')}/log"
166
- end
167
- end
168
- end
169
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "openssl"
4
-
5
- module Decidim
6
- module Voca
7
- class AppDecryptBackupFile
8
- attr_accessor :file_path
9
-
10
- def initialize(file_enc)
11
- logger.info "⚙️ starts decrypt file"
12
- raise ArgumentError, "encrypted file cannot be nil" if file_enc.nil?
13
- @file_enc = file_enc
14
- end
15
-
16
- def decrypt!
17
- setup_decipher!
18
- file_name = File.basename(@file_enc, ".enc")
19
- @file_path = File.join(File.dirname(@file_enc), file_name)
20
-
21
- File.open(@file_path, "w:BINARY") do |decrypted_file|
22
- File.open(@file_enc, "r:BINARY") do |encrypted_file|
23
- data = encrypted_file.read
24
- decrypted_data = @decipher.update(data) + @decipher.final
25
- decrypted_file.write(decrypted_data)
26
- end
27
- end
28
- raise Error, "decrypted file not created" unless File.exists?(@file_path)
29
- rescue Exception => e
30
- logger.error e.message
31
- raise e
32
- end
33
-
34
- def setup_decipher!
35
- @decipher ||= OpenSSL::Cipher::AES.new(256, :CBC).decrypt
36
- @decipher.key = Base64.decode64(ENV.fetch("BACKUP_CIPHER_KEY"))
37
- @decipher.iv = Base64.decode64(ENV.fetch("BACKUP_CIPHER_IV"))
38
- rescue Exception => e
39
- logger.error e.message
40
- raise e
41
- end
42
-
43
- ##
44
- # Define logger for the class.
45
- def logger
46
- @logger ||= Rails.logger
47
- end
48
- end
49
- end
50
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "openssl"
4
-
5
- module Decidim
6
- module Voca
7
- class AppEncryptBackupFile
8
- attr_accessor :file_enc, :cipher, :file_path
9
-
10
- def initialize(file_path)
11
- logger.info "⚙️ starts encrypt file"
12
- raise ArgumentError, "file cannot be nil" if file_path.nil?
13
- @file_path = file_path
14
- end
15
-
16
- def encrypt!
17
- setup_cipher!
18
- @file_enc = @file_path + ".enc"
19
- File.open(@file_enc, "w:BINARY") do |encrypted_file|
20
- File.open(@file_path, "r:BINARY") do |file|
21
- data = file.read
22
- encrypted_data = @cipher.update(data) + @cipher.final
23
- encrypted_file.write(encrypted_data)
24
- end
25
- end
26
- raise Error, "encrypted file not created" unless File.exists?(@file_enc)
27
- rescue Exception => e
28
- logger.error e.message
29
- raise e
30
- end
31
-
32
- private
33
- def setup_cipher!
34
- @cipher ||= OpenSSL::Cipher::AES.new(256, :CBC).encrypt
35
- @cipher.key = Base64.decode64(ENV.fetch("BACKUP_CIPHER_KEY"))
36
- @cipher.iv = Base64.decode64(ENV.fetch("BACKUP_CIPHER_IV"))
37
- rescue Exception => e
38
- logger.error e.message
39
- raise e
40
- end
41
-
42
- ##
43
- # Define logger for the class.
44
- def logger
45
- @logger ||= Rails.logger
46
- end
47
- end
48
- end
49
- end