Beispiel #1
0
  def post (self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    save_message = 'ok'

    user_email = self.request.get('user-email')

    if (user_email == '' or user_email == None):
      save_message = 'No email address provided.'
    elif (UserManager.get_user_by_email_address(user_email) == None):
      save_message = 'User does not exist.'
    else:

      projects_to_reassign = Project.query().filter(Project.owner==user_email)
      to_update = []

      for project in projects_to_reassign:
        project.owner = UserManager.get_email()
        to_update.append(project)

      if len(to_update) > 0:
        ndb.put_multi(to_update)

      user = UserManager.get_user_by_email_address(user_email)
      user.key.delete()

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json')
    self.response.write(template.render({
      "message": save_message
    }))
Beispiel #2
0
  def get(self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    template = JINJA_ENVIRONMENT.get_template('templates/project/project.html')
    self.response.write(template.render({
      'projects': Project.query(),
      'sign_out_url': UserManager.get_signout_url(),
      'gravatar_url': UserManager.get_gravatar_url(),
      'user_email': UserManager.get_email(),
      'user_is_admin': UserManager.is_admin(),
      'sections': [{
        "name": "Projects"
      }]
    }))
Beispiel #3
0
  def get(self):

    self.response.headers.add_header('Access-Control-Allow-Origin', '*')

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json')

    project_secret = self.request.get('secret')
    project = Project.query().filter(Project.secret==project_secret).get()

    if (project == None):
      self.response.write(template.render({
        "message": "No secret provided"
      }))
      return

    self.response.write(template.render({
      "message": blobstore.create_upload_url('/action/import')
    }))
Beispiel #4
0
    def get(self):

        if UserManager.get_current_user() == None:
            self.redirect('/user-not-found')
            return

        template = JINJA_ENVIRONMENT.get_template(
            'templates/project/project.html')
        self.response.write(
            template.render({
                'projects': Project.query(),
                'sign_out_url': UserManager.get_signout_url(),
                'gravatar_url': UserManager.get_gravatar_url(),
                'user_email': UserManager.get_email(),
                'user_is_admin': UserManager.is_admin(),
                'sections': [{
                    "name": "Projects"
                }]
            }))
Beispiel #5
0
  def post(self):
    key = self.request.get('key')
    data = self.request.get('data')

    if (key == None or data == None):
      return

    # We don't need a try here, because it's already been checked in the
    # import handler by this point.
    data_json = json.loads(data)
    trace = Trace.get_by_id(int(key))

    if 'secret' not in data_json:
      return

    secret = data_json['secret']
    project = Project.query().filter(Project.secret==secret).get()

    if (project == None):
      return

    if (trace == None):
      return

    @ndb.transactional(xg=True)
    def process_trace(project, trace, data_json):

      blob_reader = blobstore.BlobReader(trace.file_key)
      action_details_imported = TraceProcessor().process(project,
          blob_reader.read(), trace, data_json)

      # Tidy up the trace file if needed.
      if trace.delete_trace_after_import:
        blobstore.delete(trace.file_key)
        trace.key.delete()

      return action_details_imported

    action_details_imported = process_trace(project, trace, data_json)
Beispiel #6
0
  def get(self):

    secret = self.request.get('secret')
    labels = self.request.get('labels')
    trace_key = self.request.get('trace')

    if (trace_key == ''):
      self.response.write('no trace key')
      return

    trace = Trace.get_by_id(int(trace_key))

    if (secret == ''):
      self.response.write("no secret")
      return

    if (trace == None):
      self.response.write("no trace")
      return

    project = Project.query().filter(Project.secret==secret).get()

    if (project == None):
      self.response.write("no project")
      return

    labels_list = labels.split(',')
    labels_list_stringified = '"' + '","'.join(labels_list) + '"'

    if (labels == ''):
      labels_list_stringified = ''

    data = '{"secret":"' + secret + '", "labels": [' + labels_list_stringified + ']}'
    data_json = json.loads(data)

    blob_reader = blobstore.BlobReader(trace.file_key)
    TraceProcessor().process(project, blob_reader.read(), trace, data_json)
Beispiel #7
0
class TraceUploadHandler(blobstore_handlers.BlobstoreUploadHandler):

  def get(self):

    self.response.headers.add_header('Access-Control-Allow-Origin', '*')

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json')

    project_secret = self.request.get('secret')
    project = Project.query().filter(Project.secret==project_secret).get()

    if (project == None):
      self.response.write(template.render({
        "message": "No secret provided"
      }))
      return

    self.response.write(template.render({
      "message": blobstore.create_upload_url('/action/import')
    }))


  def post(self):

    # Allow all and sundry to post here, we're going to use the secret as
    # the method of accepting or denying posts.
    self.response.headers.add_header('Access-Control-Allow-Origin', '*')

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json')
    data = self.request.get('data')
    delete_trace_after_import = True
    json_decode_error = False
    chunks_indicator = '=\r?\n'

    # Just see if AppEngine is treating the data like chunked encoding.
    # If the data contains chunks, or seems to, remove it.
    if re.search(chunks_indicator, data):
      data = re.sub(chunks_indicator, '', data)

    # Try and parse the posted JSON
    try:
      data_json = json.loads(data)
    except Exception, e:
      self.response.write(template.render({
        "message": 'Unable to parse data'
      }))
      return

    # Check that there is a secret
    if not 'secret' in data_json:
      self.response.write(template.render({
        "message": "No secret provided"
      }))
      return

    if not 'labels' in data_json:
      data_json['labels'] = ''

    project_secret = data_json['secret']

    if 'delete-trace-after-import' in data_json:
      delete_trace_after_import = (
          data_json['delete-trace-after-import'] == 'true')

    uploads = self.get_uploads()

    if (len(uploads) == 0):
      self.response.write(template.render({
        "message": "No upload found."
      }))
      return

    upload = uploads[0]
    blob_info = blobstore.BlobInfo(upload.key())

    trace = Trace(
      file_key=upload.key(),
      date=blob_info.creation,
      filename=blob_info.filename,
      processed=False,
      delete_trace_after_import=delete_trace_after_import
    )

    project = Project.query().filter(Project.secret==project_secret).get()

    if project == None:
      self.response.write(template.render({
        "message": "No project found with secret %s." % project_secret
      }))
      return

    log = Log(
      parent=project.key,
      filename=blob_info.filename,
      date=(datetime.today() - timedelta(0, 1)),
      status='File scheduled for import.',
      records_imported=-1
    )
    log.put()

    # Save.
    trace.put()

    # Schedule the processing of the trace.
    taskqueue.add(url='/process', params={
      'key': trace.key.integer_id(),
      'data': data
    })

    self.response.write(template.render({
      "message": "ok"
    }))