effective_mergery 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/app/assets/config/effective_mergery_manifest.js +2 -0
- data/app/controllers/admin/merge_controller.rb +8 -9
- data/app/models/effective/merge.rb +14 -25
- data/config/effective_mergery.rb +3 -27
- data/lib/effective_mergery/engine.rb +0 -2
- data/lib/effective_mergery/version.rb +1 -1
- data/lib/effective_mergery.rb +5 -31
- metadata +5 -5
- data/app/models/effective/access_denied.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09d729cc7ba2f40740a83f58b09c7244d2f82f323b7b50fd9ac32f43cbd0b009'
|
4
|
+
data.tar.gz: ee2e412bf88531636840f41817c5b366516f6fa7c1d7abbeca9ef2eb20145bdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7ae5bfc66839df22f1b87fbf6533ae3e8c69aaa1895222c1ee6547222a108c37409c95508e488942470ec3e9f9c3ebb3b972469b4ae31dad749f29bba5e929f
|
7
|
+
data.tar.gz: 1cbe65cefab6cdb88dd5565a38c5eda4cdd6b9d0ee1221721b3d9a6291a292dec45948a43d72ff6badf5c6536b10208840975fab33c811bab7199a421620fcbe
|
data/MIT-LICENSE
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
module Admin
|
2
2
|
class MergeController < ApplicationController
|
3
|
-
before_action
|
3
|
+
before_action(:authenticate_user!) if defined?(Devise)
|
4
|
+
before_action { EffectiveResources.authorize!(self, :admin, :effective_mergery) }
|
4
5
|
|
5
|
-
|
6
|
+
include Effective::CrudController
|
7
|
+
|
8
|
+
if (config = EffectiveMergery.layout)
|
9
|
+
layout(config.kind_of?(Hash) ? config[:admin] : config)
|
10
|
+
end
|
6
11
|
|
7
12
|
def index
|
8
13
|
@page_title = 'Merges'
|
9
|
-
EffectiveMergery.authorized?(self, :admin, :effective_mergery)
|
10
14
|
end
|
11
15
|
|
12
16
|
def new
|
13
17
|
@page_title = 'New Merge'
|
14
|
-
EffectiveMergery.authorized?(self, :admin, :effective_mergery)
|
15
18
|
|
16
19
|
begin
|
17
20
|
@merge = Effective::Merge.new(type: params[:type])
|
@@ -23,8 +26,6 @@ module Admin
|
|
23
26
|
end
|
24
27
|
|
25
28
|
def create
|
26
|
-
EffectiveMergery.authorized?(self, :admin, :effective_mergery)
|
27
|
-
|
28
29
|
@merge = Effective::Merge.new(merge_params)
|
29
30
|
|
30
31
|
if @merge.save
|
@@ -55,8 +56,6 @@ module Admin
|
|
55
56
|
|
56
57
|
# This is the AJAX request for the object's attributes
|
57
58
|
def attributes
|
58
|
-
EffectiveMergery.authorized?(self, :admin, :effective_mergery)
|
59
|
-
|
60
59
|
object = Effective::Merge.new(type: params[:type]).collection.find(params[:id])
|
61
60
|
|
62
61
|
if object.present?
|
@@ -69,7 +68,7 @@ module Admin
|
|
69
68
|
private
|
70
69
|
|
71
70
|
def merge_params
|
72
|
-
params.require(:effective_merge).permit
|
71
|
+
params.require(:effective_merge).permit!
|
73
72
|
end
|
74
73
|
|
75
74
|
end
|
@@ -7,7 +7,7 @@ module Effective
|
|
7
7
|
validate(if: -> { source_id.present? }) { @source ||= collection.find_by_id(source_id) }
|
8
8
|
validate(if: -> { target_id.present? }) { @target ||= collection.find_by_id(target_id) }
|
9
9
|
|
10
|
-
validates :type, presence: true
|
10
|
+
validates :type, presence: true
|
11
11
|
validates :source_id, presence: true, unless: -> { source.present? }
|
12
12
|
validates :target_id, presence: true, unless: -> { target.present? }
|
13
13
|
|
@@ -48,7 +48,7 @@ module Effective
|
|
48
48
|
# This is called on Admin::Merges#new
|
49
49
|
def validate_klass!
|
50
50
|
raise "type can't be blank" unless type.present?
|
51
|
-
raise 'type must be a mergable type' unless EffectiveMergery.mergables.include?(type)
|
51
|
+
raise 'type must be a mergable type' unless EffectiveMergery.mergables.map(&:name).include?(type)
|
52
52
|
raise "invalid ActiveRecord klass" unless klass
|
53
53
|
raise "invalid ActiveRecord collection" unless collection.kind_of?(ActiveRecord::Relation)
|
54
54
|
true
|
@@ -58,37 +58,26 @@ module Effective
|
|
58
58
|
|
59
59
|
def merge!(validate: true)
|
60
60
|
resource = Effective::Resource.new(source)
|
61
|
+
success = false
|
61
62
|
|
62
63
|
klass.transaction do
|
63
|
-
|
64
|
+
# Merge associations
|
65
|
+
(resource.has_ones + resource.has_manys + resource.nested_resources).compact.each do |association|
|
66
|
+
next if association.options[:through].present?
|
64
67
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
Array(source.send(association.name)).each do |obj|
|
70
|
-
obj.assign_attributes(association.foreign_key => target.id)
|
71
|
-
|
72
|
-
unless obj.save(validate: validate)
|
73
|
-
raise "associated #{obj.class.name}<#{obj.to_param}> is invalid: #{obj.errors.full_messages.to_sentence}"
|
74
|
-
end
|
75
|
-
end
|
68
|
+
Array(source.send(association.name)).each do |obj|
|
69
|
+
obj.assign_attributes(association.foreign_key => target.id)
|
70
|
+
obj.save!(validate: validate)
|
76
71
|
end
|
72
|
+
end
|
77
73
|
|
78
|
-
|
79
|
-
|
80
|
-
unless target.save(validate: validate)
|
81
|
-
raise "merged #{target.class.name} is invalid: #{target.errors.full_messages.to_sentence}"
|
82
|
-
end
|
74
|
+
source.destroy!
|
83
75
|
|
84
|
-
|
85
|
-
|
86
|
-
self.errors.add(:base, e.message)
|
87
|
-
raise ActiveRecord::Rollback
|
88
|
-
end
|
76
|
+
target.save!(validate: validate)
|
77
|
+
success = true
|
89
78
|
end
|
90
79
|
|
91
|
-
|
80
|
+
success
|
92
81
|
end
|
93
82
|
|
94
83
|
end
|
data/config/effective_mergery.rb
CHANGED
@@ -1,26 +1,6 @@
|
|
1
1
|
EffectiveMergery.setup do |config|
|
2
|
-
# Authorization Method
|
3
|
-
#
|
4
|
-
# This method is called by all controller actions with the appropriate action and resource
|
5
|
-
# If the method returns false, an Effective::AccessDenied Error will be raised (see README.md for complete info)
|
6
|
-
#
|
7
|
-
# Use via Proc (and with CanCan):
|
8
|
-
# config.authorization_method = Proc.new { |controller, action, resource| can?(action, resource) }
|
9
|
-
#
|
10
|
-
# Use via custom method:
|
11
|
-
# config.authorization_method = :my_authorization_method
|
12
|
-
#
|
13
|
-
# And then in your application_controller.rb:
|
14
|
-
#
|
15
|
-
# def my_authorization_method(action, resource)
|
16
|
-
# current_user.is?(:admin)
|
17
|
-
# end
|
18
|
-
#
|
19
|
-
# Or disable the check completely:
|
20
|
-
# config.authorization_method = false
|
21
|
-
config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) } # CanCanCan
|
22
2
|
|
23
|
-
|
3
|
+
# Admin Screens Layout Settings
|
24
4
|
config.layout = 'application' # All EffectiveMergery controllers will use this layout
|
25
5
|
|
26
6
|
# config.layout = {
|
@@ -39,10 +19,6 @@ EffectiveMergery.setup do |config|
|
|
39
19
|
# }
|
40
20
|
# }
|
41
21
|
|
42
|
-
#
|
43
|
-
# config.
|
44
|
-
|
45
|
-
# Allow merges on all ActiveRecord classes, except the following:
|
46
|
-
# config.except = []
|
47
|
-
|
22
|
+
# The class names that can be merged
|
23
|
+
# config.class_names = ['User']
|
48
24
|
end
|
@@ -2,8 +2,6 @@ module EffectiveMergery
|
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
engine_name 'effective_mergery'
|
4
4
|
|
5
|
-
config.autoload_paths += Dir["#{config.root}/lib/"]
|
6
|
-
|
7
5
|
# Set up our default configuration options.
|
8
6
|
initializer "effective_mergery.defaults", before: :load_config_initializers do |app|
|
9
7
|
eval File.read("#{config.root}/config/effective_mergery.rb")
|
data/lib/effective_mergery.rb
CHANGED
@@ -4,41 +4,15 @@ require 'effective_mergery/version'
|
|
4
4
|
|
5
5
|
module EffectiveMergery
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
mattr_accessor :layout
|
10
|
-
mattr_accessor :admin_simple_form_options
|
11
|
-
|
12
|
-
mattr_accessor :only
|
13
|
-
mattr_accessor :except
|
14
|
-
|
15
|
-
def self.setup
|
16
|
-
yield self
|
7
|
+
def self.config_keys
|
8
|
+
[:layout, :admin_simple_form_options, :class_names]
|
17
9
|
end
|
18
10
|
|
19
|
-
|
20
|
-
if authorization_method.respond_to?(:call) || authorization_method.kind_of?(Symbol)
|
21
|
-
raise Effective::AccessDenied.new() unless (controller || self).instance_exec(controller, action, resource, &authorization_method)
|
22
|
-
end
|
23
|
-
true
|
24
|
-
end
|
11
|
+
include EffectiveGem
|
25
12
|
|
13
|
+
# Just consider the onlies right now. sorry future matt.
|
26
14
|
def self.mergables
|
27
|
-
|
28
|
-
Rails.application.eager_load! unless Rails.configuration.cache_classes
|
29
|
-
|
30
|
-
blacklist = ['Delayed::', 'Effective::', 'ActiveRecord::', 'ApplicationRecord']
|
31
|
-
|
32
|
-
ActiveRecord::Base.descendants.map { |obj| obj.name }.tap do |names|
|
33
|
-
names.reject! { |name| blacklist.any? { |b| name.start_with?(b) } }
|
34
|
-
|
35
|
-
if (onlies = Array(only)).present?
|
36
|
-
names.select! { |name| onlies.include?(name) }
|
37
|
-
elsif (excepts = Array(except)).present?
|
38
|
-
names.reject! { |name| excepts.include?(name) }
|
39
|
-
end
|
40
|
-
end.sort
|
41
|
-
)
|
15
|
+
Array(class_names).map { |name| name.constantize }
|
42
16
|
end
|
43
17
|
|
44
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_mergery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: sassc
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -89,12 +89,12 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- MIT-LICENSE
|
91
91
|
- README.md
|
92
|
+
- app/assets/config/effective_mergery_manifest.js
|
92
93
|
- app/assets/javascripts/effective_mergery.js
|
93
94
|
- app/assets/javascripts/effective_mergery/merge.js.coffee
|
94
95
|
- app/assets/stylesheets/effective_mergery.scss
|
95
96
|
- app/assets/stylesheets/effective_mergery/_merge.scss
|
96
97
|
- app/controllers/admin/merge_controller.rb
|
97
|
-
- app/models/effective/access_denied.rb
|
98
98
|
- app/models/effective/merge.rb
|
99
99
|
- app/views/admin/merge/_attributes.html.haml
|
100
100
|
- app/views/admin/merge/create.html.haml
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
|
-
rubygems_version: 3.
|
128
|
+
rubygems_version: 3.3.7
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: Deep merge any two Active Record objects.
|
@@ -1,17 +0,0 @@
|
|
1
|
-
unless defined?(Effective::AccessDenied)
|
2
|
-
module Effective
|
3
|
-
class AccessDenied < StandardError
|
4
|
-
attr_reader :action, :subject
|
5
|
-
|
6
|
-
def initialize(message = nil, action = nil, subject = nil)
|
7
|
-
@message = message
|
8
|
-
@action = action
|
9
|
-
@subject = subject
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_s
|
13
|
-
@message || I18n.t(:'unauthorized.default', :default => 'Access Denied')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|