openstax_api 5.2.2 → 5.3.0
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/lib/openstax/api/roar.rb +16 -36
- data/lib/openstax/api/version.rb +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +1665 -0
- 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: ab8a6785ca018f79bbd476d360b2a52956a6b56a
|
4
|
+
data.tar.gz: 4d77c522856c7f424a86e9c8e06646e2292af525
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27abc5a1882d7fa01c531d32d5e4e82192469d156ea843d3d6185df40e55474751834ef5a3135e2f51cdbf491275254b24ea025f7c59dd341b92279c629d4f5e
|
7
|
+
data.tar.gz: 460eb820b127aa0805dfb0c636ac810ca6bbc2533855c901e7330a147b66781aca5cfbc22b1b9abe44b2a0ea55d09c99abf5d3b5ee50fc7f61d000a29cbbfb82
|
data/lib/openstax/api/roar.rb
CHANGED
@@ -25,9 +25,7 @@ module OpenStax
|
|
25
25
|
model.class.transaction do
|
26
26
|
consume!(model, represent_with: represent_with)
|
27
27
|
yield model if block_given?
|
28
|
-
OSU::AccessPolicy.require_action_allowed!(:create,
|
29
|
-
current_api_user,
|
30
|
-
model)
|
28
|
+
OSU::AccessPolicy.require_action_allowed!(:create, current_api_user, model)
|
31
29
|
|
32
30
|
if model.save
|
33
31
|
respond_with model, represent_with: represent_with,
|
@@ -38,30 +36,24 @@ module OpenStax
|
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
41
|
-
def standard_read(model, represent_with=nil)
|
42
|
-
OSU::AccessPolicy.require_action_allowed!(:read,
|
43
|
-
|
44
|
-
|
45
|
-
respond_with model, represent_with: represent_with
|
39
|
+
def standard_read(model, represent_with=nil, use_timestamp_for_cache=false)
|
40
|
+
OSU::AccessPolicy.require_action_allowed!(:read, current_api_user, model)
|
41
|
+
respond_with model, represent_with: represent_with \
|
42
|
+
if !use_timestamp_for_cache || stale?(model)
|
46
43
|
end
|
47
44
|
|
48
45
|
def standard_update(model, represent_with=nil)
|
49
46
|
# Must be able to update the record before and after the update itself
|
50
|
-
OSU::AccessPolicy.require_action_allowed!(:update,
|
51
|
-
current_api_user,
|
52
|
-
model)
|
47
|
+
OSU::AccessPolicy.require_action_allowed!(:update, current_api_user, model)
|
53
48
|
|
54
49
|
model.class.transaction do
|
55
50
|
consume!(model, represent_with: represent_with)
|
56
51
|
yield model if block_given?
|
57
|
-
OSU::AccessPolicy.require_action_allowed!(:update,
|
58
|
-
current_api_user,
|
59
|
-
model)
|
52
|
+
OSU::AccessPolicy.require_action_allowed!(:update, current_api_user, model)
|
60
53
|
|
61
54
|
if model.save
|
62
55
|
# http://stackoverflow.com/a/27413178
|
63
|
-
respond_with model, represent_with: represent_with,
|
64
|
-
responder: ResponderWithPutContent
|
56
|
+
respond_with model, represent_with: represent_with, responder: ResponderWithPutContent
|
65
57
|
else
|
66
58
|
render_api_errors(model.errors)
|
67
59
|
end
|
@@ -69,9 +61,7 @@ module OpenStax
|
|
69
61
|
end
|
70
62
|
|
71
63
|
def standard_destroy(model)
|
72
|
-
OSU::AccessPolicy.require_action_allowed!(:destroy,
|
73
|
-
current_api_user,
|
74
|
-
model)
|
64
|
+
OSU::AccessPolicy.require_action_allowed!(:destroy, current_api_user, model)
|
75
65
|
|
76
66
|
if model.destroy
|
77
67
|
head :no_content
|
@@ -82,44 +72,34 @@ module OpenStax
|
|
82
72
|
|
83
73
|
def standard_index(relation, represent_with)
|
84
74
|
model_klass = relation.base_class
|
85
|
-
OSU::AccessPolicy.require_action_allowed!(:index,
|
86
|
-
current_api_user,
|
87
|
-
model_klass)
|
75
|
+
OSU::AccessPolicy.require_action_allowed!(:index, current_api_user, model_klass)
|
88
76
|
relation.each do |item|
|
89
77
|
# Must be able to read each record
|
90
|
-
OSU::AccessPolicy.require_action_allowed!(:read,
|
91
|
-
current_api_user,
|
92
|
-
item)
|
78
|
+
OSU::AccessPolicy.require_action_allowed!(:read, current_api_user, item)
|
93
79
|
end
|
94
|
-
respond_with(Lev::Outputs.new(items: relation),
|
95
|
-
represent_with: represent_with)
|
80
|
+
respond_with(Lev::Outputs.new(items: relation), represent_with: represent_with)
|
96
81
|
end
|
97
82
|
|
98
83
|
def standard_sort(*args)
|
99
84
|
raise NotYetImplemented
|
100
85
|
end
|
101
86
|
|
102
|
-
def standard_nested_create(model, container_association,
|
103
|
-
container, represent_with=nil)
|
87
|
+
def standard_nested_create(model, container_association, container, represent_with=nil)
|
104
88
|
# Must be able to update the container
|
105
|
-
OSU::AccessPolicy.require_action_allowed!(:update,
|
106
|
-
current_api_user,
|
107
|
-
container)
|
89
|
+
OSU::AccessPolicy.require_action_allowed!(:update, current_api_user, container)
|
108
90
|
model.send("#{container_association.to_s}=", container)
|
109
91
|
|
110
92
|
standard_create(model, represent_with)
|
111
93
|
end
|
112
94
|
|
113
95
|
def render_api_errors(errors, status = :unprocessable_entity)
|
114
|
-
hash = {status: Rack::Utils.status_code(status)}
|
96
|
+
hash = { status: Rack::Utils.status_code(status) }
|
115
97
|
case errors
|
116
98
|
when ActiveModel::Errors, Lev::BetterActiveModelErrors
|
117
99
|
hash[:errors] = []
|
118
100
|
errors.each do |attribute, message|
|
119
101
|
hash[:errors] << {
|
120
|
-
code: "#{attribute.to_s}_#{
|
121
|
-
message.to_s.gsub(/[\s-]/, '_').gsub(/[^\w]/, '')
|
122
|
-
}",
|
102
|
+
code: "#{attribute.to_s}_#{message.to_s.gsub(/[\s-]/, '_').gsub(/[^\w]/, '')}",
|
123
103
|
message: errors.full_message(attribute, message)
|
124
104
|
}
|
125
105
|
end
|
data/lib/openstax/api/version.rb
CHANGED
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|