Ejemplo n.º 1
0
 def delete(self, guid):
   """Delete the task with the given id"""
   if helpers.authorized(self.request.params['UUID'], self.request.params['ATO'], self.request.params['action']):
     # search for the Project and delete if found
     key = db.Key.from_path('Task', int(guid))
     task = db.get(key)
     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 not 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
       # Push notification email on the queue if we need to notify
       if notification.should_notify(currentUserId,task,"deleteTask",wantsNotifications):
         taskqueue.add(url='/mailer', params={'taskId': int(guid), 'currentUUID': self.request.params['UUID'], 'action': "deleteTask", 'name': taskName, 'type': taskType, 'priority': taskPriority, 'status': taskStatus, 'validation': taskValidation, 'submitterId': taskSubmitterId, 'assigneeId': taskAssigneeId, 'effort': taskEffort, 'projectId': taskProjectId, 'description': taskDescription})
       task.delete()
       self.response.set_status(204, "Deleted")
     else:
       self.response.set_status(404, "Not Found")
   else:
     self.response.set_status(401, "Not Authorized")
Ejemplo n.º 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")
 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)
Ejemplo n.º 4
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)