deep_unrest 0.1.16 → 0.1.17
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 +4 -4
- data/app/controllers/deep_unrest/application_controller.rb +4 -4
- data/lib/deep_unrest.rb +19 -4
- data/lib/deep_unrest/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbd08967e61dac10c811ea4a4183108ef47a1069
|
4
|
+
data.tar.gz: 22fcd681e5e79ca74723fbd470d767dc9b5d9dd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67dce499be10b554c4530694fb6fbb51c6aa119b58b1d81d5748fa4dd5339273bc63a6ee29b7fcc9ac54595780ef1e53aba00150f83823e07f007b85415c3632
|
7
|
+
data.tar.gz: bc4141b5c7e7d3c58f58562dd227e06b24deb1b63f6613d7ece5a20dab6b6a9047962c33393e0bd591384ecc1bd8da176ffa43bb4277d4ba40a753608fafcbaa
|
@@ -9,6 +9,7 @@ module DeepUnrest
|
|
9
9
|
# rails can't deal with array indices in params (converts them to hashes)
|
10
10
|
# see https://gist.github.com/bloudermilk/2884947
|
11
11
|
def repair_nested_params(obj)
|
12
|
+
return unless obj.respond_to?(:each)
|
12
13
|
obj.each do |key, value|
|
13
14
|
if value.is_a?(ActionController::Parameters) || value.is_a?(Hash)
|
14
15
|
# If any non-integer keys
|
@@ -25,10 +26,9 @@ module DeepUnrest
|
|
25
26
|
def update
|
26
27
|
redirect = allowed_params[:redirect]
|
27
28
|
data = repair_nested_params(allowed_params)[:data]
|
28
|
-
|
29
|
-
|
30
|
-
resp =
|
31
|
-
resp[:redirect] = redirect_replace.call(redirect) if redirect
|
29
|
+
results = DeepUnrest.perform_update(data, current_user)
|
30
|
+
resp = { destroyed: results[:destroyed] }
|
31
|
+
resp[:redirect] = results[:redirect_regex].call(redirect) if redirect
|
32
32
|
render json: resp, status: 200
|
33
33
|
rescue DeepUnrest::Unauthorized => err
|
34
34
|
render json: err.message, status: 403
|
data/lib/deep_unrest.rb
CHANGED
@@ -94,7 +94,7 @@ module DeepUnrest
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def self.temp_id?(str)
|
97
|
-
|
97
|
+
/\[[\w+\-]+\]$/.match(str)
|
98
98
|
end
|
99
99
|
|
100
100
|
def self.plural?(s)
|
@@ -245,6 +245,7 @@ module DeepUnrest
|
|
245
245
|
case action
|
246
246
|
when :destroy
|
247
247
|
cursor[:_destroy] = true
|
248
|
+
scope[:destroyed] = true
|
248
249
|
when :update, :create, :update_all
|
249
250
|
cursor.merge! parse_attributes(type,
|
250
251
|
operation[:action],
|
@@ -461,14 +462,19 @@ module DeepUnrest
|
|
461
462
|
end
|
462
463
|
|
463
464
|
def self.perform_update(params, user)
|
465
|
+
# reject new resources marked for destruction
|
466
|
+
viable_params = params.reject do |param|
|
467
|
+
temp_id?(param[:path]) && param[:destroy]
|
468
|
+
end
|
469
|
+
|
464
470
|
# identify requested scope(s)
|
465
|
-
scopes = collect_all_scopes(
|
471
|
+
scopes = collect_all_scopes(viable_params)
|
466
472
|
|
467
473
|
# authorize user for requested scope(s)
|
468
474
|
DeepUnrest.authorization_strategy.authorize(scopes, user).flatten
|
469
475
|
|
470
476
|
# bulid update arguments
|
471
|
-
mutations = build_mutation_body(
|
477
|
+
mutations = build_mutation_body(viable_params, scopes, user)
|
472
478
|
|
473
479
|
merge_siblings!(mutations)
|
474
480
|
remove_temp_ids!(mutations)
|
@@ -486,7 +492,16 @@ module DeepUnrest
|
|
486
492
|
temp_ids = results.map { |res| res[:temp_ids] }
|
487
493
|
.compact
|
488
494
|
.each_with_object({}) { |item, mem| mem.merge!(item) }
|
489
|
-
|
495
|
+
|
496
|
+
return {
|
497
|
+
redirect_regex: build_redirect_regex(temp_ids),
|
498
|
+
destroyed: scopes.select { |item| item[:destroyed] }
|
499
|
+
.map do |item|
|
500
|
+
{ type: item[:type],
|
501
|
+
id: parse_id(item[:id]),
|
502
|
+
destroyed: true }
|
503
|
+
end
|
504
|
+
}
|
490
505
|
end
|
491
506
|
|
492
507
|
# map errors to their sources
|
data/lib/deep_unrest/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_unrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lynn Hurley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|