def post_ban_reply(ban_uid):
    reply_form = AppealReplyForm(request.form)

    ban = Ban.objects(uid=ban_uid).first()
    if ban is None:
        abort(404)

    if not user_can_post(current_user, ban):
        abort(403)

    appeal = ban.appeal

    if request.method == "POST" and reply_form.validate():
        last_reply = AppealReply.objects(ban=ban).order_by('-created').first()

        # If the user just posted a reply, treat this as an edit of his previous post.
        if last_reply and last_reply.creator.name == current_user.name:
            last_reply.text += "\n- - -\n" + reply_form.text.data
            last_reply.edits.append(AppealEdit(text=last_reply.text,
                                               user=current_user.to_dbref()))
            last_reply.save()
            return redirect(url_for('bans.view_ban', ban_uid=ban_uid))

        else:
            reply = AppealReply(creator=current_user.to_dbref(), text=reply_form.text.data, ban=ban)
            reply.edits.append(AppealEdit(text=reply_form.text.data, user=current_user.to_dbref()))
            reply.save()
            appeal.replies.append(reply)
            appeal.last = datetime.datetime.utcnow()
            ban.save()
            
            BanNotification.send_notifications(ban, action="reply")
            
            return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
Beispiel #2
0
def post_ban_reply(ban_uid):
    reply_form = AppealReplyForm(request.form)

    ban = Ban.objects(uid=ban_uid).first()
    if ban is None:
        abort(404)

    if not user_can_post(current_user, ban):
        abort(403)

    appeal = ban.appeal

    if request.method == "POST" and reply_form.validate():
        last_reply = AppealReply.objects(ban=ban).order_by('-created').first()

        # If the user just posted a reply, treat this as an edit of his previous post.
        if last_reply and last_reply.creator.name == current_user.name:
            last_reply.text += "\n- - -\n" + reply_form.text.data
            last_reply.edits.append(
                AppealEdit(text=last_reply.text, user=current_user.to_dbref()))
            last_reply.save()
            return redirect(url_for('bans.view_ban', ban_uid=ban_uid))

        else:
            reply = AppealReply(creator=current_user.to_dbref(),
                                text=reply_form.text.data,
                                ban=ban)
            reply.edits.append(
                AppealEdit(text=reply_form.text.data,
                           user=current_user.to_dbref()))
            reply.save()
            appeal.replies.append(reply)
            appeal.last = datetime.datetime.utcnow()
            ban.save()

            BanNotification.send_notifications(ban, action="reply")

            return redirect(url_for('bans.view_ban', ban_uid=ban_uid))