Beispiel #1
0
  def post(self):
    if len(self.request.params) > 0:
      if helpers.authorized(self.request.params['UUID'], self.request.params['ATO'], self.request.params['action']):
        # collect the data from the record
        user_json = simplejson.loads(self.request.body)

        # create a user
        user = helpers.apply_json_to_model_instance(User(), user_json)
        # save the new user
        user.put()

        guid = user.key().id_or_name()
        new_url = "/tasks-server/user/%s" % guid
        user_json["id"] = guid

        self.response.set_status(201, "User created")
        self.response.headers['Location'] = new_url
        self.response.headers['Content-Type'] = 'text/json'
        self.response.out.write(simplejson.dumps(user_json))
      else:
        self.response.set_status(401, "Not Authorized")
    else:
      user_json = simplejson.loads(self.request.body)
      user = helpers.apply_json_to_model_instance(User(), user_json)
      user.authToken = helpers.generateAuthToken()
      user.put()
      guid = user.key().id_or_name()
      new_url = "/tasks-server/user/%s" % guid
      user_json["id"] = guid
      self.response.set_status(201, "User created")
      self.response.headers['Location'] = new_url
      self.response.headers['Content-Type'] = 'text/json'
      self.response.out.write(simplejson.dumps(user_json))
Beispiel #2
0
 def post(self):
   wantsNotifications = {"true": True, "false": False}.get(self.request.params['notify'].lower())
   # collect the data from the record
   task_json = simplejson.loads(self.request.body)
   logging.info(self.request.body)
   # if the user is a guest the project must be unallocated
   currentUserId = self.request.params['UUID']
   cukey = db.Key.from_path('User', int(currentUserId))
   user = db.get(cukey)
   if str(user.role) != '_Guest' or (task_json.has_key('projectId') == False or task_json['projectId'] == None):
     # create a new task with the passed in json
     task = helpers.apply_json_to_model_instance(Task(),task_json)
     # save task
     task.put()
     guid = task.key().id_or_name()
     # Push notification email on the queue if the task has some sort of status, etc..
     if notification.should_notify(currentUserId,task,"createTask", wantsNotifications):
       taskqueue.add(url='/mailer', params={'taskId': int(guid), 'currentUUID': self.request.params['UUID'], 'action': "createTask", 'name': "New Task"})
     new_url = "/tasks-server/task/%s" % guid
     task_json["id"] = guid
     self.response.set_status(201, "Task created")
     self.response.headers['Location'] = new_url
     self.response.headers['Content-Type'] = 'text/json'
     self.response.out.write(simplejson.dumps(task_json))
   else:
     self.response.set_status(401, "Not Authorized")
Beispiel #3
0
  def put(self, guid):
    # find the matching user
    key = db.Key.from_path('User', int(guid))
    user = db.get(key)
    if not user == None:

      # collect the data from the record
      user_json = simplejson.loads(self.request.body)
      # The following keeps Guests and Developers and Testers from being able
      # to change their role.
      currentUserId = self.request.params['UUID']
      cukey = db.Key.from_path('User', int(currentUserId))
      cuser = db.get(cukey)
      if str(user.role) != user_json['role'] and str(cuser.role) != "_Manager":
        user_json['role'] = str(user.role)
        self.response.set_status(401, "Not Authorized")
      # update the record
      user = helpers.apply_json_to_model_instance(user, user_json)
      # save the record
      user.put()
      # return the same record...
      self.response.headers['Content-Type'] = 'application/json'
      self.response.out.write(simplejson.dumps(user_json))
    else:
      self.response.set_status(404, "User not found")
 def post(self):
   if helpers.authorized(self.request.params['UUID'], self.request.params['authToken'], self.request.params['action']):
     wantsNotifications = {"true": True, "false": False}.get(self.request.params['notify'].lower())
     task_json = simplejson.loads(self.request.body)
     logging.info(self.request.body)
     task = helpers.apply_json_to_model_instance(Task(),task_json)
     # ensure Guest-created tasks are unallocated
     currentUserId = self.request.params['UUID']
     cukey = db.Key.from_path('User', int(currentUserId))
     user = db.get(cukey)
     if str(user.role) == '_Guest' and task_json.has_key('projectId') == True and task_json['projectId'] != None:
       task.projectId = None
     task.put()
     guid = task.key().id_or_name()
     # Push notification email on the queue if the task has some sort of status, etc..
     if notification.should_notify(currentUserId, task, wantsNotifications):
       taskqueue.add(url='/mailer', params={'taskId': int(guid), 'currentUUID': self.request.params['UUID'], 'action': "createTask", 'name': "New Task"})
     new_url = "/tasks-server/task/%s" % guid
     task_json["id"] = guid
     self.response.set_status(201, "Task created")
     self.response.headers['Location'] = new_url
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(simplejson.dumps(task_json))
   else:
     helpers.report_unauthorized_access(self.response)
 def put(self, guid):
   if helpers.authorized(self.request.params['UUID'], self.request.params['authToken'], self.request.params['action']):
     key = db.Key.from_path('User', int(guid))
     user = db.get(key)
     if not user == None:
       user_json = simplejson.loads(self.request.body)
       # if user password hasn't been modified by GUI keep it the same as what is in the database
       if user_json['password'] == "password":
         user_json['password'] = user.password
       status = user_json.get('status')
       being_deleted = (status != None and status == 'deleted')
       if being_deleted or helpers.is_login_name_valid(user_json['loginName'], user):
         # Prevent non-Managers from changing their role
         currentUserId = self.request.params['UUID']
         cukey = db.Key.from_path('User', int(currentUserId))
         cuser = db.get(cukey)
         if str(user.role) != user_json['role'] and str(cuser.role) != "_Manager":
           user_json['role'] = str(user.role)
           helpers.report_unauthorized_access(self.response)
         user = helpers.apply_json_to_model_instance(user, user_json)
         user.put()
         if user.password != None and len(user.password) != 0:
           user_json['password'] = "******"
         self.response.headers['Content-Type'] = 'application/json'
         self.response.out.write(simplejson.dumps(user_json))
       else:
         helpers.report_invalid_login_name(self.response)
     else:
       helpers.report_missing_record(self.response)
   else:
     helpers.report_unauthorized_access(self.response)
  def post(self):

    user_json = simplejson.loads(self.request.body)
    user = helpers.apply_json_to_model_instance(User(), user_json)
    user.authToken = helpers.generateAuthToken()
    user.put()
    guid = user.key().id_or_name()
    new_url = "/gamp-server/user/%s" % guid
    user_json["id"] = guid
    self.response.set_status(201, "User created")
    self.response.headers['Location'] = new_url
    self.response.headers['Content-Type'] = 'text/json'
    self.response.out.write(simplejson.dumps(user_json))
 def put(self, guid):
   if helpers.authorized(self.request.params['UUID'], self.request.params['authToken'], self.request.params['action']):
     key = db.Key.from_path('Comment', int(guid))
     comment = db.get(key)
     if not comment == None:
       comment_json = simplejson.loads(self.request.body)
       comment = helpers.apply_json_to_model_instance(comment, comment_json)
       comment.put()
       self.response.headers['Content-Type'] = 'application/json'
       self.response.out.write(simplejson.dumps(comment_json))
     else:
       helpers.report_missing_record(self.response)
   else:
     helpers.report_unauthorized_access(self.response)
 def post(self):
   if helpers.authorized(self.request.params['UUID'], self.request.params['authToken'], self.request.params['action']):
     comment_json = simplejson.loads(self.request.body)
     comment = helpers.apply_json_to_model_instance(Comment(), comment_json)
     comment.save()
     guid = comment.key().id_or_name()
     new_url = "/tasks-server/comment/%s" % guid
     comment_json["id"] = guid
     self.response.set_status(201, "Comment created")
     self.response.headers['Location'] = new_url
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(simplejson.dumps(comment_json))
   else:
     helpers.report_unauthorized_access(self.response)
 def post(self):
   if helpers.authorized(self.request.params['UUID'], self.request.params['authToken'], self.request.params['action']):
     watch_json = simplejson.loads(self.request.body)
     watch = helpers.apply_json_to_model_instance(Watch(), watch_json)
     watch.put()
     guid = watch.key().id_or_name()
     new_url = "/tasks-server/watch/%s" % guid
     watch_json["id"] = guid
     self.response.set_status(201, "Watch created")
     self.response.headers['Location'] = new_url
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(simplejson.dumps(watch_json))
   else:
     helpers.report_unauthorized_access(self.response)
Beispiel #10
0
  def put(self, guid):
    # find the matching watch
    key = db.Key.from_path('Watch', int(guid))
    watch = db.get(key)
    if not watch == None:

      # collect the data from the record
      watch_json = simplejson.loads(self.request.body)
      # update the record
      watch = helpers.apply_json_to_model_instance(watch, watch_json)
      # save the record
      watch.put()
      # return the same record...
      self.response.headers['Content-Type'] = 'application/json'
      self.response.out.write(simplejson.dumps(watch_json))
    else:
      self.response.set_status(404, "Watch not found")
Beispiel #11
0
  def post(self):
    # collect the data from the record
    watch_json = simplejson.loads(self.request.body)
    #logging.info(self.request.body)
    # create a watch
    watch = helpers.apply_json_to_model_instance(Watch(), watch_json)
    # save the new watch
    watch.put()

    guid = watch.key().id_or_name()
    new_url = "/tasks-server/watch/%s" % guid
    watch_json["id"] = guid

    self.response.set_status(201, "Watch created")
    self.response.headers['Location'] = new_url
    self.response.headers['Content-Type'] = 'text/json'
    self.response.out.write(simplejson.dumps(watch_json))
Beispiel #12
0
  def post(self):
    if helpers.authorized(self.request.params['UUID'], self.request.params['ATO'], self.request.params['action']):
      # collect the data from the record
      project_json = simplejson.loads(self.request.body)

      # create a new project
      project = helpers.apply_json_to_model_instance(Project(), project_json)
      # save project
      project.save()

      guid = project.key().id_or_name()
      new_url = "/tasks-server/project/%s" % guid
      project_json["id"] = guid

      self.response.set_status(201, "Project created")
      self.response.headers['Location'] = new_url
      self.response.headers['Content-Type'] = 'text/json'
      self.response.out.write(simplejson.dumps(project_json))
    else:
      self.response.set_status(401, "Not Authorized")
Beispiel #13
0
  def put(self, guid):
    """Update the project with the given id"""
    if helpers.authorized(self.request.params['UUID'], self.request.params['ATO'], self.request.params['action']):
      key = db.Key.from_path('Project', int(guid))
      project = db.get(key)
      if not project == None:
        # collect the json from the request
        project_json = simplejson.loads(self.request.body)
        # update the project record
        project = helpers.apply_json_to_model_instance(project, project_json)
        # save the updated data
        project.put()

        # return the same record...
        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(simplejson.dumps(project_json))

      else:
        self.response.set_status(404, "Project not found")
    else:
      self.response.set_status(401, "Not Authorized")
Beispiel #14
0
 def put(self, guid):
   """Update the task with the given id"""
   key = db.Key.from_path('Task', int(guid))
   task = db.get(key)
   if task != None:
     # cache current values before updates
     taskName = task.name
     taskType = task.type
     taskPriority = task.priority
     taskStatus = task.developmentStatus
     taskValidation = task.validation
     taskSubmitterId = task.submitterId
     taskAssigneeId = task.assigneeId
     taskEffort = task.effort
     taskProjectId = task.projectId
     taskDescription = task.description
     # collect the json from the request
     task_json = simplejson.loads(self.request.body)
     # if the user is a guest the project must be unallocated
     wantsNotifications = {"true": True, "false": False}.get(self.request.params['notify'].lower())
     currentUserId = self.request.params['UUID']
     cukey = db.Key.from_path('User', int(currentUserId))
     user = db.get(cukey)
     if str(user.role) != '_Guest' or (task_json.has_key('projectId') == False or task_json['projectId'] == None):
       # update the project record
       task = helpers.apply_json_to_model_instance(task, task_json)
       # save the updated data
       task.put()
       # Push notification email on the queue if we need to notify
       if notification.should_notify(currentUserId,task,"updateTask",wantsNotifications):
         taskqueue.add(url='/mailer', params={'taskId': int(guid), 'currentUUID': self.request.params['UUID'], 'action': "updateTask", 'name': taskName, 'type': taskType, 'priority': taskPriority, 'status': taskStatus, 'validation': taskValidation, 'submitterId': taskSubmitterId, 'assigneeId': taskAssigneeId, 'effort': taskEffort, 'projectId': taskProjectId, 'description': taskDescription})
       # return the same record...
       self.response.headers['Content-Type'] = 'application/json'
       self.response.out.write(simplejson.dumps(task_json))
     else:
       self.response.set_status(401, "Not Authorized")
   else:
     self.response.set_status(404, "Task not found")
 def put(self, guid):
   if helpers.authorized(self.request.params['UUID'], self.request.params['authToken'], self.request.params['action']):
     key = db.Key.from_path('Task', int(guid))
     task = db.get(key)
     if task != None:
       # cache current values before updates
       taskName = task.name
       taskType = task.type
       taskPriority = task.priority
       taskStatus = task.developmentStatus
       taskValidation = task.validation
       taskSubmitterId = task.submitterId
       taskAssigneeId = task.assigneeId
       taskEffort = task.effort
       taskProjectId = task.projectId
       taskDescription = task.description
       task_json = simplejson.loads(self.request.body)
       wantsNotifications = {"true": True, "false": False}.get(self.request.params['notify'].lower())
       task = helpers.apply_json_to_model_instance(task, task_json)
       # ensure Guest-created tasks are unallocated
       currentUserId = self.request.params['UUID']
       cukey = db.Key.from_path('User', int(currentUserId))
       user = db.get(cukey)
       if str(user.role) == '_Guest' and task_json.has_key('projectId') == True and task_json['projectId'] != None:
         taskProjectId = task.projectId = None
       task.put()
       # Push notification email on the queue if we need to notify
       action = "deleteTask" if task.status == "deleted" else "updateTask"
       if notification.should_notify(currentUserId, task, wantsNotifications):
         taskqueue.add(url='/mailer', params={'taskId': int(guid), 'currentUUID': self.request.params['UUID'], 'action': action, 'name': taskName, 'type': taskType, 'priority': taskPriority, 'status': taskStatus, 'validation': taskValidation, 'submitterId': taskSubmitterId, 'assigneeId': taskAssigneeId, 'effort': taskEffort, 'projectId': taskProjectId, 'description': taskDescription})
       self.response.headers['Content-Type'] = 'application/json'
       self.response.out.write(simplejson.dumps(task_json))
     else:
       helpers.report_missing_record(self.response)
   else:
     helpers.report_unauthorized_access(self.response)