mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 19:49:59 +00:00
Added reports page
This commit is contained in:
parent
98fbe6efb1
commit
799d5914d6
|
@ -390,7 +390,7 @@ class Report(db.Model):
|
||||||
__tablename__ = DB_TABLE_PREFIX + 'reports'
|
__tablename__ = DB_TABLE_PREFIX + 'reports'
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
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'))
|
DB_TABLE_PREFIX + 'torrents.id'))
|
||||||
user_id = db.Column(db.Integer, db.ForeignKey(
|
user_id = db.Column(db.Integer, db.ForeignKey(
|
||||||
'users.id'))
|
'users.id'))
|
||||||
|
@ -398,8 +398,11 @@ class Report(db.Model):
|
||||||
reason = db.Column(db.String(length=255), nullable=False)
|
reason = db.Column(db.String(length=255), nullable=False)
|
||||||
status = db.Column(ChoiceType(ReportStatus, impl=db.Integer()), nullable=False)
|
status = db.Column(ChoiceType(ReportStatus, impl=db.Integer()), nullable=False)
|
||||||
|
|
||||||
def __init__(self, torrent, user_id, reason):
|
user = db.relationship('User', uselist=False)
|
||||||
self.torrent = torrent
|
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.user_id = user_id
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
self.status = ReportStatus.IN_REVIEW
|
self.status = ReportStatus.IN_REVIEW
|
||||||
|
@ -412,6 +415,10 @@ class Report(db.Model):
|
||||||
''' Returns a UTC POSIX timestamp, as seconds '''
|
''' Returns a UTC POSIX timestamp, as seconds '''
|
||||||
return (self.created_time - UTC_EPOCH).total_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):
|
# class Session(db.Model):
|
||||||
# __tablename__ = 'sessions'
|
# __tablename__ = 'sessions'
|
||||||
|
|
|
@ -675,7 +675,7 @@ def submit_report(torrent_id):
|
||||||
if flask.g.user is not None:
|
if flask.g.user is not None:
|
||||||
current_user_id = flask.g.user.id
|
current_user_id = flask.g.user.id
|
||||||
report = models.Report(
|
report = models.Report(
|
||||||
torrent=torrent_id,
|
torrent_id=torrent_id,
|
||||||
user_id=current_user_id,
|
user_id=current_user_id,
|
||||||
reason=report_reason)
|
reason=report_reason)
|
||||||
|
|
||||||
|
@ -688,6 +688,17 @@ def submit_report(torrent_id):
|
||||||
return flask.redirect(flask.url_for('view_torrent', torrent_id=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):
|
def _get_cached_torrent_file(torrent):
|
||||||
# Note: obviously temporary
|
# Note: obviously temporary
|
||||||
cached_torrent = os.path.join(app.config['BASE_DIR'],
|
cached_torrent = os.path.join(app.config['BASE_DIR'],
|
||||||
|
|
|
@ -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>
|
<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' %}
|
{% if config.SITE_FLAVOR == 'nyaa' %}
|
||||||
<li><a href="https://sukebei.nyaa.si/">Fap</a></li>
|
<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' %}
|
{% elif config.SITE_FLAVOR == 'sukebei' %}
|
||||||
<li><a href="https://nyaa.si/">Fun</a></li>
|
<li><a href="https://nyaa.si/">Fun</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
30
nyaa/templates/reports.html
Normal file
30
nyaa/templates/reports.html
Normal 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 %}
|
|
@ -133,7 +133,7 @@
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form method="POST" action="{{ request.url }}/submit_report">
|
<form method="POST" action="{{ request.url }}/submit_report">
|
||||||
{{ form.csrf_token }}
|
{{ form.csrf_token }}
|
||||||
{{ render_field(form.reason, class_='form-control') }}
|
{{ render_field(form.reason, class_='form-control', maxlength=255) }}
|
||||||
<div style="float: right;">
|
<div style="float: right;">
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||||
<button type="submit" class="btn btn-danger">Report</button>
|
<button type="submit" class="btn btn-danger">Report</button>
|
||||||
|
|
Loading…
Reference in a new issue