Ejemplo n.º 1
0
    def put(self, note_id):
        request_data = request.get_json()
        note = session.query(Note).get(note_id)

        if note is None:
            return Message.instance_not_exist()

        is_moderator = False
        for moderator in note.users:
            if moderator.id == auth.current_user().id:
                is_moderator = True
        if note.owner_id != auth.current_user().id and not is_moderator:
            return Message.auth_failed()

        if 'name' in request_data:
            note.name = request_data['name']
        if 'text' in request_data:
            note.text = request_data['text']
        if 'tag_id' in request_data:
            tag_id = request_data['tag_id']
            tag = session.query(Tag).get(tag_id)
            note.tags.append(tag)

        session.commit()
        return Message.successful('updated')
Ejemplo n.º 2
0
    def put(self, note_id, user_id):
        note = session.query(Note).get(note_id)

        if note is None:
            return Message.instance_not_exist()

        user = session.query(User).get(user_id)
        if user is None:
            return Message.instance_not_exist()

        is_moderator = False
        for moderator in note.users:
            if moderator.id == auth.current_user().id:
                is_moderator = True
        if note.owner_id != auth.current_user().id and not is_moderator:
            return Message.auth_failed()

        max_moderators = 5
        if note.number_of_moderators >= max_moderators:
            return Message.message('Can not add a moderator', 400)

        note.number_of_moderators += 1
        note.users.append(user)
        session.commit()
        return Message.successful('add moderator to note')
Ejemplo n.º 3
0
    def delete(self, note_id):
        note = session.query(Note).get(note_id)

        if note is None:
            return Message.instance_not_exist()

        if note.owner_id != auth.current_user().id:
            return Message.auth_failed()

        session.delete(note)
        session.commit()
        return Message.successful('deleted')
Ejemplo n.º 4
0
    def delete(self, user_id):
        user = session.query(User).get(user_id)

        if user is None:
            return Message.instance_not_exist()

        if user.email != auth.current_user().email:
            return Message.auth_failed()

        session.delete(user)
        session.commit()
        return Message.successful('deleted')
Ejemplo n.º 5
0
    def put(self, note_id, tag_id):
        note = session.query(Note).get(note_id)

        if note is None:
            return Message.instance_not_exist()

        if note.owner_id != auth.current_user().id:
            return Message.auth_failed()

        tag = session.query(Tag).get(tag_id)
        if tag is None:
            return Message.instance_not_exist()

        note.tags.append(tag)

        session.commit()

        return Message.successful('add tag to note')
Ejemplo n.º 6
0
    def put(self, user_id):
        request_data = request.get_json()
        user = session.query(User).get(user_id)

        if user is None:
            return Message.instance_not_exist()

        if user.email != auth.current_user().email:
            return Message.auth_failed()

        if 'username' in request_data:
            user.username = request_data['username']
        if 'email' in request_data:
            user.email = request_data['email']
        if 'password' in request_data:
            user.password = request_data["password"]

        session.commit()
        return Message.successful('updated')