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

Fix torrent deletion log

* Fix `url referenced before assignment.`
* Fix every action logged as delete/undelete
This commit is contained in:
Kfir Hadas 2017-07-05 13:24:19 +03:00
parent dd8cb4757e
commit 3b55af85f0

View file

@ -732,11 +732,11 @@ def edit_torrent(torrent_id):
flask.abort(404)
# Only allow admins edit deleted torrents
if torrent.deleted and not (flask.g.user and flask.g.user.is_moderator):
if torrent.deleted and not (editor and editor.is_moderator):
flask.abort(404)
# Only allow torrent owners or admins edit torrents
if not flask.g.user or not (flask.g.user is torrent.user or flask.g.user.is_moderator):
if not editor or not (editor is torrent.user or editor.is_moderator):
flask.abort(403)
if flask.request.method == 'POST' and form.validate():
@ -752,18 +752,18 @@ def edit_torrent(torrent_id):
torrent.complete = form.is_complete.data
torrent.anonymous = form.is_anonymous.data
if flask.g.user.is_trusted:
if editor.is_trusted:
torrent.trusted = form.is_trusted.data
if flask.g.user.is_moderator:
deleted_changed = torrent.deleted != form.is_deleted.data
if editor.is_moderator:
torrent.deleted = form.is_deleted.data
if flask.g.user.is_moderator:
log = "Torrent [#{}]({}) marked as ".format(torrent.id, url)
url = flask.url_for('view_torrent', torrent_id=torrent.id)
adminlog = models.AdminLog(log=(log+"deleted"
if torrent.deleted else
log+"undeleted"),
admin_id=flask.g.user.id)
if deleted_changed and editor.is_moderator:
log = "Torrent [#{0}]({1}) marked as {2}".format(
torrent.id, url, "deleted" if torrent.deleted else "undeleted")
adminlog = models.AdminLog(log=log, admin_id=editor.id)
db.session.add(adminlog)
db.session.commit()