Skip to content

Commit

Permalink
exposed action.responded to authorize() function
Browse files Browse the repository at this point in the history
responded was a private variable used for determining if the authorize()
function had called action.accept() or action.reject().

responded has been made a public attribute of the action object so the
authorize function can check to see whether it has called accept() or
reject(). This is useful for complex control flows.
  • Loading branch information
dgreisen committed Oct 20, 2012
1 parent 7b835a1 commit a97be9d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/server/useragent.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ module.exports = (model, options) ->
when 'delete' then 'delete'
else throw new Error "Invalid action name #{name}"

responded = false
action.responded = false
action.reject = ->
throw new Error 'Multiple accept/reject calls made' if responded
responded = true
throw new Error 'Multiple accept/reject calls made' if @responded
@responded = true
userCallback 'forbidden', null
action.accept = ->
throw new Error 'Multiple accept/reject calls made' if responded
responded = true
throw new Error 'Multiple accept/reject calls made' if @responded
@responded = true
acceptCallback()

auth this, action
Expand Down
18 changes: 18 additions & 0 deletions test/client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,24 @@ genTests = (client) -> testCase
@model.applyOp @name, {op:[{i:'dD', p:3}], v:1, meta:{}}, =>
@model.getSnapshot @name, e

'If operation is rejected, action.responded == true': (test) ->
@auth = (client, action) ->
test.strictEqual action.responded, false
action.reject()
test.strictEqual action.responded, true
test.done()

client.open @name, 'text', "http://localhost:#{@port}/sjs", (error, doc) =>

'If operation is accepted, action.responded == true': (test) ->
@auth = (client, action) ->
test.strictEqual action.responded, false
action.accept()
test.strictEqual action.responded, true
test.done()

client.open @name, 'text', "http://localhost:#{@port}/sjs", (error, doc) =>

'Text API is advertised': (test) ->
@c.open @name, 'text', (error, doc) ->
test.strictEqual doc.provides?.text, true
Expand Down

0 comments on commit a97be9d

Please sign in to comment.