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

Added reports page

This commit is contained in:
nyaazi 2017-05-19 20:52:04 +03:00
parent 98fbe6efb1
commit 799d5914d6
5 changed files with 56 additions and 5 deletions

View file

@ -390,7 +390,7 @@ class Report(db.Model):
__tablename__ = DB_TABLE_PREFIX + 'reports'
id = db.Column(db.Integer, primary_key=True)
torrent = db.Column(db.Integer, db.ForeignKey(
torrent_id = db.Column(db.Integer, db.ForeignKey(
DB_TABLE_PREFIX + 'torrents.id'))
user_id = db.Column(db.Integer, db.ForeignKey(
'users.id'))
@ -398,8 +398,11 @@ class Report(db.Model):
reason = db.Column(db.String(length=255), nullable=False)
status = db.Column(ChoiceType(ReportStatus, impl=db.Integer()), nullable=False)
def __init__(self, torrent, user_id, reason):
self.torrent = torrent
user = db.relationship('User', uselist=False)
torrent = db.relationship('Torrent', uselist=False)
def __init__(self, torrent_id, user_id, reason):
self.torrent_id = torrent_id
self.user_id = user_id
self.reason = reason
self.status = ReportStatus.IN_REVIEW
@ -412,6 +415,10 @@ class Report(db.Model):
''' Returns a UTC POSIX timestamp, as seconds '''
return (self.created_time - UTC_EPOCH).total_seconds()
@classmethod
def not_reviewed(cls):
reports = cls.query.filter_by(status=0).all()
return reports
# class Session(db.Model):
# __tablename__ = 'sessions'

View file

@ -675,7 +675,7 @@ def submit_report(torrent_id):
if flask.g.user is not None:
current_user_id = flask.g.user.id
report = models.Report(
torrent=torrent_id,
torrent_id=torrent_id,
user_id=current_user_id,
reason=report_reason)
@ -688,6 +688,17 @@ def submit_report(torrent_id):
return flask.redirect(flask.url_for('view_torrent', torrent_id=torrent_id))
@app.route('/reports', methods=['GET'])
def view_reports():
reports = models.Report.not_reviewed()
if not flask.g.user or not flask.g.user.is_admin:
flask.abort(403)
return flask.render_template('reports.html',
reports=reports)
def _get_cached_torrent_file(torrent):
# Note: obviously temporary
cached_torrent = os.path.join(app.config['BASE_DIR'],

View file

@ -72,6 +72,9 @@
<li><a href="{% if rss_filter %}{{ url_for('home', page='rss', **rss_filter) }}{% else %}{{ url_for('home', page='rss') }}{% endif %}">RSS</a></li>
{% if config.SITE_FLAVOR == 'nyaa' %}
<li><a href="https://sukebei.nyaa.si/">Fap</a></li>
{% if g.user.is_admin %}
<li><a href="/reports">Reports</a></li>
{% endif %}
{% elif config.SITE_FLAVOR == 'sukebei' %}
<li><a href="https://nyaa.si/">Fun</a></li>
{% endif %}

View file

@ -0,0 +1,30 @@
{% extends "layout.html" %}
{% block title %}Reports :: {{ config.SITE_NAME }}{% endblock %}
{% block body %}
{% from "_formhelpers.html" import render_field %}
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>#</th>
<th>Reported by:</th>
<th>Torrent:</th>
<th>Reason:</th>
<th>Date:</th>
<th>Action:</th>
</tr>
</thead>
<tbody>
{% for report in reports %}
<tr>
<td>{{ report.id }}</td>
<td><a href="{{ url_for('view_user', user_name=report.user.username) }}">{{ report.user.username }}</a></td>
<td><a href="{{ url_for('view_torrent', torrent_id=report.torrent.id) }}">{{ report.torrent.display_name }}</a></td>
<td>{{ report.reason }}</td>
<td>{{ report.created_time }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}

View file

@ -133,7 +133,7 @@
<div class="modal-body">
<form method="POST" action="{{ request.url }}/submit_report">
{{ form.csrf_token }}
{{ render_field(form.reason, class_='form-control') }}
{{ render_field(form.reason, class_='form-control', maxlength=255) }}
<div style="float: right;">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger">Report</button>