decidim-core 0.29.0.rc2 → 0.29.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58010f8c0acc3bb6a92e20dc385ac989fc98313060d5fbc3ef2c4d484af32720
4
- data.tar.gz: 3be55fbdfae89e11566eb7ff9227133209de3e779fc2062cd6b86c6431436584
3
+ metadata.gz: 2d58ac45e047a62b04a7625b6da1c4ee92c2a62d9bf4e1969cdfb324257e5ef9
4
+ data.tar.gz: 94a06bf8519d6234945a39dc86cc9794149fa3dc09c89273dcd475a64a3ad78b
5
5
  SHA512:
6
- metadata.gz: b57ad83f76d31c5938f46720f2370dbd08b10378f8acb9a302904574ec99b3af904e8cde5057451108a064cba47d26469fa71d39dabcb55c4e02c299751a62e8
7
- data.tar.gz: d44e89eadae907601f933f342d6d6e25e97da2e44e806d5837d057f8c970597a0c69c61302ff9853b7ce43bb08d1ec3ab256620c414f66033a470c14843d02b4
6
+ metadata.gz: 6e90186e86e894822888b13cbaabe6c8c2a752d73a477cb13b39be5fd785d9b92082e5e403de91790f43c19a78f83bb85253e4fa0475f086f64e90258b2593b3
7
+ data.tar.gz: f297c4b6a5fad64c57984fc063778cddda2404f3861e75b8a16c4fff83986caedc44354bba11a58551c5815dae0c9785b5f8d159a9a7e0930d2f080341b69579
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "seven_zip_ruby"
4
- require "zip"
5
- require_relative "zip_stream/writer"
3
+ require "decidim/seven_zip_wrapper"
6
4
 
7
5
  module Decidim
8
6
  # Public: Generates a 7z(seven zip) file with data files ready to be persisted
@@ -10,8 +8,6 @@ module Decidim
10
8
  #
11
9
  # In fact, the 7z file wraps a ZIP file which finally contains the data files.
12
10
  class DownloadYourDataExporter
13
- include ::Decidim::ZipStream::Writer
14
-
15
11
  DEFAULT_EXPORT_FORMAT = "CSV"
16
12
  ZIP_FILE_NAME = "download-your-data.zip"
17
13
 
@@ -29,36 +25,25 @@ module Decidim
29
25
  end
30
26
 
31
27
  def export
32
- dirname = File.dirname(@path)
33
- FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
34
- File.open(@path, "wb") do |file|
35
- SevenZipRuby::Writer.open(file, password: @password) do |szw|
36
- szw.header_encryption = true
37
- szw.add_data(data, ZIP_FILE_NAME)
38
- end
39
- end
28
+ tmpdir = Dir.mktmpdir("temporary-download-your-data-dir")
29
+ user_data, user_attachments = data_and_attachments_for_user
30
+ save_user_data(tmpdir, user_data)
31
+ save_user_attachments(tmpdir, user_attachments)
32
+
33
+ SevenZipWrapper.compress_and_encrypt(filename: @path, password: @password, input_directory: tmpdir)
40
34
  end
41
35
 
42
36
  private
43
37
 
44
- def data
45
- buffer = Zip::OutputStream.write_buffer do |out|
46
- user_data, attachments = data_for(@user, @export_format)
38
+ attr_reader :user, :export_format
47
39
 
48
- add_user_data_to_zip_stream(out, user_data)
49
- add_attachments_to_zip_stream(out, attachments)
50
- end
51
-
52
- buffer.string
53
- end
54
-
55
- def data_for(user, format)
40
+ def data_and_attachments_for_user
56
41
  export_data = []
57
42
  export_attachments = []
58
43
 
59
44
  download_your_data_entities.each do |object|
60
45
  klass = Object.const_get(object)
61
- export_data << [klass.model_name.name.parameterize.pluralize, Exporters.find_exporter(format).new(klass.user_collection(user), klass.export_serializer).export]
46
+ export_data << [klass.model_name.name.parameterize.pluralize, Exporters.find_exporter(export_format).new(klass.user_collection(user), klass.export_serializer).export]
62
47
  attachments = klass.download_your_data_images(user)
63
48
  export_attachments << [klass.model_name.name.parameterize.pluralize, attachments.flatten] unless attachments.nil?
64
49
  end
@@ -69,5 +54,31 @@ module Decidim
69
54
  def download_your_data_entities
70
55
  @download_your_data_entities ||= DownloadYourDataSerializers.data_entities
71
56
  end
57
+
58
+ def save_user_data(tmpdir, user_data)
59
+ user_data.each do |entity, exporter_data|
60
+ next if exporter_data.read == "\n"
61
+
62
+ file_name = File.join(tmpdir, "#{entity}-#{exporter_data.filename}")
63
+ File.write(file_name, exporter_data.read)
64
+ end
65
+ end
66
+
67
+ def save_user_attachments(tmpdir, user_attachments)
68
+ user_attachments.each do |entity, attachment_block|
69
+ attachment_block.each do |attachment|
70
+ next unless attachment.attached?
71
+
72
+ blobs = attachment.is_a?(ActiveStorage::Attached::One) ? [attachment.blob] : attachment.blobs
73
+ blobs.each do |blob|
74
+ Dir.mkdir(File.join(tmpdir, entity.parameterize))
75
+ file_name = File.join(tmpdir, entity.parameterize, blob.filename.to_s)
76
+ blob.open do |blob_file|
77
+ File.write(file_name, blob_file.read.force_encoding("UTF-8"))
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
72
83
  end
73
84
  end
data/decidim-core.gemspec CHANGED
@@ -80,7 +80,6 @@ Gem::Specification.new do |s|
80
80
  s.add_dependency "request_store", "~> 1.5.0"
81
81
  s.add_dependency "rubyXL", "~> 3.4"
82
82
  s.add_dependency "rubyzip", "~> 2.0"
83
- s.add_dependency "seven_zip_ruby", "~> 1.3"
84
83
  s.add_dependency "shakapacker", "~> 7.1.0"
85
84
  s.add_dependency "valid_email2", "~> 4.0"
86
85
  s.add_dependency "web-push", "~> 3.0"
@@ -239,6 +239,14 @@ module Decidim
239
239
  app.config.action_mailer.deliver_later_queue_name = :mailers
240
240
  end
241
241
 
242
+ initializer "decidim_core.signed_global_id", after: "global_id" do |app|
243
+ next if app.config.global_id.fetch(:expires_in, nil).present?
244
+
245
+ config.after_initialize do
246
+ SignedGlobalID.expires_in = nil
247
+ end
248
+ end
249
+
242
250
  initializer "decidim_core.middleware" do |app|
243
251
  if app.config.public_file_server.enabled
244
252
  headers = app.config.public_file_server.headers || {}
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-core version.
5
5
  module Core
6
6
  def self.version
7
- "0.29.0.rc2"
7
+ "0.29.0.rc3"
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "shellwords"
4
+
5
+ module Decidim
6
+ class SevenZipWrapper
7
+ class << self
8
+ def compress_and_encrypt(filename:, password:, input_directory:)
9
+ run("cd #{escape(input_directory)} && 7z a -tzip -p#{escape(password)} -mem=AES256 #{escape(filename)} .")
10
+ end
11
+
12
+ def extract_and_decrypt(filename:, password:, output_directory:)
13
+ run("7z x -tzip #{escape(filename)} -o#{escape(output_directory)} -p#{escape(password)}")
14
+ end
15
+
16
+ private
17
+
18
+ def run(command)
19
+ success = system(command)
20
+
21
+ raise "Command failed: #{command}" unless success
22
+ end
23
+
24
+ def escape(string)
25
+ Shellwords.escape(string)
26
+ end
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.0.rc2
4
+ version: 0.29.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-07-16 00:00:00.000000000 Z
13
+ date: 2024-07-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: active_link_to
@@ -696,20 +696,6 @@ dependencies:
696
696
  - - "~>"
697
697
  - !ruby/object:Gem::Version
698
698
  version: '2.0'
699
- - !ruby/object:Gem::Dependency
700
- name: seven_zip_ruby
701
- requirement: !ruby/object:Gem::Requirement
702
- requirements:
703
- - - "~>"
704
- - !ruby/object:Gem::Version
705
- version: '1.3'
706
- type: :runtime
707
- prerelease: false
708
- version_requirements: !ruby/object:Gem::Requirement
709
- requirements:
710
- - - "~>"
711
- - !ruby/object:Gem::Version
712
- version: '1.3'
713
699
  - !ruby/object:Gem::Dependency
714
700
  name: shakapacker
715
701
  requirement: !ruby/object:Gem::Requirement
@@ -772,28 +758,28 @@ dependencies:
772
758
  requirements:
773
759
  - - '='
774
760
  - !ruby/object:Gem::Version
775
- version: 0.29.0.rc2
761
+ version: 0.29.0.rc3
776
762
  type: :development
777
763
  prerelease: false
778
764
  version_requirements: !ruby/object:Gem::Requirement
779
765
  requirements:
780
766
  - - '='
781
767
  - !ruby/object:Gem::Version
782
- version: 0.29.0.rc2
768
+ version: 0.29.0.rc3
783
769
  - !ruby/object:Gem::Dependency
784
770
  name: decidim-dev
785
771
  requirement: !ruby/object:Gem::Requirement
786
772
  requirements:
787
773
  - - '='
788
774
  - !ruby/object:Gem::Version
789
- version: 0.29.0.rc2
775
+ version: 0.29.0.rc3
790
776
  type: :development
791
777
  prerelease: false
792
778
  version_requirements: !ruby/object:Gem::Requirement
793
779
  requirements:
794
780
  - - '='
795
781
  - !ruby/object:Gem::Version
796
- version: 0.29.0.rc2
782
+ version: 0.29.0.rc3
797
783
  description: Adds core features so other engines can hook into the framework.
798
784
  email:
799
785
  - josepjaume@gmail.com
@@ -1907,7 +1893,6 @@ files:
1907
1893
  - app/services/decidim/static_map_generator.rb
1908
1894
  - app/services/decidim/tokenizer.rb
1909
1895
  - app/services/decidim/traceability.rb
1910
- - app/services/decidim/zip_stream/writer.rb
1911
1896
  - app/uploaders/decidim/application_uploader.rb
1912
1897
  - app/uploaders/decidim/attachment_uploader.rb
1913
1898
  - app/uploaders/decidim/avatar_uploader.rb
@@ -2939,6 +2924,7 @@ files:
2939
2924
  - lib/decidim/searchable.rb
2940
2925
  - lib/decidim/seeds.rb
2941
2926
  - lib/decidim/settings_manifest.rb
2927
+ - lib/decidim/seven_zip_wrapper.rb
2942
2928
  - lib/decidim/shareable_with_token.rb
2943
2929
  - lib/decidim/snippets.rb
2944
2930
  - lib/decidim/social_share_service_manifest.rb
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module ZipStream
5
- module Writer
6
- def add_user_data_to_zip_stream(out, user_data)
7
- user_data.each do |element|
8
- filename_file = element.last.filename(element.first.parameterize)
9
-
10
- out.put_next_entry(filename_file)
11
- if element.last.read.presence
12
- out.write element.last.read
13
- else
14
- out.write "No data"
15
- end
16
- end
17
- end
18
-
19
- def add_attachments_to_zip_stream(out, export_attachments)
20
- export_attachments.each do |attachment_block|
21
- next if attachment_block.last.nil?
22
-
23
- folder_name = attachment_block.first.parameterize
24
- attachment_block.last.each do |attachment|
25
- next unless attachment.attached?
26
-
27
- blobs = attachment.is_a?(ActiveStorage::Attached::One) ? [attachment.blob] : attachment.blobs
28
- blobs.each do |blob|
29
- out.put_next_entry("#{folder_name}/#{blob.filename}")
30
- blob.open do |f|
31
- out << f.read
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end