Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend restapi to support scaled egress tests and directory import - … #427

Merged
merged 1 commit into from
Aug 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions server/restapi/restapi.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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': 'user1@user1.com',
'name': 'user1',
'pass': 'abc123' },
{'email': 'user2@user2.com',
'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