Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
fix(symphony): use new pod/v2/user endpoint
Browse files Browse the repository at this point in the history
pod/v1/admin/user requires the bot account to have admin privileges while pod/v2/user does not
  • Loading branch information
jonfreedman committed Sep 15, 2016
1 parent b6421e3 commit 1a5b6f8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 36 deletions.
10 changes: 5 additions & 5 deletions src/adapter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class SymphonyAdapter extends Adapter
@robot.userId = response.userId
@symphony.getUser(response.userId)
.then (response) =>
@robot.displayName = response.userAttributes?.displayName
@robot.logger.info "Connected as #{response.userAttributes?.displayName} [#{response.userSystemInfo?.status}]"
@robot.displayName = response.displayName
@robot.logger.info "Connected as #{response.displayName}"
.fail (err) =>
@robot.emit 'error', new Error("Unable to resolve identity: #{err}")
hourlyRefresh = memoize @_getUser, {maxAge: 3600000, length: 2}
Expand Down Expand Up @@ -131,9 +131,9 @@ class SymphonyAdapter extends Adapter
.then (response) =>
# record basic user details in hubot's brain, setting the room causes the brain to update each time we're seen in a new conversation
existing = @robot.brain.userForId(userId)
existing['name'] = response.userAttributes?.userName
existing['displayName'] = response.userAttributes?.displayName
existing['emailAddress'] = response.userAttributes?.emailAddress
existing['name'] = response.userName
existing['displayName'] = response.displayName
existing['emailAddress'] = response.emailAddress
existing['room'] = streamId
@robot.brain.userForId(userId, existing)
existing
Expand Down
2 changes: 1 addition & 1 deletion src/diagnostic.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ userId = symphony.whoAmI()
logger.info "UserId: #{response.userId}"
symphony.getUser(response.userId)
.then (response) =>
logger.info "My name is #{response.userAttributes?.displayName} [#{response.userAttributes?.emailAddress}] and I'm #{response.userSystemInfo?.status}"
logger.info "My name is #{response.displayName} [#{response.emailAddress}]"
.fail (err) =>
logger.error "Failed to fetch userId: #{err}"
.done
Expand Down
8 changes: 4 additions & 4 deletions src/symphony.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ class Symphony
@_httpPodGet('/pod/v1/sessioninfo', true)

getUser: (userId) =>
@_httpPodGet('/pod/v1/admin/user/' + userId, true)
@_httpPodGet("/pod/v2/user?uid=#{userId}&local=true", true)

sendMessage: (streamId, message, format) =>
body = {
message: message
format: format
}
@_httpAgentPost('/agent/v2/stream/' + streamId + '/message/create', true, body)
@_httpAgentPost("/agent/v2/stream/#{streamId}/message/create", true, body)

getMessages: (streamId, since, limit = 100) =>
@_httpAgentGet('/agent/v2/stream/' + streamId + '/message', true)
@_httpAgentGet("/agent/v2/stream/#{streamId}/message", true)

createDatafeed: =>
@_httpAgentPost('/agent/v1/datafeed/create', true)

readDatafeed: (datafeedId) =>
@_httpAgentGet('/agent/v2/datafeed/' + datafeedId + '/read', false)
@_httpAgentGet("/agent/v2/datafeed/#{datafeedId}/read", false)

_httpPodGet: (path, failUnlessHttp200) =>
@sessionAuth().then (value) =>
Expand Down
42 changes: 17 additions & 25 deletions test/nock-server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,23 @@ class NockServer extends EventEmitter
.reply(200, {
userId: @botUserId
})
.get('/pod/v1/admin/user/' + @realUserId)
.get("/pod/v2/user?uid=#{@realUserId}&local=true")
.reply(200, {
userAttributes: {
emailAddress: 'johndoe@symphony.com'
firstName: 'John'
lastName: 'Doe'
userName: 'johndoe'
displayName: 'John Doe'
}
userSystemInfo: {
id: @realUserId
}
id: @realUserId
emailAddress: 'johndoe@symphony.com'
firstName: 'John'
lastName: 'Doe'
userName: 'johndoe'
displayName: 'John Doe'
})
.get('/pod/v1/admin/user/' + @botUserId)
.get("/pod/v2/user?uid=#{@botUserId}&local=true")
.reply(200, {
userAttributes: {
emailAddress: 'mozart@symphony.com'
firstName: 'Wolfgang Amadeus'
lastName: 'Mozart'
userName: 'mozart'
displayName: 'Mozart'
}
userSystemInfo: {
id: @realUserId
}
id: @realUserId
emailAddress: 'mozart@symphony.com'
firstName: 'Wolfgang Amadeus'
lastName: 'Mozart'
userName: 'mozart'
displayName: 'Mozart'
})

@agentScope = nock(@host)
Expand All @@ -116,7 +108,7 @@ class NockServer extends EventEmitter
.matchHeader('keyManagerToken', 'KEY_MANAGER_TOKEN')
.post('/agent/v1/util/echo')
.reply(200, (uri, requestBody) -> requestBody)
.post('/agent/v2/stream/' + @streamId + '/message/create')
.post("/agent/v2/stream/#{@streamId}/message/create")
.reply(200, (uri, requestBody) =>
message = {
id: uuid.v1()
Expand All @@ -130,7 +122,7 @@ class NockServer extends EventEmitter
@_receiveMessage message
message
)
.get('/agent/v2/stream/' + @streamId + '/message')
.get("/agent/v2/stream/#{@streamId}/message")
.reply(200, (uri, requestBody) => JSON.stringify(@messages))
.post('/agent/v1/datafeed/create')
.reply (uri, requestBody) =>
Expand All @@ -140,7 +132,7 @@ class NockServer extends EventEmitter
[200, JSON.stringify {
id: @datafeedId
}]
.get('/agent/v2/datafeed/' + @datafeedId + '/read')
.get("/agent/v2/datafeed/#{@datafeedId}/read")
.reply (uri, requestBody) =>
if @datafeedReadHttp400Count-- > 0
[400, null]
Expand Down
2 changes: 1 addition & 1 deletion test/symphony-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe 'REST API test suite', () ->
it 'getUser should expose user details', () ->
symphony.getUser(nock.realUserId)
.then (response) ->
assert.equal('johndoe@symphony.com', response.userAttributes.emailAddress)
assert.equal('johndoe@symphony.com', response.emailAddress)
.fail (error) ->
assert.fail(0, 1,"Failed with error #{error}")

Expand Down

0 comments on commit 1a5b6f8

Please sign in to comment.