decidim-voca 0.0.6

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 (47) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +661 -0
  3. data/README.md +153 -0
  4. data/Rakefile +86 -0
  5. data/app/assets/config/voca_manifest.js +0 -0
  6. data/app/assets/images/decidim/voca/icon.svg +1 -0
  7. data/app/commands/decidim/voca/organization/command.rb +16 -0
  8. data/app/commands/decidim/voca/organization/organization_command.rb +17 -0
  9. data/app/commands/decidim/voca/organization/update_color_command.rb +35 -0
  10. data/app/commands/decidim/voca/organization/update_environment_command.rb +23 -0
  11. data/app/commands/decidim/voca/organization/update_feature_command.rb +32 -0
  12. data/app/commands/decidim/voca/organization/update_file_upload_command.rb +45 -0
  13. data/app/commands/decidim/voca/organization/update_locale_command.rb +53 -0
  14. data/app/commands/decidim/voca/organization/update_naming_command.rb +30 -0
  15. data/app/commands/decidim/voca/organization/update_permission_command.rb +31 -0
  16. data/app/commands/decidim/voca/organization/update_smtp_command.rb +51 -0
  17. data/app/controllers/decidim/voca/admin/application_controller.rb +15 -0
  18. data/app/controllers/decidim/voca/application_controller.rb +13 -0
  19. data/app/jobs/decidim/voca/command_job.rb +36 -0
  20. data/app/jobs/decidim/voca/webhook_notifier_job.rb +57 -0
  21. data/app/rpc/decidim/voca/decidim_service_controller.rb +68 -0
  22. data/app/rpc/decidim/voca/rpc/enum_casting.rb +58 -0
  23. data/app/rpc/decidim/voca/rpc/get_settings.rb +144 -0
  24. data/app/rpc/decidim/voca/rpc/health.rb +18 -0
  25. data/app/rpc/decidim/voca/rpc/seed_admin.rb +75 -0
  26. data/app/rpc/decidim/voca/rpc/set_settings.rb +56 -0
  27. data/app/rpc/decidim/voca/rpc/setup_db.rb +38 -0
  28. data/config/environments/development.rb +6 -0
  29. data/config/i18n-tasks.yml +9 -0
  30. data/config/locales/en.yml +6 -0
  31. data/config/spring.rb +2 -0
  32. data/lib/decidim/voca/admin.rb +10 -0
  33. data/lib/decidim/voca/admin_engine.rb +27 -0
  34. data/lib/decidim/voca/backup/app_backup.rb +169 -0
  35. data/lib/decidim/voca/backup/app_decrypt_backup_file.rb +50 -0
  36. data/lib/decidim/voca/backup/app_encrypt_backup_file.rb +49 -0
  37. data/lib/decidim/voca/backup/app_upload_to_s3.rb +49 -0
  38. data/lib/decidim/voca/engine.rb +31 -0
  39. data/lib/decidim/voca/middleware/dynamic_config_middleware.rb +42 -0
  40. data/lib/decidim/voca/rpc/decidim_pb.rb +134 -0
  41. data/lib/decidim/voca/rpc/decidim_services_pb.rb +30 -0
  42. data/lib/decidim/voca/test/factories.rb +9 -0
  43. data/lib/decidim/voca/updater.rb +50 -0
  44. data/lib/decidim/voca/version.rb +13 -0
  45. data/lib/decidim/voca.rb +22 -0
  46. data/lib/tasks/voca.rake +88 -0
  47. metadata +124 -0
@@ -0,0 +1,169 @@
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
@@ -0,0 +1,50 @@
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
@@ -0,0 +1,49 @@
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
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "aws-sdk-s3"
4
+
5
+ module Decidim
6
+ module Voca
7
+ class Uploader
8
+ attr_accessor :filename, :folder
9
+
10
+ def initialize(filename, folder)
11
+ logger.info "⚙️ starts upload file to S3"
12
+ raise ArgumentError, "filename cannot be nil" if filename.nil?
13
+ @filename = filename
14
+ raise ArgumentError, "folder cannot be nil" if folder.nil?
15
+ @folder = folder
16
+ end
17
+
18
+ def upload!
19
+ instance_uuid = ENV.fetch("INSTANCE_UUID")
20
+ destination = File.join(
21
+ "#{instance_uuid}/",
22
+ "#{@folder}/",
23
+ File.basename(filename)
24
+ )
25
+ logger.info "Uploading file: #{@filename} for client: #{instance_uuid}"
26
+ bucket.object(destination).upload_file(filename)
27
+ logger.info "Backup file: #{@filename} upload success"
28
+ rescue Exception => e
29
+ logger.error e.message
30
+ raise e
31
+ end
32
+
33
+ private
34
+ def bucket
35
+ s3_endpoint ||= ENV.fetch("ENDPOINT") unless nil
36
+ s3 ||= Aws::S3::Resource.new(endpoint: "#{s3_endpoint}")
37
+ s3_bucket = s3.bucket("vocacity")
38
+ raise Error if s3_bucket.name.nil?
39
+ s3_bucket
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
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+ require "decidim/core"
5
+ module Decidim
6
+ module Voca
7
+ # This is the engine that runs on the public interface of voca.
8
+ class Engine < ::Rails::Engine
9
+ isolate_namespace Decidim::Voca
10
+
11
+ routes do
12
+ # Add engine routes here
13
+ # resources :voca
14
+ # root to: "voca#index"
15
+ end
16
+
17
+ initializer "decidim_voca.middleware" do |app|
18
+ app.config.middleware.insert_after(Warden::Manager, Decidim::Voca::DynamicConfigMiddleware, Redis.new(
19
+ url: ENV.fetch("REDIS_CONFIG_URL", "redis://127.0.0.1:6379/2"),
20
+ ), "config")
21
+ end
22
+
23
+ initializer "decidim_voca.gruf" do |app|
24
+ ::Gruf.configure do |c|
25
+ c.server_binding_url = ENV.fetch("GRPC_HOST", "0.0.0.0") + ":" + ENV.fetch("GRPC_PORT", "4445")
26
+ c.rpc_server_options = c.rpc_server_options.merge(pool_size: [ENV.fetch("RAILS_MAX_THREADS", 5).to_i - 1, 1].max)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,42 @@
1
+ module Decidim
2
+ module Voca
3
+ class DynamicConfigMiddleware
4
+ # Initializes the middleware with a Redis client and a Redis key name
5
+ #
6
+ # @param app [Object] Rack application to call
7
+ # @param redis_client [Redis] Redis client instance
8
+ # @param redis_key [String] Redis key name to retrieve configuration data from
9
+ def initialize(app, redis_client, redis_key)
10
+ @app = app
11
+ @redis_client = redis_client
12
+ @redis_key = redis_key
13
+ end
14
+
15
+ # Calls the Rack application and sets configuration data from Redis key
16
+ #
17
+ # @param env [Hash] Rack environment variables
18
+ # @return [Array] Rack response array
19
+ def call(env)
20
+ configure_decidim_with_redis_data
21
+ # Call Rack application
22
+ @app.call(env)
23
+ end
24
+
25
+ private
26
+
27
+ def configure_decidim_with_redis_data
28
+ config_data = @redis_client.hgetall(@redis_key)
29
+ return unless config_data.present?
30
+
31
+ # Set configuration attributes using config_data
32
+ if config_data["currency_unit"].present?
33
+ Decidim.currency_unit = config_data["currency_unit"]
34
+ end
35
+ if config_data["timezone"].present?
36
+ ENV["TZ"] = config_data["timezone"] || ENV.fetch("TZ", "UTC")
37
+ Rails.application.config.time_zone = ActiveSupport::TimeZone[ENV["TZ"]]
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,134 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: decidim.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'google/protobuf/timestamp_pb'
7
+ require 'google/protobuf/empty_pb'
8
+
9
+ Google::Protobuf::DescriptorPool.generated_pool.build do
10
+ add_file("decidim.proto", :syntax => :proto3) do
11
+ add_message "voca_decidim.GetSettingsResponse" do
12
+ optional :id, :uint64, 1
13
+ proto3_optional :permission_settings, :message, 2, "voca_decidim.DecidimOrganizationPermissionSettings"
14
+ proto3_optional :naming_settings, :message, 3, "voca_decidim.DecidimOrganizationNamingSettings"
15
+ proto3_optional :locale_settings, :message, 4, "voca_decidim.DecidimOrganizationLocaleSettings"
16
+ proto3_optional :smtp_settings, :message, 5, "voca_decidim.DecidimOrganizationSMTPSettings"
17
+ proto3_optional :color_settings, :message, 6, "voca_decidim.DecidimOrganizationColorSettings"
18
+ proto3_optional :file_upload_settings, :message, 7, "voca_decidim.DecidimOrganizationFileUploadSettings"
19
+ proto3_optional :feature_settings, :message, 8, "voca_decidim.DecidimOrganizationFeatureFlagSettings"
20
+ optional :created_at, :message, 9, "google.protobuf.Timestamp"
21
+ end
22
+ add_message "voca_decidim.SetSettingsRequest" do
23
+ proto3_optional :permission_settings, :message, 1, "voca_decidim.DecidimOrganizationPermissionSettings"
24
+ proto3_optional :naming_settings, :message, 2, "voca_decidim.DecidimOrganizationNamingSettings"
25
+ proto3_optional :locale_settings, :message, 3, "voca_decidim.DecidimOrganizationLocaleSettings"
26
+ proto3_optional :smtp_settings, :message, 4, "voca_decidim.DecidimOrganizationSMTPSettings"
27
+ proto3_optional :color_settings, :message, 5, "voca_decidim.DecidimOrganizationColorSettings"
28
+ proto3_optional :file_upload_settings, :message, 6, "voca_decidim.DecidimOrganizationFileUploadSettings"
29
+ proto3_optional :feature_settings, :message, 7, "voca_decidim.DecidimOrganizationFeatureFlagSettings"
30
+ end
31
+ add_message "voca_decidim.DecidimOrganizationPermissionSettings" do
32
+ proto3_optional :force_users_to_authenticate_before_access_organization, :bool, 1
33
+ optional :users_registration_mode, :enum, 2, "voca_decidim.SETTINGS_REGISTER_MODE_OPTION"
34
+ end
35
+ add_message "voca_decidim.DecidimOrganizationNamingSettings" do
36
+ optional :host, :string, 1
37
+ repeated :secondary_hosts, :string, 2
38
+ optional :name, :string, 3
39
+ optional :reference_prefix, :string, 4
40
+ end
41
+ add_message "voca_decidim.DecidimOrganizationLocaleSettings" do
42
+ optional :default_locale, :string, 1
43
+ repeated :available_locales, :string, 2
44
+ optional :currency_unit, :string, 3
45
+ optional :timezone, :string, 4
46
+ end
47
+ add_message "voca_decidim.DecidimOrganizationSMTPSettings" do
48
+ optional :from_label, :string, 1
49
+ optional :from_email, :string, 2
50
+ optional :address, :string, 3
51
+ optional :port, :string, 4
52
+ optional :authentication, :enum, 5, "voca_decidim.SETTINGS_SMTP_AUTHENTICATION_OPTION"
53
+ optional :username, :string, 6
54
+ optional :password, :string, 7
55
+ optional :domain, :string, 8
56
+ optional :enable_starttls_auto, :bool, 9
57
+ optional :openssl_verify_mode, :enum, 10, "voca_decidim.SETTINGS_SMTP_OPENSSL_OPTION"
58
+ end
59
+ add_message "voca_decidim.DecidimOrganizationColorSettings" do
60
+ optional :alert, :string, 1
61
+ optional :primary, :string, 2
62
+ optional :success, :string, 3
63
+ optional :warning, :string, 4
64
+ optional :highlight, :string, 5
65
+ optional :secondary, :string, 6
66
+ optional :highlight_alternative, :string, 7
67
+ end
68
+ add_message "voca_decidim.DecidimOrganizationFileUploadSettings" do
69
+ optional :maximum_file_size_avatar, :float, 1
70
+ optional :maximum_file_size_default, :float, 2
71
+ repeated :allowed_content_types_admin, :string, 3
72
+ repeated :allowed_content_types_default, :string, 4
73
+ repeated :allowed_file_extensions_admin, :string, 5
74
+ repeated :allowed_file_extensions_default, :string, 6
75
+ end
76
+ add_message "voca_decidim.DecidimOrganizationFeatureFlagSettings" do
77
+ repeated :available_authorizations, :string, 1
78
+ optional :badges_enabled, :bool, 2
79
+ optional :user_groups_enabled, :bool, 3
80
+ optional :enable_machine_translations, :bool, 4
81
+ optional :machine_translation_display_priority, :enum, 5, "voca_decidim.SETTINGS_MACHINE_TRANSLATION_PRIORITY_OPTION"
82
+ end
83
+ add_message "voca_decidim.SeedAdminRequest" do
84
+ optional :admin_email, :string, 1
85
+ optional :system_email, :string, 2
86
+ optional :system_password, :string, 3
87
+ end
88
+ add_message "voca_decidim.SeedAdminResponse" do
89
+ optional :admin_email, :string, 1
90
+ optional :admin_password, :string, 2
91
+ end
92
+ add_message "voca_decidim.PingResponse" do
93
+ optional :message, :string, 1
94
+ end
95
+ add_enum "voca_decidim.SETTINGS_REGISTER_MODE_OPTION" do
96
+ value :SETTINGS_REGISTER_MODE_REGISTER_AND_LOGIN, 0
97
+ value :SETTINGS_REGISTER_MODE_LOGIN, 1
98
+ value :SETTINGS_REGISTER_MODE_EXTERNAL, 2
99
+ end
100
+ add_enum "voca_decidim.SETTINGS_SMTP_AUTHENTICATION_OPTION" do
101
+ value :SETTINGS_SMTP_AUTHENTICATION_PLAIN, 0
102
+ value :SETTINGS_SMTP_AUTHENTICATION_LOGIN, 1
103
+ value :SETTINGS_SMTP_AUTHENTICATION_CRAM_MD5, 2
104
+ value :SETTINGS_SMTP_AUTHENTICATION_NONE, 3
105
+ end
106
+ add_enum "voca_decidim.SETTINGS_SMTP_OPENSSL_OPTION" do
107
+ value :SETTINGS_SMTP_OPENSSL_NONE, 0
108
+ value :SETTINGS_SMTP_OPENSSL_PEER, 1
109
+ end
110
+ add_enum "voca_decidim.SETTINGS_MACHINE_TRANSLATION_PRIORITY_OPTION" do
111
+ value :SETTINGS_MACHINE_TRANSLATION_PRIORITY_ORIGINAL, 0
112
+ value :SETTINGS_MACHINE_TRANSLATION_PRIORITY_TRANSLATED, 1
113
+ end
114
+ end
115
+ end
116
+
117
+ module VocaDecidim
118
+ GetSettingsResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.GetSettingsResponse").msgclass
119
+ SetSettingsRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.SetSettingsRequest").msgclass
120
+ DecidimOrganizationPermissionSettings = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.DecidimOrganizationPermissionSettings").msgclass
121
+ DecidimOrganizationNamingSettings = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.DecidimOrganizationNamingSettings").msgclass
122
+ DecidimOrganizationLocaleSettings = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.DecidimOrganizationLocaleSettings").msgclass
123
+ DecidimOrganizationSMTPSettings = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.DecidimOrganizationSMTPSettings").msgclass
124
+ DecidimOrganizationColorSettings = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.DecidimOrganizationColorSettings").msgclass
125
+ DecidimOrganizationFileUploadSettings = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.DecidimOrganizationFileUploadSettings").msgclass
126
+ DecidimOrganizationFeatureFlagSettings = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.DecidimOrganizationFeatureFlagSettings").msgclass
127
+ SeedAdminRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.SeedAdminRequest").msgclass
128
+ SeedAdminResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.SeedAdminResponse").msgclass
129
+ PingResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.PingResponse").msgclass
130
+ SETTINGS_REGISTER_MODE_OPTION = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.SETTINGS_REGISTER_MODE_OPTION").enummodule
131
+ SETTINGS_SMTP_AUTHENTICATION_OPTION = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.SETTINGS_SMTP_AUTHENTICATION_OPTION").enummodule
132
+ SETTINGS_SMTP_OPENSSL_OPTION = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.SETTINGS_SMTP_OPENSSL_OPTION").enummodule
133
+ SETTINGS_MACHINE_TRANSLATION_PRIORITY_OPTION = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("voca_decidim.SETTINGS_MACHINE_TRANSLATION_PRIORITY_OPTION").enummodule
134
+ end
@@ -0,0 +1,30 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: decidim.proto for package 'voca_decidim'
3
+
4
+ require 'grpc'
5
+ require_relative './decidim_pb'
6
+
7
+ module VocaDecidim
8
+ module Decidim
9
+ class Service
10
+
11
+ include ::GRPC::GenericService
12
+
13
+ self.marshal_class_method = :encode
14
+ self.unmarshal_class_method = :decode
15
+ self.service_name = 'voca_decidim.Decidim'
16
+
17
+ # region/Health
18
+ rpc :Ping, ::Google::Protobuf::Empty, ::VocaDecidim::PingResponse
19
+ # region/Settings
20
+ rpc :GetSettings, ::Google::Protobuf::Empty, ::VocaDecidim::GetSettingsResponse
21
+ rpc :SetSettings, ::VocaDecidim::SetSettingsRequest, ::Google::Protobuf::Empty
22
+ # region/Seed
23
+ rpc :CompileAssets, ::Google::Protobuf::Empty, ::Google::Protobuf::Empty
24
+ rpc :SetupDb, ::Google::Protobuf::Empty, ::Google::Protobuf::Empty
25
+ rpc :SeedAdmin, ::VocaDecidim::SeedAdminRequest, ::VocaDecidim::SeedAdminResponse
26
+ end
27
+
28
+ Stub = Service.rpc_stub_class
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/core/test/factories"
4
+
5
+ FactoryBot.define do
6
+
7
+
8
+ # Add engine factories here
9
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Voca
5
+ class Updater
6
+ class << self
7
+ def update!(options)
8
+ ActiveSupport::Deprecation.warn('deprecated.')
9
+
10
+ updater = self.new(options.deep_symbolize_keys)
11
+ end
12
+ end
13
+
14
+ attr_reader :options
15
+ def initialize(options)
16
+ @options = options
17
+ validate_options!
18
+ update!
19
+ end
20
+
21
+ private
22
+ def validate_options!
23
+ allowed_attributes = [
24
+ :org_name,
25
+ :org_prefix,
26
+ :host,
27
+ :default_locale,
28
+ :available_locales
29
+ ]
30
+ options.each do |k, v|
31
+ raise Decidim::Voca::Error.new("invalid option #{k}") unless allowed_attributes.include?(k)
32
+ end
33
+ end
34
+
35
+ def update!
36
+ Decidim::Organization.first!.update!(transformed_options)
37
+ end
38
+
39
+ def transformed_options
40
+ transform = {}
41
+ transform[:host] = options[:host] if options[:host].present?
42
+ transform[:name] = options[:org_name] if options[:org_name].present?
43
+ transform[:default_locale] = options[:default_locale] if options[:default_locale].present?
44
+ transform[:available_locales] = options[:available_locales].split(",").map(&:strip).map(&:to_sym) if options[:available_locales].present?
45
+ transform[:reference_prefix] = options[:org_prefix] if options[:org_prefix].present?
46
+ transform
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This holds the decidim-meetings version.
4
+ module Decidim
5
+ module Voca
6
+ def self.version
7
+ "0.0.6"
8
+ end
9
+ def self.decidim_version
10
+ ">= 0.26"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "gruf"
4
+ require_relative "voca/admin"
5
+ require_relative "voca/engine"
6
+ require_relative "voca/admin_engine"
7
+ require_relative "voca/version"
8
+
9
+ require_relative "voca/backup/app_backup"
10
+ require_relative "voca/backup/app_upload_to_s3"
11
+ require_relative "voca/backup/app_encrypt_backup_file"
12
+ require_relative "voca/backup/app_decrypt_backup_file"
13
+ require_relative "voca/updater"
14
+ require_relative "voca/rpc/decidim_services_pb"
15
+ require_relative "voca/middleware/dynamic_config_middleware"
16
+
17
+ require "active_support/core_ext"
18
+ module Decidim
19
+ module Voca
20
+ class Error < StandardError; end
21
+ end
22
+ end