def addCollaborators(taskObj): """ Add collaborators to an existing task :type taskObj: object :param An instance with the following attributes collaborators :return An instance of the Task class """ my_objects = [] userObj = Collection() groupObj = Collection() #Obtain the group using id groupObj.id = taskObj.group_id taskgroup = getGroupById(groupObj) #Obtain the task using task is task = getTaskById(taskObj) #Create a Status object to assign to each collaborator taskObj.status = Status(status=0, dateTime=time.time()) #Checking existence of collaborators for userObj.email in taskObj.collaborators: user = userbll.getUserByEmail(userObj) if not [x for x in taskgroup.members if x.id == user.id]: raise UserNotMember my_objects.append(Collaborator(user=user, status=taskObj.status)) GroupTask.objects(id=task.id).update(push_all__collaborators=my_objects) task.save() task.reload() return task
def addNewTask(taskObj): """ Adds a new task to the task list :type taskObj : object :para. taskObj : An object with the following attributes owner, collaborators, priority, name, description, dueDateTime, status :return an object of the task class. """ #Assigning initial status to each task taskObj.task_status = Status(status=1, dateTime=time.time()) taskObj.coll_status = Status(status=0, dateTime=time.time()) #Define an emptly list to include all the user objects my_objects = [] userObj = Collection() #for finding the user id of the owner userObj.id = taskObj.owner userObj.owner = userbll.getUserById(userObj) #Checking whether the collaborators is a user of the app #If not - Create a new account for the user for userObj.email in taskObj.collaborators: try: User.objects.get(email=userObj.email) except Exception: userbll.createAndInvite( userObj ) #contains _id = senders id and email = recievers email #Creating the list of collaborators for val in taskObj.collaborators: userObj.email = val my_objects.append( Collaborator(user=userbll.getUserByEmail(userObj), status=taskObj.coll_status)) #Create a task with the necessary data. task = Task(owner=userObj.owner, collaborators=my_objects, priority=taskObj.priority, name=taskObj.name, description=taskObj.description, dueDateTime=taskObj.dueDateTime, status=taskObj.task_status) task.save() return task
def collStatusChange(self, taskObj, task): message = {} #Retrive the collaborators user = userbll.getUserByEmail(taskObj) message["type"] = self.NOTIFICATION_TYPE["Collaborator_Status_Change"] message["ownerName"] = str(user.name) message["taskName"] = str(task.name) message["status"] = taskObj.collstatus message["dateTime"] = self.seconds_time return message
def collDeletion(self, taskObj, task): message = {} userObj = Collection() message["type"] = self.NOTIFICATION_TYPE["Collaborator_Deleted"] message["ownerName"] = str(task.owner.name) message["taskName"] = str(task.name) message["unknown"] = 0 message["dateTime"] = self.seconds_time message["removedColl"] = "" #Get the removed Collaborator using his mail for userObj.email in taskObj.collaborators: user = userbll.getUserByEmail(userObj) if not (user.name): message["unknown"] += 1 else: message["removedColl"] += user.name + ", " return message
def remCollaborators(taskObj): """ Remove collaborators from an existing task :type taskObj: object :param taskObj: An instance with the following attributes collaborators :return An instance of the Task class """ userObj = Collection() task = getTaskById(taskObj) for userObj.email in taskObj.collaborators: user = userbll.getUserByEmail(userObj) Task.objects(id=taskObj.id).update_one(pull__collaborators__user=user) task.save() task.reload() return task
def modifyCollStatus(taskObj): """ Modify the status of the collaborator :type taskObj : object :param taskObj :An instance with the following attributes id - id of the task email - email of the collaborator collstatus - new status of the collaborator :return An instance of the Collaborator class """ task = getTaskById(taskObj) userObj = userbll.getUserByEmail(taskObj) collaborator = [x for x in task.collaborators if x.user == userObj] collaborator[0].status.status = taskObj.collstatus collaborator[0].status.dateTime = time.time() task.save() return task
def addNewTask(taskObj): """ Adds a new task to the task list :type taskObj : object :para. taskObj : An object with the following attributes owner, collaborators, priority, name, description, dueDateTime, status group :return an object of the task class. """ #Assigning initial status to each task taskObj.status = Status(status=0, dateTime=time.time()) #Define an emptly list to include all the user objects my_objects = [] userObj = Collection() #for finding the user id of the owner userObj.id = taskObj.owner taskObj.owner = userbll.getUserById(userObj) #Find if the group exists. If Yes, get TaskGroup object groupObj.id = taskObj.group_id taskgroup = getGroupById(groupObj) #Checking whether the collaborators is a user of the app #If yes check whether he is a member of the group for userObj.email in taskObj.collaborators: user = userbll.getUserByEmail(userObj) if not [x for x in taskgroup.members if x.id == user.id]: raise UserNotMember #Creating the list of collaborators for userObj.email in taskObj.collaborators: my_objects.append( Collaborator(user=userbll.getUserByEmail(userObj), status=taskObj.status)) #Create a task with the necessary data. task = GroupTask(owner=taskObj.owner, collaborators=my_objects, priority=taskObj.priority, name=taskObj.name, description=taskObj.description, dueDateTime=taskObj.dueDateTime, status=taskObj.status, collaborator_count=taskObj.collaborator_count).save() #Add the GroupTask object to the TaskGroup's task_list list try: TaskGroup.objects(id=taskgroup.id).update(push__task_list=task.id) except: raise GroupWithIDNotFound taskgroup.save() return task