Exemplo n.º 1
0
    def set_new_title(self, title):
        query = {'_id': self._id}
        update = {'title': title}
        Database.update_one(Checklist.collection, query, update)
        updatedChecklist = Checklist.get_by_id(self._id).dict_from_class()

        return updatedChecklist
Exemplo n.º 2
0
    def update(self, updates):
        query = {'_id': self._id}
        update = {**updates, "isEdited": True, "action": Log.actions['UPDATE']}
        Database.update_one(Log.collection, query, update)
        updatedCursor = Log.get_by_id(self._id)

        return updatedCursor
Exemplo n.º 3
0
    def assign_board(self, boardId):
        curentTeamId = self._id
        query = {"_id": curentTeamId}

        addBoard = {"boards": boardId}

        Database.update_push('teams', query, addBoard)
Exemplo n.º 4
0
    def delete_comment(self, _id):
        result = Database.delete_one('comments', {'_id': self._id})
        isDocumentExist = Database.find_one('comments', {'_id': self._id})

        if result.deleted_count is 1 and isDocumentExist is None:
            return True
        return False
Exemplo n.º 5
0
    def add_item(self, item):
        itemDict = Item(**item).dict_from_class()
        query = {'_id': self._id}
        newItem = {'items': itemDict}

        Database.update_push(Checklist.collection, query, newItem)
        updatedClass = Checklist.get_by_id(self._id).dict_from_class()

        return updatedClass
Exemplo n.º 6
0
 def add_label(self, label):
     Database.update_one('cards', {'_id': self._id}, {"labels": []})
     if type(label) is dict:
         Database.update_push('cards', {'_id': self._id}, {"labels": label})
     elif type(label) is list:
         [
             Database.update_push('cards', {'_id': self._id},
                                  {"labels": lebl}) for lebl in label
         ]
Exemplo n.º 7
0
    def for_list(self, listId, listTitle):
        prepareData = {
            **self.rest, 'listId': listId,
            "logType": Log.logType['LIST'],
            "action": Log.actions['CREATE'],
            'body': listTitle
        }

        Database.insert(Log.collection, prepareData)
Exemplo n.º 8
0
    def remove_item(self, itemId):
        query = {'_id': self._id}
        document = {'items': {'_id': itemId}}
        Database.delete_one_from_array(Checklist.collection, query, document)
        cursor = Database.find_one(Checklist.collection, query)
        isRemovedtItemExist = list(
            filter(lambda c: c['_id'] == itemId, cursor['items']))

        if len(isRemovedtItemExist) == 0:
            return True
        return False
Exemplo n.º 9
0
    def add_attachment(self, file, content_type, file_name):
        filedId = FS.put(file, content_type, file_name)
        query = {'_id': self._id}

        if len(self.attachments['files']) == 0:
            Database.update_one(Card.collection, query,
                                {'attachments.assigned': filedId})

        Database.update_push(Card.collection, query,
                             {'attachments.files': filedId})

        _, cursorCard = Card.get_card_by_id(self._id)

        return cursorCard, filedId
Exemplo n.º 10
0
    def register_user(email, password, name):
        user_data = Database.find_one('users', {"email": email})
        print("There is current user {}".format(user_data))

        if user_data is not None:
            raise err.UserIsAlreadyExist("The user with {} is already exist".format(email))
        
        if not Utils.email_is_valid(email):
            raise err.InvalidEmail("Please, write a valid email")
        
        userId = User(email, Utils.hash_password(password), name).save()
        userCursor = Database.find_one('users', {'_id': userId})

        return True, userCursor
Exemplo n.º 11
0
    def assign_attachment_file(self, fileId):
        query = {'_id': self._id}
        if fileId == self.attachments['assigned']:
            Database.update_one(Card.collection, query,
                                {'attachments.assigned': ''})
        else:
            Database.update_one(Card.collection, query,
                                {'attachments.assigned': fileId})

        cursorCard = Database.find_one(Card.collection, query)
        return {
            **cursorCard, 'attachments': {
                'assigned': cursorCard['attachments']['assigned']
            }
        }
Exemplo n.º 12
0
 def get_board(cls, _id):
     cursorBoard = Database.find_one('boards', {'_id': _id})
     if cursorBoard is not None:
         return cls(**cursorBoard), cursorBoard
     else:
         raise error.BoardIsNotExistInDatabase(
             "The board with this Id is not exist in Database")
Exemplo n.º 13
0
    def update_team(self, updates):
        updatedClass = Database.update_one(Team.collection, {'_id': self._id},
                                           {**updates})

        if updatedClass.raw_result['nModified'] == 1:
            return {**updates, '_id': self._id}

        return "THERE IS NOTHINK TO UPDATE"
Exemplo n.º 14
0
    def update(self, updates):
        isUpdatedResult = Database.update_one(Board.collection,
                                              {'_id': self._id}, {**updates})

        if isUpdatedResult.raw_result['nModified'] == 1:
            return {'_id': self._id, **updates, 'reletedTo': self.reletedTo}

        return "Nothink to update"
Exemplo n.º 15
0
    def is_login_valid(email, password):
        user_data = Database.find_one('users', {"email": email})

        if user_data is None:
            raise err.UserNotExist("User is not exist")
        if not Utils.check_hashed_password(password, user_data['password']):
            raise err.IncorectPassword("Wrond password")
        
        return True
Exemplo n.º 16
0
 def update_comment(self, updates):
     commentId = Database.update_one('comments', {'_id': self._id}, {
         'description': updates,
         'isEdited': True
     })
     if commentId.acknowledged:
         cursor, _ = Comment.get_by_id(self._id)
         return cursor
     return "throw error cause nothink to update actually"
Exemplo n.º 17
0
    def update_user_info(self, updates):
        updatedClass = Database.update_one(User.collection, {'_id': self._id}, {**updates})

        if updatedClass.raw_result['nModified']  == 1:
            return {**updates, '_id' : self._id}

        # userWutkUpdatedData = User.get_user_by_id_cursor(self._id)

        return "We dont uppdate actualy nothink"
Exemplo n.º 18
0
    def delete_attachment(self, fileId):
        query = {'_id': self._id}
        toRemoveFile = {'attachments.files': fileId}

        isRemoveFromFs = FS.delete(fileId)

        try:
            if isRemoveFromFs:
                if fileId == self.attachments['assigned']:
                    clearAssignment = {'attachments.assigned': ''}
                    Database.update_one(Card.collection, query,
                                        clearAssignment)

                Database.delete_one_from_array(Card.collection, query,
                                               toRemoveFile)

            return {**query, 'forList': self.forList, 'deletedFile': fileId}
        except:
            raise "The file is not exist with — {} | id".format(fileId)
Exemplo n.º 19
0
    def add_checklist(self, newChecklist):
        checklistId = Checklist(**newChecklist).save()

        updatedCardId = Database.update_push('cards', {'_id': self._id},
                                             {'checklists': checklistId})

        justCreatedCheckList = Checklist.get_by_id(
            checklistId).dict_from_class()

        return justCreatedCheckList
Exemplo n.º 20
0
    def create_for_board(self):
        prepareData = {
            **self.rest, "teamId": self.teamId,
            "logType": Log.logType['BOARD'],
            "action": Log.actions['ASSIGN'],
            "cardId": None,
            "body": None
        }

        logId = Database.insert(Log.collection, prepareData)
        return logId
Exemplo n.º 21
0
    def assign_to(self, logType, addonsInfo=dict()):

        prepareData = {
            **self.rest, "action": self._action(action='a'),
            "logType": logType,
            **addonsInfo
        }

        logId = Database.insert(Log.collection, prepareData)

        return logId
Exemplo n.º 22
0
 def create_team(self):
     teamNameFromDb = Database.find_one("teams",
                                        {"teamName": self.teamName})
     if teamNameFromDb is None:
         teamId = Team(teamName=self.teamName,
                       authorId=self.authorId,
                       boards=self.boards).save()
         _, team = Team.get_team_by_id(teamId)
         return team
     else:
         raise err.TeamIsAlreadyExist(
             "The team with this name is already exist")
Exemplo n.º 23
0
    def for_comment(self, cardId, body, commentId, action='c'):
        if action == 'u':
            commentAction = Log.actions['UPDATE']
        elif action == 'd':
            commentAction = Log.actions['DELETE']
        else:
            commentAction = Log.actions['CREATE']

        prepareData = {
            **self.rest, "logType": Log.logType['COMMENT'],
            "action": commentAction,
            "cardId": cardId,
            "commentId": commentId,
            "body": body
        }

        logId = Database.insert(Log.collection, prepareData)
        return logId
Exemplo n.º 24
0
    def is_login_valid(email, password):
        '''
        This method verifies that an email-password combo (as sent by site forms) is valid or not.
        Checks that email exists, and that password associated to that email is correct

        :param email: The user's email
        :param password: A sha512 hashed password
        :return: True if valid, False otherwise
        '''
        user_data = Database.find_one(
            UserConstants.COLLECTION,
            {'email': email})  # Password in sha512 --> pbkdf2_sha512

        if user_data is None:
            # Tell the user their email does not exist
            raise UserErrors.UserNotExistsError("Your user does not exist!")
        if not Utils.check_hashed_password(password, user_data['password']):
            # Tell the user their password is wrong
            raise UserErrors.IncorrectPasswordError("Your password was wrong!")

        return True
Exemplo n.º 25
0
    def register_user(email, password):
        '''
        Registers a user using an email & password. Password already comes hashed as sha-512.

        :param email: user's email (might be invalid)
        :param password: sha-512 hashed password
        :return: True if registered, False otherwise (exceptions can als be raised)
        '''

        user_data = Database.find_one(UserConstants.COLLECTION,
                                      {"email": email})

        if user_data is not None:
            raise UserErrors.UserAlreadyRegisteredError(
                "User email already exists")

        if not Utils.email_is_valid(email):
            raise UserErrors.InvalidEmailError("Invalid email format!")

        User(email, Utils.hash_password(password)).save_to_mongo()
        return True
Exemplo n.º 26
0
 def assign_list_to_board(cls, listId):
     print("The assign_list_to_board — {}".format(cls._id))
     Database.update_push('boards', {'_id': cls._id}, {"lists": listId})
Exemplo n.º 27
0
    def remove_board(cls, boardId, removeFromTeamCollection):
        _, boardCursor = Board.get_board(boardId)

        teamId = boardCursor['reletedTo']['teamId']
        deletedBoard = Database.delete_one('boards', {"_id": boardId})
        removeFromTeamCollection(teamId, boardId)
Exemplo n.º 28
0
 def toggleBoardImportant(self, isImportant):
     Database.update_one('boards', {'_id': self._id},
                         {'isImportant': isImportant})
     cursorBoard = Database.find_one('boards', {'_id': self._id})
     return cursorBoard
Exemplo n.º 29
0
 def get_boards_by_author(cls, authorId):
     cursorBoards = Database.find('boards', {'authorId': authorId})
     return [board for board in cursorBoards]
Exemplo n.º 30
0
 def save(self):
     return Database.insert('boards', self.json())