warrant 3.1.0 → 5.0.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/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
data/lib/warrant/models/user.rb
CHANGED
@@ -1,24 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Warrant
|
4
|
-
class User
|
4
|
+
class User < Warrant::Object
|
5
5
|
OBJECT_TYPE = "user"
|
6
6
|
|
7
7
|
include Warrant::WarrantObject
|
8
8
|
|
9
|
-
|
9
|
+
alias :user_id :object_id
|
10
10
|
|
11
11
|
# @!visibility private
|
12
|
-
def initialize(user_id,
|
13
|
-
|
14
|
-
@email = email
|
15
|
-
@created_at = created_at
|
12
|
+
def initialize(user_id, meta = {}, created_at = nil)
|
13
|
+
super(OBJECT_TYPE, user_id, meta, created_at)
|
16
14
|
end
|
17
15
|
|
18
16
|
# Creates a user with the given parameters
|
19
17
|
#
|
20
18
|
# @option params [String] :user_id User defined string identifier for this user. If not provided, Warrant will create an id for the user 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 user. Note that userIds in Warrant must be composed of alphanumeric chars and/or '-', '_', and '@'. (optional)
|
21
|
-
# @option params [
|
19
|
+
# @option params [Hash] :meta A JSON object containing additional information about this user (e.g. email/name) to be persisted to Warrant. (optional)
|
22
20
|
#
|
23
21
|
# @return [User] created user
|
24
22
|
#
|
@@ -31,23 +29,16 @@ module Warrant
|
|
31
29
|
# @raise [Warrant::InvalidRequestError]
|
32
30
|
# @raise [Warrant::NotFoundError]
|
33
31
|
# @raise [Warrant::UnauthorizedError]
|
34
|
-
def self.create(params = {})
|
35
|
-
|
36
|
-
|
37
|
-
case res
|
38
|
-
when Net::HTTPSuccess
|
39
|
-
res_json = JSON.parse(res.body)
|
40
|
-
User.new(res_json['userId'], res_json['email'], res_json['createdAt'])
|
41
|
-
else
|
42
|
-
APIOperations.raise_error(res)
|
43
|
-
end
|
32
|
+
def self.create(params = {}, options = {})
|
33
|
+
object = Object.create({ object_type: OBJECT_TYPE, object_id: params[:user_id], meta: params[:meta] }, options)
|
34
|
+
return User.new(object.object_id, object.meta, object.created_at)
|
44
35
|
end
|
45
36
|
|
46
37
|
# Batch creates multiple users with given parameters
|
47
38
|
#
|
48
|
-
# @param [Array] Array of users to create.
|
49
|
-
#
|
50
|
-
#
|
39
|
+
# @param [Array<Hash>] users Array of users to create.
|
40
|
+
# @option users [String] :user_id User defined string identifier for this user. If not provided, Warrant will create an id for the user and return it. In this case, you should store the id in your system for future reference. Note that tenantIds in Warrant must be composed of alphanumeric chars and/or '-', '_', and '@'. (optional)
|
41
|
+
# @option users [Hash] :meta A JSON object containing additional information about the user (e.g. name/description, etc.) to be persisted to Warrant. (optional)
|
51
42
|
#
|
52
43
|
# @return [Array<User>] all created users
|
53
44
|
#
|
@@ -60,21 +51,14 @@ module Warrant
|
|
60
51
|
# @raise [Warrant::InvalidRequestError]
|
61
52
|
# @raise [Warrant::NotFoundError]
|
62
53
|
# @raise [Warrant::UnauthorizedError]
|
63
|
-
def self.batch_create(users =
|
64
|
-
res =
|
65
|
-
|
66
|
-
case res
|
67
|
-
when Net::HTTPSuccess
|
68
|
-
users = JSON.parse(res.body)
|
69
|
-
users.map{ |user| User.new(user['userId'], user['email'], user['createdAt']) }
|
70
|
-
else
|
71
|
-
APIOperations.raise_error(res)
|
72
|
-
end
|
54
|
+
def self.batch_create(users, options = {})
|
55
|
+
res = Object.batch_create(users.map{ |user| { object_type: OBJECT_TYPE, object_id: user[:user_id], meta: user[:meta] }}, options)
|
56
|
+
return res.map{ |obj| User.new(obj.object_id, obj.meta, obj.created_at)}
|
73
57
|
end
|
74
58
|
|
75
59
|
# Deletes a user with given user id
|
76
60
|
#
|
77
|
-
# @param user_id [String] User defined string identifier for this user.
|
61
|
+
# @param user_id [String] User defined string identifier for this user.
|
78
62
|
#
|
79
63
|
# @return [nil] if delete was successful
|
80
64
|
#
|
@@ -85,21 +69,44 @@ module Warrant
|
|
85
69
|
# @raise [Warrant::InvalidParameterError]
|
86
70
|
# @raise [Warrant::NotFoundError]
|
87
71
|
# @raise [Warrant::UnauthorizedError]
|
88
|
-
def self.delete(user_id)
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
72
|
+
def self.delete(user_id, options = {})
|
73
|
+
return Object.delete(OBJECT_TYPE, user_id, options)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Batch deletes multiple users with given parameters
|
77
|
+
#
|
78
|
+
# @param [Array<Hash, User>] users Array of users to delete.
|
79
|
+
# @option users [String] :user_id Customer defined string identifier for this user.
|
80
|
+
#
|
81
|
+
# @return [nil] if delete was successful
|
82
|
+
#
|
83
|
+
# @example Delete two users with ids "test-user-1" and "test-user-2"
|
84
|
+
# Warrant::User.batch_delete([{ user_id: "test-user-1" }, { user_id: "test-user-2" }])
|
85
|
+
#
|
86
|
+
# @raise [Warrant::InternalError]
|
87
|
+
# @raise [Warrant::InvalidParameterError]
|
88
|
+
# @raise [Warrant::NotFoundError]
|
89
|
+
# @raise [Warrant::UnauthorizedError]
|
90
|
+
def self.batch_delete(users, options = {})
|
91
|
+
return Object.batch_delete(users.map{ |user|
|
92
|
+
if user.instance_of? User
|
93
|
+
{ object_type: OBJECT_TYPE, object_id: user.object_id }
|
94
|
+
else
|
95
|
+
{ object_type: OBJECT_TYPE, object_id: user[:user_id] }
|
96
|
+
end
|
97
|
+
}, options)
|
97
98
|
end
|
98
99
|
|
99
100
|
# Lists all users for your organization
|
100
101
|
#
|
101
|
-
# @
|
102
|
-
# @
|
102
|
+
# @param [Hash] filters Filters to apply to result set
|
103
|
+
# @param [Hash] options Options to apply on a per-request basis
|
104
|
+
# @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)
|
105
|
+
# @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)
|
106
|
+
# @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)
|
107
|
+
# @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)
|
108
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
109
|
+
# @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)
|
103
110
|
#
|
104
111
|
# @return [Array<User>] all users for your organization
|
105
112
|
#
|
@@ -109,16 +116,11 @@ module Warrant
|
|
109
116
|
# @raise [Warrant::InternalError]
|
110
117
|
# @raise [Warrant::InvalidParameterError]
|
111
118
|
# @raise [Warrant::UnauthorizedError]
|
112
|
-
def self.list(filters = {})
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
users = JSON.parse(res.body)
|
118
|
-
users.map{ |user| User.new(user['userId'], user['email'], user['createdAt']) }
|
119
|
-
else
|
120
|
-
APIOperations.raise_error(res)
|
121
|
-
end
|
119
|
+
def self.list(filters = {}, options = {})
|
120
|
+
filters.merge({ object_type: "user" })
|
121
|
+
list_response = Object.list(filters, options)
|
122
|
+
users = list_response.results.map{ |object| User.new(object.object_id, object.meta, object.created_at)}
|
123
|
+
return ListResponse.new(users, list_response.prev_cursor, list_response.next_cursor)
|
122
124
|
end
|
123
125
|
|
124
126
|
# Get a user with the given user_id
|
@@ -131,23 +133,15 @@ module Warrant
|
|
131
133
|
# @raise [Warrant::InvalidParameterError]
|
132
134
|
# @raise [Warrant::NotFoundError]
|
133
135
|
# @raise [Warrant::UnauthorizedError]
|
134
|
-
def self.get(user_id)
|
135
|
-
|
136
|
-
|
137
|
-
case res
|
138
|
-
when Net::HTTPSuccess
|
139
|
-
user = JSON.parse(res.body)
|
140
|
-
User.new(user['userId'], user['email'], user['createdAt'])
|
141
|
-
else
|
142
|
-
APIOperations.raise_error(res)
|
143
|
-
end
|
136
|
+
def self.get(user_id, options = {})
|
137
|
+
object = Object.get(OBJECT_TYPE, user_id, options)
|
138
|
+
return User.new(object.object_id, object.meta, object.created_at)
|
144
139
|
end
|
145
140
|
|
146
|
-
# Updates a user with the given user_id
|
141
|
+
# Updates a user with the given user_id
|
147
142
|
#
|
148
|
-
# @param user_id [String] User defined string identifier for this user.
|
149
|
-
# @param [Hash]
|
150
|
-
# @option params [String] :email Email address for this user. Designed to be used as a UI-friendly identifier. (optional)
|
143
|
+
# @param user_id [String] User defined string identifier for this user.
|
144
|
+
# @param meta [Hash] A JSON object containing additional information about this user (e.g. name/description, etc.) to be persisted to Warrant.
|
151
145
|
#
|
152
146
|
# @return [User] updated user
|
153
147
|
#
|
@@ -159,55 +153,56 @@ module Warrant
|
|
159
153
|
# @raise [Warrant::InvalidRequestError]
|
160
154
|
# @raise [Warrant::NotFoundError]
|
161
155
|
# @raise [Warrant::UnauthorizedError]
|
162
|
-
def self.update(user_id,
|
163
|
-
|
164
|
-
|
165
|
-
case res
|
166
|
-
when Net::HTTPSuccess
|
167
|
-
res_json = JSON.parse(res.body)
|
168
|
-
User.new(res_json['userId'], res_json['email'], res_json['createdAt'])
|
169
|
-
else
|
170
|
-
APIOperations.raise_error(res)
|
171
|
-
end
|
156
|
+
def self.update(user_id, meta, options = {})
|
157
|
+
object = Object.update(OBJECT_TYPE, user_id, meta, options)
|
158
|
+
return User.new(object.object_id, object.meta, object.created_at)
|
172
159
|
end
|
173
160
|
|
174
161
|
# Updates the user with the given params
|
175
162
|
#
|
176
|
-
# @
|
163
|
+
# @param meta [Hash] A JSON object containing additional information about this user (e.g. name/description, etc.) to be persisted to Warrant.
|
177
164
|
#
|
178
165
|
# @return [User] updated user
|
179
166
|
#
|
180
167
|
# @example Update user "test-user"'s email
|
181
168
|
# user = Warrant::User.get("test-user")
|
182
|
-
# user.update(email: "my-new-email@example.com")
|
169
|
+
# user.update({ email: "my-new-email@example.com" })
|
183
170
|
#
|
184
171
|
# @raise [Warrant::InternalError]
|
185
172
|
# @raise [Warrant::InvalidParameterError]
|
186
173
|
# @raise [Warrant::InvalidRequestError]
|
187
174
|
# @raise [Warrant::NotFoundError]
|
188
175
|
# @raise [Warrant::UnauthorizedError]
|
189
|
-
def update(
|
190
|
-
return User.update(user_id,
|
176
|
+
def update(meta, options = {})
|
177
|
+
return User.update(user_id, meta, options)
|
191
178
|
end
|
192
179
|
|
193
180
|
# List all roles for a user.
|
194
181
|
#
|
195
|
-
# @
|
196
|
-
# @
|
182
|
+
# @param [Hash] filters Filters to apply to result set
|
183
|
+
# @param [Hash] options Options to apply on a per-request basis
|
184
|
+
# @option filters [String] :object_type Only return objects with an `objectType` matching this value
|
185
|
+
# @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)
|
186
|
+
# @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)
|
187
|
+
# @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)
|
188
|
+
# @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)
|
189
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
190
|
+
# @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)
|
197
191
|
#
|
198
192
|
# @return [Array<Role>] all roles for the user
|
199
193
|
#
|
200
194
|
# @raise [Warrant::InternalError]
|
201
195
|
# @raise [Warrant::MissingRequiredParameterError]
|
202
196
|
# @raise [Warrant::UnauthorizedError]
|
203
|
-
def list_roles(filters = {})
|
204
|
-
return Role.list_for_user(user_id, filters)
|
197
|
+
def list_roles(filters = {}, options = {})
|
198
|
+
return Role.list_for_user(user_id, filters, options)
|
205
199
|
end
|
206
200
|
|
207
201
|
# Assign a role to a user
|
208
202
|
#
|
209
203
|
# @param user_id [String] The user_id of the user you want to assign a role to.
|
210
204
|
# @param role_id [String] The role_id of the role you want to assign to a user.
|
205
|
+
# @param relation [String] The relation for this role to user association. The relation must be valid as per the +role+ object type definition.
|
211
206
|
#
|
212
207
|
# @return [Permission] assigned role
|
213
208
|
#
|
@@ -221,14 +216,15 @@ module Warrant
|
|
221
216
|
# @raise [Warrant::MissingRequiredParameterError]
|
222
217
|
# @raise [Warrant::NotFoundError]
|
223
218
|
# @raise [Warrant::UnauthorizedError]
|
224
|
-
def assign_role(role_id)
|
225
|
-
return Role.assign_to_user(user_id, role_id)
|
219
|
+
def assign_role(role_id, relation: "member", options: {})
|
220
|
+
return Role.assign_to_user(user_id, role_id, relation: relation, options: options)
|
226
221
|
end
|
227
222
|
|
228
223
|
# Remove a role from a user
|
229
224
|
#
|
230
225
|
# @param user_id [String] The user_id of the role you want to assign a role to.
|
231
226
|
# @param role_id [String] The role_id of the role you want to assign to a user.
|
227
|
+
# @param relation [String] The relation for this role to user association. The relation must be valid as per the +role+ object type definition.
|
232
228
|
#
|
233
229
|
# @return [nil] if remove was successful
|
234
230
|
#
|
@@ -241,27 +237,35 @@ module Warrant
|
|
241
237
|
# @raise [Warrant::MissingRequiredParameterError]
|
242
238
|
# @raise [Warrant::NotFoundError]
|
243
239
|
# @raise [Warrant::UnauthorizedError]
|
244
|
-
def remove_role(role_id)
|
245
|
-
return Role.remove_from_user(user_id, role_id)
|
240
|
+
def remove_role(role_id, relation: "member", options: {})
|
241
|
+
return Role.remove_from_user(user_id, role_id, relation: relation, options: options)
|
246
242
|
end
|
247
243
|
|
248
244
|
# List all permissions for a user
|
249
245
|
#
|
250
|
-
# @
|
251
|
-
# @
|
246
|
+
# @param [Hash] filters Filters to apply to result set
|
247
|
+
# @param [Hash] options Options to apply on a per-request basis
|
248
|
+
# @option filters [String] :object_type Only return objects with an `objectType` matching this value
|
249
|
+
# @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)
|
250
|
+
# @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)
|
251
|
+
# @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)
|
252
|
+
# @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)
|
253
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
254
|
+
# @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)
|
252
255
|
#
|
253
256
|
# @return [Array<Permission>] all permissions for the user
|
254
257
|
#
|
255
258
|
# @raise [Warrant::InternalError]
|
256
259
|
# @raise [Warrant::MissingRequiredParameterError]
|
257
260
|
# @raise [Warrant::UnauthorizedError]
|
258
|
-
def list_permissions(filters = {})
|
259
|
-
return Permission.list_for_user(user_id, filters)
|
261
|
+
def list_permissions(filters = {}, options = {})
|
262
|
+
return Permission.list_for_user(user_id, filters, options)
|
260
263
|
end
|
261
264
|
|
262
265
|
# Assign a permission to a user
|
263
266
|
#
|
264
267
|
# @param permission_id [String] The permission_id of the permission you want to assign to a user.
|
268
|
+
# @param relation [String] The relation for this permission to user association. The relation must be valid as per the +permission+ object type definition.
|
265
269
|
#
|
266
270
|
# @return [Permission] assigned permission
|
267
271
|
#
|
@@ -275,13 +279,14 @@ module Warrant
|
|
275
279
|
# @raise [Warrant::MissingRequiredParameterError]
|
276
280
|
# @raise [Warrant::NotFoundError]
|
277
281
|
# @raise [Warrant::UnauthorizedError]
|
278
|
-
def assign_permission(permission_id)
|
279
|
-
return Permission.assign_to_user(user_id, permission_id)
|
282
|
+
def assign_permission(permission_id, relation: "member", options: {})
|
283
|
+
return Permission.assign_to_user(user_id, permission_id, relation: relation, options: options)
|
280
284
|
end
|
281
285
|
|
282
286
|
# Remove a permission from a user
|
283
287
|
#
|
284
288
|
# @param permission_id [String] The permission_id of the permission you want to assign to a user.
|
289
|
+
# @param relation [String] The relation for this permission to user association. The relation must be valid as per the +permission+ object type definition.
|
285
290
|
#
|
286
291
|
# @return [nil] if remove was successful
|
287
292
|
#
|
@@ -293,15 +298,15 @@ module Warrant
|
|
293
298
|
# @raise [Warrant::MissingRequiredParameterError]
|
294
299
|
# @raise [Warrant::NotFoundError]
|
295
300
|
# @raise [Warrant::UnauthorizedError]
|
296
|
-
def remove_permission(permission_id)
|
297
|
-
Permission.remove_from_user(user_id, permission_id)
|
301
|
+
def remove_permission(permission_id, relation: "member", options: {})
|
302
|
+
Permission.remove_from_user(user_id, permission_id, relation: relation, options: options)
|
298
303
|
end
|
299
304
|
|
300
305
|
# Checks whether a user has a given permission
|
301
306
|
#
|
302
307
|
# @param permission_id [String] The permission_id of the permission you want to check whether or not it exists on the user.
|
308
|
+
# @param relation [String] The relation for this permission to user association. The relation must be valid as per the +permission+ object type definition.
|
303
309
|
# @option options [Hash] :context Object containing key-value pairs that specifies the context the warrant should be checked in. (optional)
|
304
|
-
# @option options [Boolean] :consistent_read Boolean flag indicating whether or not to enforce strict consistency for this access check. Defaults to false. (optional)
|
305
310
|
# @option options [Boolean] :debug Boolean flag indicating whether or not to return debug information for this access check. Defaults to false. (optional)
|
306
311
|
#
|
307
312
|
# @return [Boolean] whether or not the user has the given permission
|
@@ -314,43 +319,45 @@ module Warrant
|
|
314
319
|
# @raise [Warrant::InvalidParameterError]
|
315
320
|
# @raise [Warrant::NotFoundError]
|
316
321
|
# @raise [Warrant::UnauthorizedError]
|
317
|
-
def has_permission?(permission_id,
|
318
|
-
return Warrant.user_has_permission?(
|
322
|
+
def has_permission?(permission_id, relation: "member", options: {})
|
323
|
+
return Warrant.user_has_permission?({
|
319
324
|
permission_id: permission_id,
|
325
|
+
relation: relation,
|
320
326
|
user_id: user_id,
|
321
|
-
context:
|
322
|
-
|
323
|
-
|
324
|
-
)
|
327
|
+
context: options[:context],
|
328
|
+
debug: options[:debug]
|
329
|
+
}, options)
|
325
330
|
end
|
326
331
|
|
327
332
|
# List all users for a tenant
|
328
333
|
#
|
329
334
|
# @param tenant_id [String] The tenant_id of the tenant from which to fetch users
|
330
|
-
# @
|
331
|
-
# @
|
335
|
+
# @param [Hash] filters Filters to apply to result set
|
336
|
+
# @param [Hash] options Options to apply on a per-request basis
|
337
|
+
# @option filters [String] :object_type Only return objects with an `objectType` matching this value
|
338
|
+
# @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)
|
339
|
+
# @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)
|
340
|
+
# @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)
|
341
|
+
# @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)
|
342
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
343
|
+
# @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)
|
332
344
|
#
|
333
345
|
# @return [Array<User>] all users for the tenant
|
334
346
|
#
|
335
347
|
# @raise [Warrant::InternalError]
|
336
348
|
# @raise [Warrant::InvalidParameterError]
|
337
349
|
# @raise [Warrant::UnauthorizedError]
|
338
|
-
def self.list_for_tenant(tenant_id, filters = {})
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
when Net::HTTPSuccess
|
343
|
-
users = JSON.parse(res.body)
|
344
|
-
users.map{ |user| User.new(user['userId'], user['email'], user['createdAt']) }
|
345
|
-
else
|
346
|
-
APIOperations.raise_error(res)
|
347
|
-
end
|
350
|
+
def self.list_for_tenant(tenant_id, filters = {}, options = {})
|
351
|
+
query_response = Warrant.query("select * of type user for tenant:#{tenant_id}", filters: filters, options: options)
|
352
|
+
users = query_response.results.map{ |result| User.new(result.object_id, result.meta) }
|
353
|
+
return ListResponse.new(users, query_response.prev_cursor, query_response.next_cursor)
|
348
354
|
end
|
349
355
|
|
350
356
|
# Add a user to a tenant
|
351
357
|
#
|
352
358
|
# @param tenant_id [String] The tenant_id of the tenant you want to assign a user to.
|
353
359
|
# @param user_id [String] The user_id of the user you want to add to the tenant.
|
360
|
+
# @param relation [String] The relation for this tenant to user association. The relation must be valid as per the +tenant+ object type definition.
|
354
361
|
#
|
355
362
|
# @return [Warrant] warrant assigning user to the tenant
|
356
363
|
#
|
@@ -359,14 +366,15 @@ module Warrant
|
|
359
366
|
# @raise [Warrant::InvalidParameterError]
|
360
367
|
# @raise [Warrant::NotFoundError]
|
361
368
|
# @raise [Warrant::UnauthorizedError]
|
362
|
-
def self.assign_to_tenant(tenant_id, user_id)
|
363
|
-
Warrant.create({ object_type: Tenant::OBJECT_TYPE, object_id: tenant_id },
|
369
|
+
def self.assign_to_tenant(tenant_id, user_id, relation: "member", options: {})
|
370
|
+
Warrant.create({ object_type: Tenant::OBJECT_TYPE, object_id: tenant_id }, relation, { object_type: User::OBJECT_TYPE, object_id: user_id }, nil, options)
|
364
371
|
end
|
365
372
|
|
366
373
|
# Remove a user from a tenant
|
367
374
|
#
|
368
375
|
# @param tenant_id [String] The tenant_id of the tenant you want to remove the user from.
|
369
376
|
# @param user_id [String] The user_id of the user you want to remove from the tenant.
|
377
|
+
# @param relation [String] The relation for this tenant to user association. The relation must be valid as per the +tenant+ object type definition.
|
370
378
|
#
|
371
379
|
# @return [nil] if remove was successful
|
372
380
|
#
|
@@ -374,14 +382,21 @@ module Warrant
|
|
374
382
|
# @raise [Warrant::NotFoundError]
|
375
383
|
# @raise [Warrant::UnauthorizedError]
|
376
384
|
# @raise [Warrant::WarrantError]
|
377
|
-
def self.remove_from_tenant(tenant_id, user_id)
|
378
|
-
Warrant.delete({ object_type: Tenant::OBJECT_TYPE, object_id: tenant_id },
|
385
|
+
def self.remove_from_tenant(tenant_id, user_id, relation: "member", options: {})
|
386
|
+
Warrant.delete({ object_type: Tenant::OBJECT_TYPE, object_id: tenant_id }, relation, { object_type: User::OBJECT_TYPE, object_id: user_id }, nil, options)
|
379
387
|
end
|
380
388
|
|
381
389
|
# List all tenants for a user
|
382
390
|
#
|
383
|
-
# @
|
384
|
-
# @
|
391
|
+
# @param [Hash] filters Filters to apply to result set
|
392
|
+
# @param [Hash] options Options to apply on a per-request basis
|
393
|
+
# @option filters [String] :object_type Only return objects with an `objectType` matching this value
|
394
|
+
# @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)
|
395
|
+
# @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)
|
396
|
+
# @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)
|
397
|
+
# @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)
|
398
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
399
|
+
# @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)
|
385
400
|
#
|
386
401
|
# @return [Array<Tenant>] all tenants for the user
|
387
402
|
#
|
@@ -389,27 +404,35 @@ module Warrant
|
|
389
404
|
# @raise [Warrant::InvalidRequestError]
|
390
405
|
# @raise [Warrant::UnauthorizedError]
|
391
406
|
# @raise [Warrant::WarrantError]
|
392
|
-
def list_tenants(filters = {})
|
393
|
-
return Tenant.list_for_user(user_id, filters)
|
407
|
+
def list_tenants(filters = {}, options = {})
|
408
|
+
return Tenant.list_for_user(user_id, filters, options)
|
394
409
|
end
|
395
410
|
|
396
411
|
# List pricing tiers for a user
|
397
412
|
#
|
398
|
-
# @
|
399
|
-
# @
|
413
|
+
# @param [Hash] filters Filters to apply to result set
|
414
|
+
# @param [Hash] options Options to apply on a per-request basis
|
415
|
+
# @option filters [String] :object_type Only return objects with an `objectType` matching this value
|
416
|
+
# @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)
|
417
|
+
# @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)
|
418
|
+
# @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)
|
419
|
+
# @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)
|
420
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
421
|
+
# @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)
|
400
422
|
#
|
401
423
|
# @return [Array<PricingTier>] assigned pricing tiers for the user
|
402
424
|
#
|
403
425
|
# @raise [Warrant::InternalError]
|
404
426
|
# @raise [Warrant::InvalidParameterError]
|
405
427
|
# @raise [Warrant::UnauthorizedError]
|
406
|
-
def list_pricing_tiers(filters = {})
|
407
|
-
return PricingTier.list_for_user(user_id, filters)
|
428
|
+
def list_pricing_tiers(filters = {}, options = {})
|
429
|
+
return PricingTier.list_for_user(user_id, filters, options)
|
408
430
|
end
|
409
431
|
|
410
432
|
# Assign a pricing tier to a user
|
411
433
|
#
|
412
434
|
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to assign to the user.
|
435
|
+
# @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.
|
413
436
|
#
|
414
437
|
# @return [PricingTier] assigned pricing tier
|
415
438
|
#
|
@@ -418,13 +441,14 @@ module Warrant
|
|
418
441
|
# @raise [Warrant::InvalidParameterError]
|
419
442
|
# @raise [Warrant::NotFoundError]
|
420
443
|
# @raise [Warrant::UnauthorizedError]
|
421
|
-
def assign_pricing_tier(pricing_tier_id)
|
422
|
-
return PricingTier.assign_to_user(user_id, pricing_tier_id)
|
444
|
+
def assign_pricing_tier(pricing_tier_id, relation: "member", options: {})
|
445
|
+
return PricingTier.assign_to_user(user_id, pricing_tier_id, relation: relation, options: options)
|
423
446
|
end
|
424
447
|
|
425
448
|
# Remove a pricing tier from a user
|
426
449
|
#
|
427
450
|
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to assign from the user.
|
451
|
+
# @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.
|
428
452
|
#
|
429
453
|
# @return [nil] if remove was successful
|
430
454
|
#
|
@@ -433,27 +457,35 @@ module Warrant
|
|
433
457
|
# @raise [Warrant::NotFoundError]
|
434
458
|
# @raise [Warrant::UnauthorizedError]
|
435
459
|
# @raise [Warrant::WarrantError]
|
436
|
-
def remove_pricing_tier(pricing_tier_id)
|
437
|
-
return PricingTier.remove_from_user(user_id, pricing_tier_id)
|
460
|
+
def remove_pricing_tier(pricing_tier_id, relation: "member", options: {})
|
461
|
+
return PricingTier.remove_from_user(user_id, pricing_tier_id, relation: relation, options: options)
|
438
462
|
end
|
439
463
|
|
440
464
|
# List features for a user
|
441
465
|
#
|
442
|
-
# @
|
443
|
-
# @
|
466
|
+
# @param [Hash] filters Filters to apply to result set
|
467
|
+
# @param [Hash] options Options to apply on a per-request basis
|
468
|
+
# @option filters [String] :object_type Only return objects with an `objectType` matching this value
|
469
|
+
# @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)
|
470
|
+
# @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)
|
471
|
+
# @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)
|
472
|
+
# @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)
|
473
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
474
|
+
# @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)
|
444
475
|
#
|
445
476
|
# @return [Array<Feature>] assigned features for the user
|
446
477
|
#
|
447
478
|
# @raise [Warrant::InternalError]
|
448
479
|
# @raise [Warrant::InvalidParameterError]
|
449
480
|
# @raise [Warrant::UnauthorizedError]
|
450
|
-
def list_features(filters = {})
|
451
|
-
return Feature.list_for_user(user_id, filters)
|
481
|
+
def list_features(filters = {}, options = {})
|
482
|
+
return Feature.list_for_user(user_id, filters, options)
|
452
483
|
end
|
453
484
|
|
454
485
|
# Assign a feature to a user
|
455
486
|
#
|
456
487
|
# @param feature_id [String] The feature_id of the feature you want to assign to the user.
|
488
|
+
# @param relation [String] The relation for this feature to user association. The relation must be valid as per the +feature+ object type definition.
|
457
489
|
#
|
458
490
|
# @return [Feature] assigned feature
|
459
491
|
#
|
@@ -462,13 +494,14 @@ module Warrant
|
|
462
494
|
# @raise [Warrant::InvalidParameterError]
|
463
495
|
# @raise [Warrant::NotFoundError]
|
464
496
|
# @raise [Warrant::UnauthorizedError]
|
465
|
-
def assign_feature(feature_id)
|
466
|
-
return Feature.assign_to_user(user_id, feature_id)
|
497
|
+
def assign_feature(feature_id, relation: "member", options: {})
|
498
|
+
return Feature.assign_to_user(user_id, feature_id, relation: relation, options: options)
|
467
499
|
end
|
468
500
|
|
469
501
|
# Remove a feature from a user
|
470
502
|
#
|
471
503
|
# @param feature_id [String] The feature_id of the feature you want to assign from the user.
|
504
|
+
# @param relation [String] The relation for this feature to user association. The relation must be valid as per the +feature+ object type definition.
|
472
505
|
#
|
473
506
|
# @return [nil] if remove was successful
|
474
507
|
#
|
@@ -477,34 +510,34 @@ module Warrant
|
|
477
510
|
# @raise [Warrant::NotFoundError]
|
478
511
|
# @raise [Warrant::UnauthorizedError]
|
479
512
|
# @raise [Warrant::WarrantError]
|
480
|
-
def remove_feature(feature_id)
|
481
|
-
return Feature.remove_from_user(user_id, feature_id)
|
513
|
+
def remove_feature(feature_id, relation: "member", options: {})
|
514
|
+
return Feature.remove_from_user(user_id, feature_id, relation: relation, options: options)
|
482
515
|
end
|
483
516
|
|
484
517
|
# Check whether a user has a given feature
|
485
518
|
#
|
486
519
|
# @param feature_id [String] The feature_id of the feature to check whether the user has access to.
|
520
|
+
# @param relation [String] The relation for this feature to user association. The relation must be valid as per the +feature+ object type definition.
|
487
521
|
# @option options [Hash] :context Object containing key-value pairs that specifies the context the warrant should be checked in. (optional)
|
488
|
-
# @option options [Boolean] :consistent_read Boolean flag indicating whether or not to enforce strict consistency for this access check. Defaults to false. (optional)
|
489
522
|
# @option options [Boolean] :debug Boolean flag indicating whether or not to return debug information for this access check. Defaults to false. (optional)
|
490
523
|
#
|
491
|
-
# @
|
524
|
+
# @return [Boolean] whether or not the user has the given feature
|
492
525
|
#
|
493
526
|
# @raise [Warrant::InternalError]
|
494
527
|
# @raise [Warrant::InvalidParameterError]
|
495
528
|
# @raise [Warrant::NotFoundError]
|
496
529
|
# @raise [Warrant::UnauthorizedError]
|
497
|
-
def has_feature?(feature_id,
|
498
|
-
return Warrant.has_feature?(
|
530
|
+
def has_feature?(feature_id, relation: "member", options: {})
|
531
|
+
return Warrant.has_feature?({
|
499
532
|
feature_id: feature_id,
|
533
|
+
relation: relation,
|
500
534
|
subject: {
|
501
535
|
object_type: "user",
|
502
536
|
object_id: user_id
|
503
537
|
},
|
504
|
-
context:
|
505
|
-
|
506
|
-
|
507
|
-
)
|
538
|
+
context: options[:context],
|
539
|
+
debug: options[:debug]
|
540
|
+
}, options)
|
508
541
|
end
|
509
542
|
|
510
543
|
def warrant_object_type
|