Exemple #1
0
def notes_delete_message():
    resource_id = request.form['resource_id']
    thread_id = str(request.form['thread_id'])
    # TODO: fix inconsistant field name
    msg_id = request.form['msgId']
    user = current_user.name
    thread = Note.get_by_thread_id(thread_id)
    if thread is None:
        return Response('no thread', mimetype='text/plain')

    # TODO: check if actually is owner
    is_owner = True

    def should_keep(msg):
        _content, _user, _id = msg
        # lack permission to delete
        if not (_user == user or is_owner):
            return True
        # keep if it's not the message we're looking for
        return _id != msg_id

    msgs = json.loads(thread.data)
    new_msgs = filter(should_keep, msgs)
    if len(msgs) == len(new_msgs):
        return Response('error', mimetype='text/plain')
    if len(new_msgs) == 0:
        db.session.delete(thread)
    else:
        thread.data = json.dumps(new_msgs)
        thread.updated = datetime.utcnow()
    unread_notes = UnreadNote.query.filter_by(msg_id=msg_id).all()
    for note in unread_notes:
        db.session.delete(note)
    db.session.commit()
    return Response('deleted', mimetype='text/plain')
Exemple #2
0
def notes_submit_message():
    resource_id = request.form['resource_id']
    thread_id = str(request.form['thread_id'])
    content = request.form['content']
    msg_id = request.form['msg_id'] # only if this edits a previous message
    user = get_current_user_email_with_default()
    if resource_id == 'Demo':
        output = json.dumps([content, msg_id, user, thread_id])
        return Response(output, mimetype='text/plain')

    thread = Note.get_by_thread_id(thread_id)
    msgs = json.loads(thread.data)
    was_new_message = True
    for msg in msgs:
        _content, _user, _id = msg
        if _id == msg_id and _user == user:
            msg[0] = content
            was_new_message = False

    if was_new_message:
        msg_id = str(datetime.utcnow())
        msgs.append([content, user, msg_id])

    thread.data = json.dumps(msgs)
    thread.updated = datetime.utcnow()
    new_note_notification(resource_id, user, thread_id, msg_id)
    db.session.commit()
    if request.form['fromPage'] == 'mobileviewnotes':
        return Response('sent', mimetype='text/plain')
    output = json.dumps([content, msg_id, user, thread_id])
    return Response(output, mimetype='text/plain')
def notes_submit_message():
    resource_id = request.form['resource_id']
    thread_id = str(request.form['thread_id'])
    content = request.form['content']
    msg_id = request.form['msg_id']  # only if this edits a previous message
    user = get_current_user_email_with_default()
    if resource_id == 'Demo':
        output = json.dumps([content, msg_id, user, thread_id])
        return Response(output, mimetype='text/plain')

    thread = Note.get_by_thread_id(thread_id)
    msgs = json.loads(thread.data)
    was_new_message = True
    for msg in msgs:
        _content, _user, _id = msg
        if _id == msg_id and _user == user:
            msg[0] = content
            was_new_message = False

    if was_new_message:
        msg_id = str(datetime.utcnow())
        msgs.append([content, user, msg_id])

    thread.data = json.dumps(msgs)
    thread.updated = datetime.utcnow()
    new_note_notification(resource_id, user, thread_id, msg_id)
    db.session.commit()
    if request.form['fromPage'] == 'mobileviewnotes':
        return Response('sent', mimetype='text/plain')
    output = json.dumps([content, msg_id, user, thread_id])
    return Response(output, mimetype='text/plain')
def notes_delete_message():
    resource_id = request.form['resource_id']
    thread_id = str(request.form['thread_id'])
    # TODO: fix inconsistant field name
    msg_id = request.form['msgId']
    user = current_user.name
    thread = Note.get_by_thread_id(thread_id)
    if thread is None:
        return Response('no thread', mimetype='text/plain')

    # TODO: check if actually is owner
    is_owner = True

    def should_keep(msg):
        _content, _user, _id = msg
        # lack permission to delete
        if not (_user == user or is_owner):
            return True
        # keep if it's not the message we're looking for
        return _id != msg_id

    msgs = json.loads(thread.data)
    new_msgs = filter(should_keep, msgs)
    if len(msgs) == len(new_msgs):
        return Response('error', mimetype='text/plain')
    if len(new_msgs) == 0:
        db.session.delete(thread)
    else:
        thread.data = json.dumps(new_msgs)
        thread.updated = datetime.utcnow()
    unread_notes = UnreadNote.query.filter_by(msg_id=msg_id).all()
    for note in unread_notes:
        db.session.delete(note)
    db.session.commit()
    return Response('deleted', mimetype='text/plain')
Exemple #5
0
def notes_delete_thread():
    resource_id = request.form['resource_id']
    thread_id = str(request.form['thread_id'])
    thread = Note.get_by_thread_id(thread_id)
    db.session.delete(thread)
    unread_notes = UnreadNote.query.filter_by(thread_id=thread_id).all()
    for note in unread_notes:
        db.session.delete(note)
    db.session.commit()
    return Response('1', mimetype='text/plain')
def notes_delete_thread():
    resource_id = request.form['resource_id']
    thread_id = str(request.form['thread_id'])
    thread = Note.get_by_thread_id(thread_id)
    db.session.delete(thread)
    unread_notes = UnreadNote.query.filter_by(thread_id=thread_id).all()
    for note in unread_notes:
        db.session.delete(note)
    db.session.commit()
    return Response('1', mimetype='text/plain')
Exemple #7
0
def notes_position():
    resource_id = request.form['resource_id']
    positions = request.form['positions']
    now = datetime.utcnow()
    for row, col, thread_id in json.loads(positions):
        thread_id = str(thread_id)
        thread = Note.get_by_thread_id(thread_id)
        thread.row = row
        thread.col = col
        thread.updated = now
    db.session.commit()
    return Response('1', mimetype='text/plain')
def notes_position():
    resource_id = request.form['resource_id']
    positions = request.form['positions']
    now = datetime.utcnow()
    for row, col, thread_id in json.loads(positions):
        thread_id = str(thread_id)
        thread = Note.get_by_thread_id(thread_id)
        thread.row = row
        thread.col = col
        thread.updated = now
    db.session.commit()
    return Response('1', mimetype='text/plain')