Beispiel #1
0
def unban(ban_uid):
    ban = Ban.objects(uid=ban_uid).first()
    if ban is None:
        abort(404)

    if not current_user.has_permission("bans.appeal.manage"):
        abort(403)

    if not ban.active:
        flash("Ban has already been lifted.", category='alert')
        return redirect(url_for('bans.view_ban', ban_uid=ban_uid))

    if request.method == "POST":
        form = BanUnbanTimeForm(request.form)

        if form.validate():
            ban.removed_time = form.date.data
            ban.removed_by = current_user.name
            ban.save()
            flash("Ban will be lifted on specified date.", category='success')
            return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
        else:
            flash(
                "Unban date form failed to validate. Make sure you're typing in the right data.",
                category='alert')
            return redirect(url_for('bans.view_ban', ban_uid=ban_uid))

    ban.active = False
    ban.removed_by = current_user.name
    ban.removed_time = datetime.datetime.utcnow()
    ban.save()
    ban.ban_lifted()
    flash("Ban has been lifted.", category='success')
    return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
Beispiel #2
0
def close_appeal(ban_uid):
    ban = Ban.objects(uid=ban_uid).first()
    if ban is None:
        abort(404)

    if not current_user.has_permission("bans.appeal.manage"):
        abort(403)

    if ban.appeal.state == 'closed_forever':
        flash("Appeal has already been closed.", category='alert')
        return redirect(url_for('bans.view_ban', ban_uid=ban_uid))

    if request.method == "POST":
        form = AppealUnlockTimeForm(request.form)

        if form.validate():
            ban.appeal.unlock_time = form.date.data
            ban.appeal.state = 'closed_time'
            ban.save()
            flash("Appeal closed until specified date.", category='success')
            return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
        else:
            flash(
                "Appeal unlock date form failed to validate. Make sure you're typing in the right data.",
                category='alert')
            return redirect(url_for('bans.view_ban', ban_uid=ban_uid))

    ban.appeal.state = 'closed_forever'
    ban.save()
    flash("Appeal has been closed.", category='success')
    return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
Beispiel #3
0
def close_appeal(ban_uid):
    ban = Ban.objects(uid=ban_uid).first()
    if ban is None:
        abort(404)

    if not current_user.has_permission("bans.appeal.manage"):
        abort(403)

    if ban.appeal.state == 'closed_forever':
        flash("Appeal has already been closed.", category='alert')
        return redirect(url_for('bans.view_ban', ban_uid=ban_uid))

    if request.method == "POST":
        form = AppealUnlockTimeForm(request.form)

        if form.validate():
            ban.appeal.unlock_time = form.date.data
            ban.appeal.state = 'closed_time'
            ban.save()
            flash("Appeal closed until specified date.", category='success')
            return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
        else:
            flash("Appeal unlock date form failed to validate. Make sure you're typing in the right data.", category='alert')
            return redirect(url_for('bans.view_ban', ban_uid=ban_uid))

    ban.appeal.state = 'closed_forever'
    ban.save()
    flash("Appeal has been closed.", category='success')
    return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
Beispiel #4
0
def unban(ban_uid):
    ban = Ban.objects(uid=ban_uid).first()
    if ban is None:
        abort(404)

    if not current_user.has_permission("bans.appeal.manage"):
        abort(403)

    if not ban.active:
        flash("Ban has already been lifted.", category='alert')
        return redirect(url_for('bans.view_ban', ban_uid=ban_uid))

    if request.method == "POST":
        form = BanUnbanTimeForm(request.form)

        if form.validate():
            ban.removed_time = form.date.data
            ban.removed_by = current_user.name
            ban.save()
            flash("Ban will be lifted on specified date.", category='success')
            return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
        else:
            flash("Unban date form failed to validate. Make sure you're typing in the right data.", category='alert')
            return redirect(url_for('bans.view_ban', ban_uid=ban_uid))

    ban.active = False
    ban.removed_by = current_user.name
    ban.removed_time = datetime.datetime.utcnow()
    ban.save()
    ban.ban_lifted()
    flash("Ban has been lifted.", category='success')
    return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
Beispiel #5
0
    def delete(self):
        args = self.delete_parser.parse_args()
        validate_args = self.validate_delete(args)
        if validate_args:
            return validate_args

        remover = request.api_user.name
        uuid = args.get("uuid")
        uid = args.get("id")

        query = dict(active=True)

        if uuid:
            query["target"] = uuid
        if uid:
            query["uid"] = uid

        ban = Ban.objects(**query).first()

        if ban is None:
            return {'error': [{'message': "no active bans found"}]}

        ban.active = False
        ban.removed_by = remover
        ban.removed_time = datetime.datetime.utcnow()
        ban.save()
        ban.ban_lifted()

        return {'ban': construct_local_ban_data(ban)}
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 #7
0
    def post(self):
        args = self.post_parser.parse_args()
        validate_args = self.validate_post(args)
        if validate_args:
            return validate_args

        issuer = request.api_user
        reason = args.get("reason")
        source = args.get("server")
        uuid = args.get("uuid")

        player = MinecraftPlayer.find_or_create_player(uuid)

        if len(Ban.objects(target=player, active=True)) > 0:
            return {'error': [{'message': "the user is already banned", 'identifier': "anathema.bans.add:user_already_exists"}]}

        ban = Ban(issuer=issuer, issuer_old=issuer.name, target=player, username=player.mcname, reason=reason,
                  server=source, watching=[issuer]).save()

        return {'ban': construct_local_ban_data(ban)}
Beispiel #8
0
    def get(self, uid):
        ban = Ban.objects(uid=uid).first()
        if ban is None:
            abort(404)

        user = request.api_user._get_current_object()

        return {
            'uid': uid,
            'watching': user in ban.watching
        }
Beispiel #9
0
def view_ban(ban_uid):

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

    appeal = ban.appeal

    if ban.appeal.state == 'closed_time':
        if ban.appeal.unlock_time and ban.appeal.unlock_time < datetime.datetime.utcnow(
        ):
            ban.appeal.state = 'open'
            ban.save()

    replies = AppealReply.objects(ban=ban).order_by('+created')
    notes = Note.objects(target=ban.target, active=True)

    can_post = user_can_post(current_user, ban)

    alts = []
    if current_user.can("view alts"):
        user_ips = PlayerIpsModel.objects(player=ban.target).first()
        if user_ips:
            alts = PlayerIpsModel.objects(ips__in=user_ips.ips,
                                          player__ne=ban.target)

    unlock_time_form = AppealUnlockTimeForm()
    if appeal.unlock_time:
        unlock_time_form.date.data = appeal.unlock_time
    unban_time_form = BanUnbanTimeForm()
    if ban.removed_time:
        unban_time_form.date.data = ban.removed_time

    js_state_manager.get_manager().update(
        {'ban': {
            'watching': current_user in ban.watching,
            'id': ban.uid
        }})

    return render_template('bans_unified_view.html',
                           ban_id=ban_uid,
                           ban_object=ban,
                           appeal_object=appeal,
                           notes=notes,
                           reply_form=AppealReplyForm(),
                           edit_form=BanReasonEditForm(),
                           reply_edit_form=AppealReplyTextEditForm(),
                           unlock_time_form=unlock_time_form,
                           unban_time_form=unban_time_form,
                           replies=replies,
                           can_post=can_post,
                           alts=alts)
Beispiel #10
0
def ban_reason_edit(ban_uid):
    edit_form = BanReasonEditForm(request.form)

    if not current_user.has_permission("bans.appeal.manage"):
        abort(403)

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

    if request.method == "POST" and edit_form.validate():
        ban.reason = edit_form.text.data
        ban.save()
        return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
Beispiel #11
0
def ban_reason_edit(ban_uid):
    edit_form = BanReasonEditForm(request.form)

    if not current_user.has_permission("bans.appeal.manage"):
        abort(403)

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

    if request.method == "POST" and edit_form.validate():
        ban.reason = edit_form.text.data
        ban.save()
        return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
Beispiel #12
0
def open_appeal(ban_uid):
    ban = Ban.objects(uid=ban_uid).first()
    if ban is None:
        abort(404)

    if not current_user.has_permission("bans.appeal.manage"):
        abort(403)

    if ban.appeal.state == 'open':
        flash("Appeal is already open.", category='alert')
        return redirect(url_for('bans.view_ban', ban_uid=ban_uid))

    ban.appeal.state = 'open'
    ban.save()
    flash("Appeal has been re-opened.", category='success')
    return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
Beispiel #13
0
def open_appeal(ban_uid):
    ban = Ban.objects(uid=ban_uid).first()
    if ban is None:
        abort(404)

    if not current_user.has_permission("bans.appeal.manage"):
        abort(403)

    if ban.appeal.state == 'open':
        flash("Appeal is already open.", category='alert')
        return redirect(url_for('bans.view_ban', ban_uid=ban_uid))

    ban.appeal.state = 'open'
    ban.save()
    flash("Appeal has been re-opened.", category='success')
    return redirect(url_for('bans.view_ban', ban_uid=ban_uid))
Beispiel #14
0
def get_local_bans(uuid=None, uid=None, active=None):
    query = dict()

    if uuid is not None:
        query['target'] = uuid
    if uid is not None:
        query['uid'] = uid
    if active is not None:
        query['active'] = active

    bans_data = Ban.objects(**query)

    bans_response = []
    for ban_data in bans_data:
        bans_response.append(construct_local_ban_data(ban_data))

    return bans_response
def view_ban(ban_uid):

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

    appeal = ban.appeal

    if ban.appeal.state == 'closed_time':
        if ban.appeal.unlock_time and ban.appeal.unlock_time < datetime.datetime.utcnow():
            ban.appeal.state = 'open'
            ban.save()

    replies = AppealReply.objects(ban=ban).order_by('+created')
    notes = Note.objects(target=ban.target, active=True)

    can_post = user_can_post(current_user, ban)

    alts = []
    if current_user.can("view alts"):
        user_ips = PlayerIpsModel.objects(player=ban.target).first()
        if user_ips:
            alts = PlayerIpsModel.objects(ips__in=user_ips.ips, player__ne=ban.target)

    unlock_time_form = AppealUnlockTimeForm()
    if appeal.unlock_time:
        unlock_time_form.date.data = appeal.unlock_time
    unban_time_form = BanUnbanTimeForm()
    if ban.removed_time:
        unban_time_form.date.data = ban.removed_time

    js_state_manager.get_manager().update({
        'ban': {
            'watching': current_user in ban.watching,
            'id': ban.uid
        }
    })

    return render_template('bans_unified_view.html', ban_id=ban_uid, ban_object=ban, appeal_object=appeal, notes=notes,
                           reply_form=AppealReplyForm(), edit_form=BanReasonEditForm(), reply_edit_form=AppealReplyTextEditForm(),
                           unlock_time_form=unlock_time_form, unban_time_form=unban_time_form, replies=replies,
                           can_post=can_post, alts=alts)
Beispiel #16
0
    def put(self, uid):
        args = self.put_parser.parse_args()
        watch = args.get("watch").lower() == "true"

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

        user = request.api_user._get_current_object()

        if user in ban.watching:
            if not watch:
                ban.watching.remove(user)
        else:
            if watch:
                ban.watching.append(user)
        ban.save()

        return {
            'uid': uid,
            'watching': user in ban.watching
        }
Beispiel #17
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))