-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #427 from Sing-Li/restapi-test-and-admin-automatio…
…n-support Extend restapi to support scaled egress tests and directory import - …
- Loading branch information
Showing
1 changed file
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,126 @@ Api.addRoute 'rooms/:id/send', authRequired: true, | |
Meteor.call('sendMessage', {msg: this.bodyParams.msg, rid: @urlParams.id} ) | ||
status: 'success' #need to handle error | ||
|
||
|
||
# validate an array of users | ||
Api.testapiValidateUsers = (users) -> | ||
for user, i in users | ||
if user.name? | ||
if user.email? | ||
if user.pass? | ||
if /^[0-9a-z-_]+$/i.test user.name | ||
if /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]+\b/i.test user.email | ||
continue | ||
throw new Meteor.Error 'invalid-user-record', "[restapi] bulk/register -> record #" + i + " is invalid" | ||
return | ||
|
||
|
||
### | ||
@api {post} /bulk/register Register multiple users based on an input array. | ||
@apiName register | ||
@apiGroup TestAndAdminAutomation | ||
@apiVersion 0.0.1 | ||
@apiDescription Caller must have 'testagent' or 'adminautomation' role. | ||
NOTE: remove room is NOT recommended; use Meteor.reset() to clear db and re-seed instead | ||
@apiParam {json} rooms An array of users in the body of the POST. | ||
@apiParamExample {json} POST Request Body example: | ||
{ | ||
'users':[ {'email': '[email protected]', | ||
'name': 'user1', | ||
'pass': 'abc123' }, | ||
{'email': '[email protected]', | ||
'name': 'user2', | ||
'pass': 'abc123'}, | ||
... | ||
] | ||
} | ||
@apiSuccess {json} ids An array of IDs of the registered users. | ||
@apiSuccessExample {json} Success-Response: | ||
HTTP/1.1 200 OK | ||
{ | ||
'ids':[ {'uid': 'uid_1'}, | ||
{'uid': 'uid_2'}, | ||
... | ||
] | ||
} | ||
### | ||
Api.addRoute 'bulk/register', authRequired: true, | ||
post: | ||
roleRequired: ['testagent', 'adminautomation'] | ||
action: -> | ||
try | ||
Api.testapiValidateUsers @bodyParams.users | ||
this.response.setTimeout (500 * @bodyParams.users.length) | ||
ids = [] | ||
endCount = @bodyParams.users.length - 1 | ||
for incoming, i in @bodyParams.users | ||
ids[i] = Meteor.call 'registerUser', incoming | ||
Meteor.runAsUser ids[i].uid, () => | ||
Meteor.call 'setUsername', incoming.name | ||
|
||
status: 'success', ids: ids | ||
catch e | ||
statusCode: 400 # bad request or other errors | ||
body: status: 'fail', message: e.name + ' :: ' + e.message | ||
|
||
|
||
|
||
# validate an array of rooms | ||
Api.testapiValidateRooms = (rooms) -> | ||
for room, i in rooms | ||
if room.name? | ||
if room.members? | ||
if room.members.length > 1 | ||
if /^[0-9a-z-_]+$/i.test room.name | ||
continue | ||
throw new Meteor.Error 'invalid-room-record', "[restapi] bulk/createRoom -> record #" + i + " is invalid" | ||
return | ||
|
||
|
||
### | ||
@api {post} /bulk/createRoom Create multiple rooms based on an input array. | ||
@apiName createRoom | ||
@apiGroup TestAndAdminAutomation | ||
@apiVersion 0.0.1 | ||
@apiParam {json} rooms An array of rooms in the body of the POST. | ||
@apiParamExample {json} POST Request Body example: | ||
{ | ||
'rooms':[ {'name': 'room1', | ||
'members': ['user1', 'user2'] | ||
}, | ||
{'name': 'room2', | ||
'members': ['user1', 'user2', 'user3'] | ||
} | ||
... | ||
] | ||
} | ||
@apiDescription Caller must have 'testagent' or 'adminautomation' role. | ||
NOTE: remove room is NOT recommended; use Meteor.reset() to clear db and re-seed instead | ||
@apiSuccess {json} ids An array of ids of the rooms created. | ||
@apiSuccessExample {json} Success-Response: | ||
HTTP/1.1 200 OK | ||
{ | ||
'ids':[ {'rid': 'rid_1'}, | ||
{'rid': 'rid_2'}, | ||
... | ||
] | ||
} | ||
### | ||
Api.addRoute 'bulk/createRoom', authRequired: true, | ||
post: | ||
roleRequired: ['testagent', 'adminautomation'] | ||
action: -> | ||
try | ||
this.response.setTimeout (1000 * @bodyParams.rooms.length) | ||
Api.testapiValidateRooms @bodyParams.rooms | ||
ids = [] | ||
Meteor.runAsUser this.userId, () => | ||
(ids[i] = Meteor.call 'createChannel', incoming.name, incoming.members) for incoming,i in @bodyParams.rooms | ||
status: 'success', ids: ids # need to handle error | ||
catch e | ||
statusCode: 400 # bad request or other errors | ||
body: status: 'fail', message: e.name + ' :: ' + e.message | ||
|
||
|
||
|