Exemplo n.º 1
0
class AppHandler(object):
    '''
  Handler for retrieving information about a specific app. Also
  allows app information to be updated, or for an app to be deleted. Only
  the creator can access and modify the app information.
  '''
    @public_api_auth
    def GET(self, app_id, auth_user=None, auth_app_id=None):
        '''
    Return a JSON object containing information about the specific app.
    '''
        try:
            app_id = ObjectId(app_id)
        except Exception, e:
            logging.error(e)
            return error_response(400, 'Not a valid app id')

        try:
            app = App.collection.find_one({'_id': app_id, 'deleted': False})
            if not app:
                message = 'App does not exist'
                logging.warn(message)
                return error_response(404, message)
            if not app.user_can_update(auth_user):
                message = 'App cannot be accessed by the user'
                logging.warn(message)
                return error_response(403, message)
            formatted_dict = app.formatted_dict()
            return encode_json(formatted_dict)
        except Exception, e:
            logging.error(e)
            return error_response(500, 'Server Error')
Exemplo n.º 2
0
 def GET(self, app_id, auth_user=None, auth_app_id=None):
   '''
   Return a JSON object containing information about the specific app.
   '''
   try:
     app_id = ObjectId(app_id)
   except Exception, e:
     logging.error(e)
     return error_response(400, 'Not a valid app id')
Exemplo n.º 3
0
 def DELETE(self, app_id, auth_user=None, auth_app_id=None):
   '''
   Delete the given app, and returns a JSON object containing a
   success notification.
   '''
   try:
     app_id = ObjectId(app_id)
   except Exception, e:
     return error_response(400, 'Not a valid app id')
Exemplo n.º 4
0
 def GET(self, app_id, auth_user=None, auth_app_id=None):
     '''
 Return a JSON object containing information about the specific app.
 '''
     try:
         app_id = ObjectId(app_id)
     except Exception, e:
         logging.error(e)
         return error_response(400, 'Not a valid app id')
Exemplo n.º 5
0
 def DELETE(self, app_id, auth_user=None, auth_app_id=None):
     '''
 Delete the given app, and returns a JSON object containing a
 success notification.
 '''
     try:
         app_id = ObjectId(app_id)
     except Exception, e:
         return error_response(400, 'Not a valid app id')
Exemplo n.º 6
0
 def PUT(self, app_id, auth_user=None, auth_app_id=None):
   '''
   Update the given app, and returns a JSON object containing the new
   timestamp.
   '''
   try:
     app_id = ObjectId(app_id)
   except Exception, e:
     logging.error(e)
     return error_response(400, 'Not a valid app id')
Exemplo n.º 7
0
 def PUT(self, app_id, auth_user=None, auth_app_id=None):
     '''
 Update the given app, and returns a JSON object containing the new
 timestamp.
 '''
     try:
         app_id = ObjectId(app_id)
     except Exception, e:
         logging.error(e)
         return error_response(400, 'Not a valid app id')
Exemplo n.º 8
0
 def GET(self, auth_user=None, auth_app_id=None):
     '''
 Return JSON array of basic app info. Only returns apps
 created by the authenticated user.
 '''
     try:
         spec = {'deleted': False, 'creator': auth_user._id}
         apps = App.collection.find(spec)
         formatted_apps = [app.formatted_dict() for app in apps]
         return encode_json(formatted_apps)
     except Exception, e:
         logging.error(e)
         return error_response(500)
Exemplo n.º 9
0
 def POST(self, auth_user=None, auth_app_id=None):
   '''
   Create a new app and return a JSON object containing the new
   app information.
   '''
   params = web.input(data=None)
   try:
     if params.data:
       data = decode_json(params.data)
     else:
       data = decode_json(web.ctx.data)
     App.validate(data)
   except Exception, e:
     logging.error(e)
     return error_response(400, 'Data did not pass validation')
Exemplo n.º 10
0
 def POST(self, auth_user=None, auth_app_id=None):
     '''
 Create a new app and return a JSON object containing the new
 app information.
 '''
     params = web.input(data=None)
     try:
         if params.data:
             data = decode_json(params.data)
         else:
             data = decode_json(web.ctx.data)
         App.validate(data)
     except Exception, e:
         logging.error(e)
         return error_response(400, 'Data did not pass validation')
Exemplo n.º 11
0
 def GET(self, auth_user=None, auth_app_id=None):
   '''
   Return JSON array of basic app info. Only returns apps
   created by the authenticated user.
   '''
   try:
     spec = {
       'deleted': False,
       'creator': auth_user._id
     }
     apps = App.collection.find(spec)
     formatted_apps = [app.formatted_dict() for app in apps]
     return encode_json(formatted_apps)
   except Exception, e:
     logging.error(e)
     return error_response(500)
Exemplo n.º 12
0
      else:
        data = decode_json(web.ctx.data)
      App.validate(data)
    except Exception, e:
      logging.error(e)
      return error_response(400, 'Data did not pass validation')

    try:
      app = App(data)
      app.set_creator(auth_user)
      app.save()
      formatted_dict = app.formatted_dict()
      return encode_json(formatted_dict)
    except Exception, e:
      logging.error(e)
      return error_response(500)


class AppHandler(object):
  '''
  Handler for retrieving information about a specific app. Also
  allows app information to be updated, or for an app to be deleted. Only
  the creator can access and modify the app information.
  '''

  @public_api_auth
  def GET(self, app_id, auth_user=None, auth_app_id=None):
    '''
    Return a JSON object containing information about the specific app.
    '''
    try:
Exemplo n.º 13
0
            else:
                data = decode_json(web.ctx.data)
            App.validate(data)
        except Exception, e:
            logging.error(e)
            return error_response(400, 'Data did not pass validation')

        try:
            app = App(data)
            app.set_creator(auth_user)
            app.save()
            formatted_dict = app.formatted_dict()
            return encode_json(formatted_dict)
        except Exception, e:
            logging.error(e)
            return error_response(500)


class AppHandler(object):
    '''
  Handler for retrieving information about a specific app. Also
  allows app information to be updated, or for an app to be deleted. Only
  the creator can access and modify the app information.
  '''
    @public_api_auth
    def GET(self, app_id, auth_user=None, auth_app_id=None):
        '''
    Return a JSON object containing information about the specific app.
    '''
        try:
            app_id = ObjectId(app_id)