예제 #1
0
def ban_or_unban(request, url_user):
    """
    A page to ban or unban a user. Only can be used by an admin.
    """
    form = moderation_forms.BanForm(request.form)
    if request.method == "POST" and form.validate():
        already_banned = unban_user(url_user.id)
        same_as_requesting_user = (request.user.id == url_user.id)
        if not already_banned and not same_as_requesting_user:
            user_ban = ban_user(url_user.id,
                                expiration_date=form.user_banned_until.data,
                                reason=form.why_user_was_banned.data)
            user_ban.save()
    return redirect(request,
                    'mediagoblin.moderation.users_detail',
                    user=url_user.username)
예제 #2
0
def moderation_users_detail(request):
    '''
    Shows details about a particular user.
    '''
    user = User.query.filter_by(username=request.matchdict['user']).first()
    active_reports = user.reports_filed_on.filter(
        ReportBase.resolved==None).limit(5)
    closed_reports = user.reports_filed_on.filter(
        ReportBase.resolved!=None).all()
    privileges = Privilege.query
    user_banned = UserBan.query.get(user.id)
    ban_form = moderation_forms.BanForm()

    return render_to_response(
        request,
        'mediagoblin/moderation/user.html',
        {'user':user,
         'privileges': privileges,
         'reports':active_reports,
         'user_banned':user_banned,
         'ban_form':ban_form})