rails_admin_draft 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96122c2d58423d2a963678b8fc06a923ff234f9ca7b6b038901acca099c8993e
4
- data.tar.gz: 6a5557f4e8dbb370ed79553fde57e65c1421583c82e9a6ea19ebb45ae6d3b061
3
+ metadata.gz: 50f58bc7bf92dc6416841d6c1f6d45ec06d10c08c8c2c73c6ef44d9a992c0fc0
4
+ data.tar.gz: e9c3a67f666a61995fd37c687b9b2a1b35d0cfde738e905b6f2d5af2e47a19b6
5
5
  SHA512:
6
- metadata.gz: ada57b779764918b92cfc142d926935e6efd74bae1f5987cd4c440d32ae0e89769d82000c401749e5243e5c216e7f031fa996861e7a90f6fff53d3a9d65f229f
7
- data.tar.gz: 5aeb25e7a722359a25133bd8656fd7d0e3104f854c4e4cc159e6918d4af96eedd3fa013eda69e556e0c67c450a5bb0c88a6baee43d84749d162fef772ee2c978
6
+ metadata.gz: d727b538cd1d7c1ee072fd03575215df9c651f9396f31dc5f58af2c2246e55f13ff49f5741f460a37351221351877dc0dfbbc6693def7bde51607b996b50b639
7
+ data.tar.gz: 845c88469340f36465b6b71f91dbd2e5ca1b7afc69edb15e06b0a22e3fd5abd4ca4dfc35edd7f1a324d63c9c1255db67ffd1bae83532a18cc170ce69462f4451
@@ -55,22 +55,27 @@ module DraftConcern
55
55
  return if !self.is_draft?
56
56
  model_to_publish = self
57
57
 
58
- ActiveRecord::Base.transaction do
59
- if self.draft_source_id.present?
60
- model_to_publish = Draft::OverwriteService.new(source: self, destination: self.draft_source).perform
61
- model_to_publish.slug = self.slug # Keep same slug
62
- if Object.const_defined?('DiscardConcern') && self.class.include?('DiscardConcern'.constantize)
63
- self.destroy(true)
64
- else
65
- self.destroy
66
- end
67
- remove_draft_on_unique_text_fields(model_to_publish)
58
+ if self.draft_source_id.present?
59
+ # Save new image if we publish directly the draft
60
+ self.image.store! if self.image.present?
61
+ self.save!
62
+
63
+ model_to_publish = Draft::OverwriteService.new(source: self, destination: self.draft_source).perform
64
+ model_to_publish.slug = self.slug # Keep same slug
65
+
66
+ if Object.const_defined?('DiscardConcern') && self.class.include?('DiscardConcern'.constantize)
67
+ self.image.remove!
68
+ self.destroy(true)
69
+ else
70
+ self.image.remove!
71
+ self.destroy
68
72
  end
69
-
70
- model_to_publish.draft_status = DraftStatus::PUBLISHED
71
- model_to_publish.save!
73
+ remove_draft_on_unique_text_fields(model_to_publish)
72
74
  end
73
75
 
76
+ model_to_publish.draft_status = DraftStatus::PUBLISHED
77
+ model_to_publish.save!
78
+
74
79
  return model_to_publish
75
80
  end
76
81
 
@@ -1,3 +1,5 @@
1
+ require 'fileutils'
2
+
1
3
  module Draft
2
4
  class OverwriteService
3
5
  DRAFT_ASSOCIATIONS = [:draft, :draft_source]
@@ -46,8 +48,26 @@ module Draft
46
48
  return if attributes.blank?
47
49
 
48
50
  attributes.each do |attribute|
49
- @destination.send(attribute).remove! if @destination.send(attribute).present?
51
+ if @destination.send(attribute).present?
52
+ destination_path = File.dirname(File.open(@destination.send(attribute).file.path))
53
+ @destination.send(attribute).remove!
54
+
55
+ end
56
+
50
57
  new_upload = @source.send(attribute).present? ? File.open(@source.send(attribute).file.path) : nil
58
+
59
+ if @source.image.present?
60
+ dir_source = @source.send(attribute).file.path.remove(@source.send(attribute).identifier)
61
+
62
+ Dir[File.join(dir_source, "*#{@source.send(attribute).identifier}")].each do | filename |
63
+ # copy if image destination is present
64
+ FileUtils.mv(filename, destination_path) if destination_path.present?
65
+ end
66
+ end
67
+
68
+ # Delete folder
69
+ FileUtils.remove_dir(dir_source, true) if dir_source.present?
70
+
51
71
  @destination.send("#{attribute}=", new_upload)
52
72
  end
53
73
  end
@@ -1,3 +1,3 @@
1
1
  module RailsAdminDraft
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_draft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grégory Huet
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-02-01 00:00:00.000000000 Z
12
+ date: 2023-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails