     else
       return resp.send 200, dataset
 
-app.get '/api/:user/datasets/:id/views?', checkThisIsMyDataHub, (req, resp) ->
+listViews = (req, resp) ->
   console.log "GET /api/#{req.params.user}/datasets/#{req.params.id}/views"
   Dataset.findOneById req.params.id, req.user.effective.shortName, (err, dataset) ->
     if err?

          return resp.send 500, error: 'Error trying to update status'
        return resp.send 200, status: 'ok'


app.get '/api/:user/subscription/:plan/sign/?', (req, resp) ->
  signedSubscription = recurlySign.sign
    subscription:
      plan_code: req.params.plan
  resp.send 200, signedSubscription

app.post '/api/:user/subscription/verify/?', (req, resp) ->
  Subscription.getRecurlyResult req.body.recurly_token, (err, result) ->
    if err?
      statusCode = err.statusCode or 500

        req.session.save()
        resp.send 201, success: "Verified and upgraded"

# Allow set-password, signup, docs, etc, to be visited by anons
# Note: these are NOT regular expressions!!
app.get '/set-password/:token/?', renderClientApp
app.get '/subscribe/?*', renderClientApp
app.get '/pricing/?*', renderClientApp
app.get '/signup/?*', renderClientApp
app.get '/help/?*', renderClientApp
app.get '/terms/?*', renderClientApp
app.get '/', renderClientApp

# Switch is protected by a specific function.
app.get '/switch/:username/?', checkSwitchUserRights, switchUser

app.post "/login", login

# Set a password using a token.
# TODO: :token should be in POST body
app.post '/api/token/:token/?', setPassword

app.post '/api/user/?', addUser

# :todo: Add IP address check (at the moment, anyone running an identd
# can post to anyone's status).
app.post '/api/status/?', checkIdent, postStatus

app.get '/api/:user/subscription/:plan/sign/?', signPlan
app.post '/api/:user/subscription/verify/?', verifyRecurly

############ AUTHENTICATED ############

logout = (req, resp) ->
  req.logout()
  resp.redirect '/'

listTools = (req, resp) ->
  Tool.findForUser req.user.effective.shortName, (err, tools) ->
    console.log "API about to return"
    resp.send 200, tools

postTool = (req, resp) ->
  body = req.body
  Tool.findOneByName body.name, (err, tool) ->
    isNew = not tool?
