1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 09:19:59 +00:00

Quick and dirty comment list for moderators to look at (#421)

This commit is contained in:
Anna-Maria Meriniemi 2017-12-04 15:51:31 +02:00 committed by GitHub
parent 052a038763
commit 3941a0b9b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 105 additions and 0 deletions

View file

@ -441,6 +441,11 @@ class CommentBase(DeclarativeHelperBase):
return db.relationship('User', uselist=False, return db.relationship('User', uselist=False,
back_populates=cls._table_prefix('comments'), lazy="joined") back_populates=cls._table_prefix('comments'), lazy="joined")
@declarative.declared_attr
def torrent(cls):
return db.relationship(cls._flavor_prefix('Torrent'), uselist=False,
back_populates='comments', lazy="joined")
def __repr__(self): def __repr__(self):
return '<Comment %r>' % self.id return '<Comment %r>' % self.id

View file

@ -18,6 +18,7 @@
<div class="row" style="margin-bottom: 20px;"> <div class="row" style="margin-bottom: 20px;">
<div class="col-md-2" style="max-width: 150px;"> <div class="col-md-2" style="max-width: 150px;">
<img class="avatar" src="{{ user.gravatar_url() }}"> <img class="avatar" src="{{ user.gravatar_url() }}">
<a href="{{ url_for('users.view_user_comments', user_name=user.username) }}">View all comments</a>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<dl class="dl-horizontal"> <dl class="dl-horizontal">

View file

@ -0,0 +1,72 @@
{% extends "layout.html" %}
{% block title %}Comments made by {{ user.username }} :: {{ config.SITE_NAME }}{% endblock %}
{% block meta_image %}{{ user.gravatar_url() }}{% endblock %}
{% block metatags %}
<meta property="og:description" content="Comments made by {{ user.username }}">
{% endblock %}
{% block body %}
{% from "_formhelpers.html" import render_menu_with_button %}
{% from "_formhelpers.html" import render_field %}
<h3>
<span class="text-{{ user.userlevel_color }}" data-toggle="tooltip" title="{{ user.userlevel_str }}">{{ user.username }}</span>'{{ '' if user.username[-1] == 's' else 's' }} comments
</h3>
{% if comments_query.items %}
<div id="comments" class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
Total of {{ comments_query.total }} comments
</h3>
</div>
{% for comment in comments_query.items %}
<div class="panel panel-default comment-panel">
<div class="panel-body">
<div class="col-md-2">
<p>
<a class="text-{{ comment.user.userlevel_color }}" href="{{ url_for('users.view_user', user_name=comment.user.username) }}" data-toggle="tooltip" title="{{ comment.user.userlevel_str }}">{{ comment.user.username }}</a>
</p>
<img class="avatar" src="{{ comment.user.gravatar_url() }}" alt="{{ comment.user.userlevel_str }}">
</div>
<div class="col-md-10 comment">
<div class="row comment-details">
<a href="#com-{{ loop.index }}"><small data-timestamp-swap data-timestamp="{{ comment.created_utc_timestamp|int }}">{{ comment.created_time.strftime('%Y-%m-%d %H:%M UTC') }}</small></a>
{% if comment.edited_time %}
<small data-timestamp-swap data-timestamp-title data-timestamp="{{ comment.edited_utc_timestamp }}" title="{{ comment.edited_time }}">(edited)</small>
{% endif %}
<small>on torrent <a href="{{ url_for('torrents.view', torrent_id=comment.torrent_id) }}">#{{comment.torrent_id}} <i>{{ comment.torrent.display_name }}</i></a></small>
{# <div class="comment-actions">
{% if g.user.id == comment.user_id and not comment.editing_limit_exceeded %}
<button class="btn btn-xs edit-comment" title="Edit"{% if config.EDITING_TIME_LIMIT %} data-until="{{ comment.editable_until|int }}"{% endif %}>Edit</button>
{% endif %}
{% if g.user.is_moderator or g.user.id == comment.user_id %}
<form class="delete-comment-form" action="{{ url_for('torrents.delete_comment', torrent_id=comment.torrent_id, comment_id=comment.id) }}" method="POST">
<button name="submit" type="submit" class="btn btn-danger btn-xs" title="Delete">Delete</button>
</form>
{% endif %}
</div> #}
</div>
<div class="row">
{# Escape newlines into html entities because CF strips blank newlines #}
<div markdown-text class="comment-content" id="torrent-comment{{ comment.id }}">{{- comment.text | escape | replace('\r\n', '\n') | replace('\n', '&#10;'|safe) -}}</div>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
{% else %}
<h3>No comments</h3>
{% endif %}
<div class="center">
{% from "bootstrap/pagination.html" import render_pagination %}
{{ render_pagination(comments_query) }}
</div>
{% endblock %}
</div>

View file

@ -226,6 +226,33 @@ def view_user(user_name):
ipbanned=ipbanned) ipbanned=ipbanned)
@bp.route('/user/<user_name>/comments')
def view_user_comments(user_name):
user = models.User.by_username(user_name)
if not user:
flask.abort(404)
# Only moderators get to see all comments for now
if not flask.g.user or not flask.g.user.is_moderator:
flask.abort(403)
page_number = flask.request.args.get('p')
try:
page_number = max(1, int(page_number))
except (ValueError, TypeError):
page_number = 1
comments_per_page = 100
comments_query = (models.Comment.query.filter(models.Comment.user_id)
.order_by(models.Comment.created_time.desc()))
comments_query = comments_query.paginate_faste(page_number, per_page=comments_per_page, step=5)
return flask.render_template('user_comments.html',
comments_query=comments_query,
user=user)
@bp.route('/user/activate/<payload>') @bp.route('/user/activate/<payload>')
def activate_user(payload): def activate_user(payload):
if app.config['MAINTENANCE_MODE']: if app.config['MAINTENANCE_MODE']: