1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 09:19:59 +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) flask.abort(404)
# Only allow admins edit deleted torrents # 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) flask.abort(404)
# Only allow torrent owners or admins edit torrents # 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) flask.abort(403)
if flask.request.method == 'POST' and form.validate(): if flask.request.method == 'POST' and form.validate():
@ -752,18 +752,18 @@ def edit_torrent(torrent_id):
torrent.complete = form.is_complete.data torrent.complete = form.is_complete.data
torrent.anonymous = form.is_anonymous.data torrent.anonymous = form.is_anonymous.data
if flask.g.user.is_trusted: if editor.is_trusted:
torrent.trusted = form.is_trusted.data 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 torrent.deleted = form.is_deleted.data
if flask.g.user.is_moderator: url = flask.url_for('view_torrent', torrent_id=torrent.id)
log = "Torrent [#{}]({}) marked as ".format(torrent.id, url) if deleted_changed and editor.is_moderator:
url = flask.url_for('view_torrent', torrent_id=torrent.id) log = "Torrent [#{0}]({1}) marked as {2}".format(
adminlog = models.AdminLog(log=(log+"deleted" torrent.id, url, "deleted" if torrent.deleted else "undeleted")
if torrent.deleted else adminlog = models.AdminLog(log=log, admin_id=editor.id)
log+"undeleted"),
admin_id=flask.g.user.id)
db.session.add(adminlog) db.session.add(adminlog)
db.session.commit() db.session.commit()