warrant 3.1.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -7
- data/lib/warrant/api_operations.rb +9 -7
- data/lib/warrant/models/feature.rb +122 -93
- data/lib/warrant/models/list_response.rb +14 -0
- data/lib/warrant/models/object.rb +230 -0
- data/lib/warrant/models/permission.rb +72 -97
- data/lib/warrant/models/pricing_tier.rb +128 -93
- data/lib/warrant/models/query_result.rb +16 -0
- data/lib/warrant/models/role.rb +72 -91
- data/lib/warrant/models/session.rb +4 -4
- data/lib/warrant/models/tenant.rb +131 -123
- data/lib/warrant/models/user.rb +180 -147
- data/lib/warrant/models/warrant.rb +201 -110
- data/lib/warrant/util.rb +6 -0
- data/lib/warrant/version.rb +1 -1
- data/lib/warrant.rb +3 -0
- metadata +5 -2
@@ -1,21 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Warrant
|
4
|
-
class PricingTier
|
4
|
+
class PricingTier < Warrant::Object
|
5
5
|
OBJECT_TYPE = "pricing-tier"
|
6
6
|
|
7
7
|
include Warrant::WarrantObject
|
8
8
|
|
9
|
-
|
9
|
+
alias :pricing_tier_id :object_id
|
10
10
|
|
11
11
|
# @!visibility private
|
12
|
-
def initialize(pricing_tier_id)
|
13
|
-
|
12
|
+
def initialize(pricing_tier_id, meta = {}, created_at = nil)
|
13
|
+
super(OBJECT_TYPE, pricing_tier_id, meta, created_at)
|
14
14
|
end
|
15
15
|
|
16
16
|
# Creates a pricing tier with the given parameters
|
17
17
|
#
|
18
|
-
# @option params [String] :
|
18
|
+
# @option params [String] :pricing tier_id User defined string identifier for this pricing tier. If not provided, Warrant will create an id for the pricing tier and return it. In this case, you should store the id in your system as you will need to provide it for any authorization requests for that pricing tier. Note that pricingTierIds in Warrant must be composed of alphanumeric chars, '-', and/or '_'. (optional)
|
19
|
+
# @option params [Hash] :meta A JSON object containing additional information about this pricing tier (e.g. name/description) to be persisted to Warrant. (optional)
|
19
20
|
#
|
20
21
|
# @return [PricingTier] created pricing tier
|
21
22
|
#
|
@@ -26,16 +27,9 @@ module Warrant
|
|
26
27
|
# @raise [Warrant::InternalError]
|
27
28
|
# @raise [Warrant::InvalidRequestError]
|
28
29
|
# @raise [Warrant::UnauthorizedError]
|
29
|
-
def self.create(params = {})
|
30
|
-
|
31
|
-
|
32
|
-
case res
|
33
|
-
when Net::HTTPSuccess
|
34
|
-
res_json = JSON.parse(res.body)
|
35
|
-
PricingTier.new(res_json['pricingTierId'])
|
36
|
-
else
|
37
|
-
APIOperations.raise_error(res)
|
38
|
-
end
|
30
|
+
def self.create(params = {}, options = {})
|
31
|
+
object = Object.create({ object_type: OBJECT_TYPE, object_id: params[:pricing_tier_id], meta: params[:meta] }, options)
|
32
|
+
return PricingTier.new(object.object_id, object.meta, object.created_at)
|
39
33
|
end
|
40
34
|
|
41
35
|
# Deletes a pricing tier with given pricing tier id
|
@@ -51,39 +45,33 @@ module Warrant
|
|
51
45
|
# @raise [Warrant::InvalidParameterError]
|
52
46
|
# @raise [Warrant::NotFoundError]
|
53
47
|
# @raise [Warrant::UnauthorizedError]
|
54
|
-
def self.delete(pricing_tier_id)
|
55
|
-
|
56
|
-
|
57
|
-
case res
|
58
|
-
when Net::HTTPSuccess
|
59
|
-
return
|
60
|
-
else
|
61
|
-
APIOperations.raise_error(res)
|
62
|
-
end
|
48
|
+
def self.delete(pricing_tier_id, options = {})
|
49
|
+
return Object.delete(OBJECT_TYPE, pricing_tier_id, options)
|
63
50
|
end
|
64
51
|
|
65
52
|
# Lists all pricing tiers for your organization
|
66
53
|
#
|
67
|
-
# @
|
68
|
-
# @
|
54
|
+
# @param [Hash] filters Filters to apply to result set
|
55
|
+
# @param [Hash] options Options to apply on a per-request basis
|
56
|
+
# @option filters [Integer] :limit A positive integer representing the maximum number of items to return in the response. Must be less than or equal to 1000. Defaults to 25. (optional)
|
57
|
+
# @option filters [String] :prev_cursor A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)
|
58
|
+
# @option filters [String] :next_cursor A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)
|
59
|
+
# @option filters [String] :sort_by The column to sort the result by. Unless otherwise specified, all list endpoints are sorted by their unique identifier by default. Supported values for objects are +object_type+, +object_id+, and +created_at+ (optional)
|
60
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
61
|
+
# @option options [String] :warrant_token A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)
|
69
62
|
#
|
70
|
-
# @return [Array<
|
63
|
+
# @return [Array<PricingTier>] all pricing tiers for your organization
|
71
64
|
#
|
72
65
|
# @example List all pricing tiers
|
73
66
|
# Warrant::PricingTier.list()
|
74
67
|
#
|
75
68
|
# @raise [Warrant::InternalError]
|
76
69
|
# @raise [Warrant::UnauthorizedError]
|
77
|
-
def self.list(filters = {})
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
pricing_tiers = JSON.parse(res.body)
|
83
|
-
pricing_tiers.map{ |pricing_tier| PricingTier.new(pricing_tier['pricingTierId']) }
|
84
|
-
else
|
85
|
-
APIOperations.raise_error(res)
|
86
|
-
end
|
70
|
+
def self.list(filters = {}, options = {})
|
71
|
+
filters.merge({ object_type: "pricing-tier" })
|
72
|
+
list_response = Object.list(filters, options)
|
73
|
+
pricing_tiers = list_response.results.map{ |object| PricingTier.new(object.object_id, object.meta, object.created_at)}
|
74
|
+
return ListResponse.new(pricing_tiers, list_response.prev_cursor, list_response.next_cursor)
|
87
75
|
end
|
88
76
|
|
89
77
|
# Get a pricing_tier with the given pricing_tier_id
|
@@ -96,46 +84,79 @@ module Warrant
|
|
96
84
|
# @raise [Warrant::InvalidParameterError]
|
97
85
|
# @raise [Warrant::NotFoundError]
|
98
86
|
# @raise [Warrant::UnauthorizedError]
|
99
|
-
def self.get(pricing_tier_id)
|
100
|
-
|
87
|
+
def self.get(pricing_tier_id, options = {})
|
88
|
+
object = Object.get(OBJECT_TYPE, pricing_tier_id, options)
|
89
|
+
return PricingTier.new(object.object_id, object.meta, object.created_at)
|
90
|
+
end
|
101
91
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
92
|
+
# Updates a pricing tier with the given pricing_tier_id and params
|
93
|
+
#
|
94
|
+
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier to be updated.
|
95
|
+
# @param meta [Hash] A JSON object containing additional information about this pricing tier (e.g. name/description, etc.) to be persisted to Warrant.
|
96
|
+
#
|
97
|
+
# @return [PricingTier] updated pricing tier
|
98
|
+
#
|
99
|
+
# @example Update pricing tier "test-pricing-tier"'s name
|
100
|
+
# Warrant::PricingTier.update("test-pricing-tier", { name: "Test Tier" })
|
101
|
+
#
|
102
|
+
# @raise [Warrant::InternalError]
|
103
|
+
# @raise [Warrant::InvalidParameterError]
|
104
|
+
# @raise [Warrant::InvalidRequestError]
|
105
|
+
# @raise [Warrant::NotFoundError]
|
106
|
+
# @raise [Warrant::UnauthorizedError]
|
107
|
+
def self.update(pricing_tier_id, meta, options = {})
|
108
|
+
object = Object.update(OBJECT_TYPE, pricing_tier_id, meta, options)
|
109
|
+
return PricingTier.new(object.object_id, object.meta, object.created_at)
|
109
110
|
end
|
110
111
|
|
112
|
+
# Updates a pricing tier with the given params
|
113
|
+
#
|
114
|
+
# @param meta [Hash] A JSON object containing additional information about this pricing tier (e.g. name/description, etc.) to be persisted to Warrant.
|
115
|
+
#
|
116
|
+
# @return [PricingTier] updated pricing tier
|
117
|
+
#
|
118
|
+
# @example Update pricing tier "test-pricing-tier"'s name
|
119
|
+
# pricing_tier = Warrant::PricingTier.get("test-pricing-tier")
|
120
|
+
# pricing_tier.update({ name: "Test Tier" })
|
121
|
+
#
|
122
|
+
# @raise [Warrant::InternalError]
|
123
|
+
# @raise [Warrant::InvalidParameterError]
|
124
|
+
# @raise [Warrant::InvalidRequestError]
|
125
|
+
# @raise [Warrant::NotFoundError]
|
126
|
+
# @raise [Warrant::UnauthorizedError]
|
127
|
+
def update(meta, options = {})
|
128
|
+
return PricingTier.update(pricing_tier_id, meta)
|
129
|
+
end
|
111
130
|
|
112
131
|
# List pricing tiers for tenant
|
113
132
|
#
|
114
133
|
# @param tenant_id [String] The tenant_id of the tenant to list pricing tiers for.
|
115
|
-
# @
|
116
|
-
# @
|
134
|
+
# @param [Hash] filters Filters to apply to result set
|
135
|
+
# @param [Hash] options Options to apply on a per-request basis
|
136
|
+
# @option filters [String] :object_type Only return objects with an `objectType` matching this value
|
137
|
+
# @option filters [Integer] :limit A positive integer representing the maximum number of items to return in the response. Must be less than or equal to 1000. Defaults to 25. (optional)
|
138
|
+
# @option filters [String] :prev_cursor A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)
|
139
|
+
# @option filters [String] :next_cursor A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)
|
140
|
+
# @option filters [String] :sort_by The column to sort the result by. Unless otherwise specified, all list endpoints are sorted by their unique identifier by default. Supported values for objects are +object_type+, +object_id+, and +created_at+ (optional)
|
141
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
142
|
+
# @option options [String] :warrant_token A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)
|
117
143
|
#
|
118
144
|
# @return [Array<PricingTier>] assigned pricing tiers for the tenant
|
119
145
|
#
|
120
146
|
# @raise [Warrant::InternalError]
|
121
147
|
# @raise [Warrant::InvalidParameterError]
|
122
148
|
# @raise [Warrant::UnauthorizedError]
|
123
|
-
def self.list_for_tenant(tenant_id, filters = {})
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
when Net::HTTPSuccess
|
128
|
-
pricing_tiers = JSON.parse(res.body)
|
129
|
-
pricing_tiers.map{ |pricing_tier| PricingTier.new(pricing_tier['pricingTierId']) }
|
130
|
-
else
|
131
|
-
APIOperations.raise_error(res)
|
132
|
-
end
|
149
|
+
def self.list_for_tenant(tenant_id, filters = {}, options = {})
|
150
|
+
query_response = Warrant.query("select pricing-tier where tenant:#{tenant_id} is *", filters: filters, options: options)
|
151
|
+
pricing_tiers = query_response.results.map{ |result| PricingTier.new(result.object_id, result.meta) }
|
152
|
+
return ListResponse.new(pricing_tiers, query_response.prev_cursor, query_response.next_cursor)
|
133
153
|
end
|
134
154
|
|
135
155
|
# Assign a pricing tier to a tenant
|
136
156
|
#
|
137
157
|
# @param tenant_id [String] The tenant_id of the tenant you want to assign a pricing tier to.
|
138
158
|
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to assign to a tenant.
|
159
|
+
# @param relation [String] The relation for this pricing tier to tenant association. The relation must be valid as per the +pricing tier+ object type definition.
|
139
160
|
#
|
140
161
|
# @return [Warrant] warrant assigning pricing tier to tenant
|
141
162
|
#
|
@@ -144,14 +165,15 @@ module Warrant
|
|
144
165
|
# @raise [Warrant::InvalidParameterError]
|
145
166
|
# @raise [Warrant::NotFoundError]
|
146
167
|
# @raise [Warrant::UnauthorizedError]
|
147
|
-
def self.assign_to_tenant(tenant_id, pricing_tier_id)
|
148
|
-
Warrant.create({ object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id },
|
168
|
+
def self.assign_to_tenant(tenant_id, pricing_tier_id, relation: "member", options: {})
|
169
|
+
Warrant.create({ object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id }, relation, { object_type: Tenant::OBJECT_TYPE, object_id: tenant_id }, nil, options)
|
149
170
|
end
|
150
171
|
|
151
172
|
# Remove a pricing tier from a tenant
|
152
173
|
#
|
153
174
|
# @param tenant_id [String] The tenant_id of the tenant you want to remove a pricing tier from.
|
154
175
|
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to remove from a tenant.
|
176
|
+
# @param relation [String] The relation for this pricing tier to tenant association. The relation must be valid as per the +pricing tier+ object type definition.
|
155
177
|
#
|
156
178
|
# @return [nil] if remove was successful
|
157
179
|
#
|
@@ -160,37 +182,39 @@ module Warrant
|
|
160
182
|
# @raise [Warrant::NotFoundError]
|
161
183
|
# @raise [Warrant::UnauthorizedError]
|
162
184
|
# @raise [Warrant::WarrantError]
|
163
|
-
def self.remove_from_tenant(tenant_id, pricing_tier_id)
|
164
|
-
Warrant.delete({ object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id },
|
185
|
+
def self.remove_from_tenant(tenant_id, pricing_tier_id, relation: "member", options: {})
|
186
|
+
Warrant.delete({ object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id }, relation, { object_type: Tenant::OBJECT_TYPE, object_id: tenant_id }, nil, options)
|
165
187
|
end
|
166
188
|
|
167
189
|
# List pricing tiers for user
|
168
190
|
#
|
169
191
|
# @param user_id [String] The user_id of the user to list pricing tiers for.
|
170
|
-
# @
|
171
|
-
# @
|
192
|
+
# @param [Hash] filters Filters to apply to result set
|
193
|
+
# @param [Hash] options Options to apply on a per-request basis
|
194
|
+
# @option filters [String] :object_type Only return objects with an `objectType` matching this value
|
195
|
+
# @option filters [Integer] :limit A positive integer representing the maximum number of items to return in the response. Must be less than or equal to 1000. Defaults to 25. (optional)
|
196
|
+
# @option filters [String] :prev_cursor A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)
|
197
|
+
# @option filters [String] :next_cursor A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)
|
198
|
+
# @option filters [String] :sort_by The column to sort the result by. Unless otherwise specified, all list endpoints are sorted by their unique identifier by default. Supported values for objects are +object_type+, +object_id+, and +created_at+ (optional)
|
199
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
200
|
+
# @option options [String] :warrant_token A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)
|
172
201
|
#
|
173
202
|
# @return [Array<PricingTier>] assigned pricing tiers for the user
|
174
203
|
#
|
175
204
|
# @raise [Warrant::InternalError]
|
176
205
|
# @raise [Warrant::InvalidParameterError]
|
177
206
|
# @raise [Warrant::UnauthorizedError]
|
178
|
-
def self.list_for_user(user_id, filters = {})
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
when Net::HTTPSuccess
|
183
|
-
pricing_tiers = JSON.parse(res.body)
|
184
|
-
pricing_tiers.map{ |pricing_tier| PricingTier.new(pricing_tier['pricingTierId']) }
|
185
|
-
else
|
186
|
-
APIOperations.raise_error(res)
|
187
|
-
end
|
207
|
+
def self.list_for_user(user_id, filters = {}, options = {})
|
208
|
+
query_response = Warrant.query("select pricing-tier where user:#{user_id} is *", filters: filters, options: options)
|
209
|
+
pricing_tiers = query_response.results.map{ |result| PricingTier.new(result.object_id, result.meta) }
|
210
|
+
return ListResponse.new(pricing_tiers, query_response.prev_cursor, query_response.next_cursor)
|
188
211
|
end
|
189
212
|
|
190
213
|
# Assign a pricing tier to a user
|
191
214
|
#
|
192
215
|
# @param user_id [String] The user_id of the user you want to assign a pricing tier to.
|
193
216
|
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to assign to a user.
|
217
|
+
# @param relation [String] The relation for this pricing tier to user association. The relation must be valid as per the +pricing tier+ object type definition.
|
194
218
|
#
|
195
219
|
# @return [Warrant] warrant assigning pricing tier to user
|
196
220
|
#
|
@@ -199,14 +223,15 @@ module Warrant
|
|
199
223
|
# @raise [Warrant::InvalidParameterError]
|
200
224
|
# @raise [Warrant::NotFoundError]
|
201
225
|
# @raise [Warrant::UnauthorizedError]
|
202
|
-
def self.assign_to_user(user_id, pricing_tier_id)
|
203
|
-
Warrant.create({ object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id },
|
226
|
+
def self.assign_to_user(user_id, pricing_tier_id, relation: "member", options: {})
|
227
|
+
Warrant.create({ object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id }, relation, { object_type: User::OBJECT_TYPE, object_id: user_id }, nil, options)
|
204
228
|
end
|
205
229
|
|
206
230
|
# Remove a pricing tier from a user
|
207
231
|
#
|
208
232
|
# @param user_id [String] The user_id of the user you want to remove a pricing tier from.
|
209
233
|
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to remove from a user.
|
234
|
+
# @param relation [String] The relation for this pricing tier to user association. The relation must be valid as per the +pricing tier+ object type definition.
|
210
235
|
#
|
211
236
|
# @return [nil] if remove was successful
|
212
237
|
#
|
@@ -215,27 +240,35 @@ module Warrant
|
|
215
240
|
# @raise [Warrant::NotFoundError]
|
216
241
|
# @raise [Warrant::UnauthorizedError]
|
217
242
|
# @raise [Warrant::WarrantError]
|
218
|
-
def self.remove_from_user(user_id, pricing_tier_id)
|
219
|
-
Warrant.delete({ object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id },
|
243
|
+
def self.remove_from_user(user_id, pricing_tier_id, relation: "member", options: {})
|
244
|
+
Warrant.delete({ object_type: PricingTier::OBJECT_TYPE, object_id: pricing_tier_id }, relation, { object_type: User::OBJECT_TYPE, object_id: user_id }, nil, options)
|
220
245
|
end
|
221
246
|
|
222
247
|
# List features for a pricing tier
|
223
248
|
#
|
224
|
-
# @
|
225
|
-
# @
|
249
|
+
# @param [Hash] filters Filters to apply to result set
|
250
|
+
# @param [Hash] options Options to apply on a per-request basis
|
251
|
+
# @option filters [String] :object_type Only return objects with an `objectType` matching this value
|
252
|
+
# @option filters [Integer] :limit A positive integer representing the maximum number of items to return in the response. Must be less than or equal to 1000. Defaults to 25. (optional)
|
253
|
+
# @option filters [String] :prev_cursor A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)
|
254
|
+
# @option filters [String] :next_cursor A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)
|
255
|
+
# @option filters [String] :sort_by The column to sort the result by. Unless otherwise specified, all list endpoints are sorted by their unique identifier by default. Supported values for objects are +object_type+, +object_id+, and +created_at+ (optional)
|
256
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
257
|
+
# @option options [String] :warrant_token A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)
|
226
258
|
#
|
227
259
|
# @return [Array<Feature>] assigned features for the pricing tier
|
228
260
|
#
|
229
261
|
# @raise [Warrant::InternalError]
|
230
262
|
# @raise [Warrant::InvalidParameterError]
|
231
263
|
# @raise [Warrant::UnauthorizedError]
|
232
|
-
def list_features(filters = {})
|
233
|
-
return Feature.list_for_pricing_tier(pricing_tier_id, filters)
|
264
|
+
def list_features(filters = {}, options = {})
|
265
|
+
return Feature.list_for_pricing_tier(pricing_tier_id, filters, options)
|
234
266
|
end
|
235
267
|
|
236
268
|
# Assign a feature to a pricing tier
|
237
269
|
#
|
238
270
|
# @param feature_id [String] The feature_id of the feature you want to assign to the pricing tier.
|
271
|
+
# @param relation [String] The relation for this feature to pricing tier association. The relation must be valid as per the +feature+ object type definition.
|
239
272
|
#
|
240
273
|
# @return [Feature] assigned feature
|
241
274
|
#
|
@@ -244,13 +277,14 @@ module Warrant
|
|
244
277
|
# @raise [Warrant::InvalidParameterError]
|
245
278
|
# @raise [Warrant::NotFoundError]
|
246
279
|
# @raise [Warrant::UnauthorizedError]
|
247
|
-
def assign_feature(feature_id)
|
248
|
-
return Feature.assign_to_pricing_tier(pricing_tier_id, feature_id)
|
280
|
+
def assign_feature(feature_id, relation: "member", options: {})
|
281
|
+
return Feature.assign_to_pricing_tier(pricing_tier_id, feature_id, relation: relation, options: options)
|
249
282
|
end
|
250
283
|
|
251
284
|
# Remove a feature from a pricing tier
|
252
285
|
#
|
253
286
|
# @param feature_id [String] The feature_id of the feature you want to assign from the pricing tier.
|
287
|
+
# @param relation [String] The relation for this feature to pricing tier association. The relation must be valid as per the +feature+ object type definition.
|
254
288
|
#
|
255
289
|
# @return [nil] if remove was successful
|
256
290
|
#
|
@@ -259,15 +293,16 @@ module Warrant
|
|
259
293
|
# @raise [Warrant::NotFoundError]
|
260
294
|
# @raise [Warrant::UnauthorizedError]
|
261
295
|
# @raise [Warrant::WarrantError]
|
262
|
-
def remove_feature(feature_id)
|
263
|
-
return Feature.remove_from_pricing_tier(pricing_tier_id, feature_id)
|
296
|
+
def remove_feature(feature_id, relation: "member", options: {})
|
297
|
+
return Feature.remove_from_pricing_tier(pricing_tier_id, feature_id, relation: relation, options: options)
|
264
298
|
end
|
265
299
|
|
266
300
|
# Check whether a pricing tier has a given feature
|
267
301
|
#
|
268
302
|
# @param feature_id [String] The feature_id of the feature to check whether the pricing tier has access to.
|
303
|
+
# @param relation [String] The relation for this feature to pricing tier association. The relation must be valid as per the +feature+ object type definition.
|
304
|
+
# @param [Hash] options Options to apply on a per-request basis
|
269
305
|
# @option options [Hash] :context Object containing key-value pairs that specifies the context the warrant should be checked in. (optional)
|
270
|
-
# @option options [Boolean] :consistent_read Boolean flag indicating whether or not to enforce strict consistency for this access check. Defaults to false. (optional)
|
271
306
|
# @option options [Boolean] :debug Boolean flag indicating whether or not to return debug information for this access check. Defaults to false. (optional)
|
272
307
|
#
|
273
308
|
# @return [Boolean] whether or not the pricing tier has the given feature
|
@@ -276,17 +311,17 @@ module Warrant
|
|
276
311
|
# @raise [Warrant::InvalidParameterError]
|
277
312
|
# @raise [Warrant::NotFoundError]
|
278
313
|
# @raise [Warrant::UnauthorizedError]
|
279
|
-
def has_feature?(feature_id,
|
280
|
-
return Warrant.has_feature?(
|
314
|
+
def has_feature?(feature_id, relation: "member", options: {})
|
315
|
+
return Warrant.has_feature?({
|
281
316
|
feature_id: feature_id,
|
317
|
+
relation: relation,
|
282
318
|
subject: {
|
283
319
|
object_type: "pricing-tier",
|
284
320
|
object_id: pricing_tier_id
|
285
321
|
},
|
286
|
-
context:
|
287
|
-
|
288
|
-
|
289
|
-
)
|
322
|
+
context: options[:context],
|
323
|
+
debug: options[:debug]
|
324
|
+
}, options)
|
290
325
|
end
|
291
326
|
|
292
327
|
def warrant_object_type
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Warrant
|
4
|
+
class QueryResult
|
5
|
+
attr_accessor :object_type, :object_id, :warrant, :is_implicit, :meta
|
6
|
+
|
7
|
+
# @!visibility private
|
8
|
+
def initialize(object_type, object_id, warrant, is_implicit, meta)
|
9
|
+
@object_type = object_type
|
10
|
+
@object_id = object_id
|
11
|
+
@warrant = warrant
|
12
|
+
@is_implicit = is_implicit
|
13
|
+
@meta = meta
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|