Add logging to report view and add option to disable (ban) a user for superadmins

This commit is contained in:
Matt Kliewer 2017-07-09 02:26:21 -04:00 committed by Alex Ingram
parent 570ee1225a
commit 708e0da5a1
3 changed files with 66 additions and 34 deletions

View File

@ -518,6 +518,15 @@ class User(db.Model):
elif self.level >= UserLevelType.MODERATOR:
return 'Moderator'
@property
def userstatus_str(self):
if self.status == UserStatusType.INACTIVE:
return 'Inactive'
elif self.status == UserStatusType.ACTIVE:
return 'Active'
elif self.status == UserStatusType.BANNED:
return 'Banned'
@property
def userlevel_color(self):
if self.level == UserLevelType.REGULAR:

View File

@ -338,6 +338,9 @@ def view_user(user_name):
elif selection == 'moderator':
user.level = models.UserLevelType.MODERATOR
log = "[{}]({}) changed to moderator user".format(user_name, url)
elif selection == 'disabled':
user.status = models.UserStatusType.BANNED
log = "[{}]({}) changed to banned user".format(user_name, url)
adminlog = models.AdminLog(log=log, admin_id=flask.g.user.id)
db.session.add(user)
@ -871,19 +874,36 @@ def view_reports():
report_id = report_action.report.data
torrent = models.Torrent.by_id(torrent_id)
report = models.Report.by_id(report_id)
report_user = models.User.by_id(report.user_id)
if not torrent or not report or report.status != 0:
flask.abort(404)
else:
log = "Report #{}: {} [#{}]({}), reported by [{}]({})"
if action == 'delete':
torrent.deleted = True
report.status = 1
log = log.format(report_id, 'Deleted', torrent_id,
flask.url_for('view_torrent', torrent_id=torrent_id),
report_user.username,
flask.url_for('view_user', user_name=report_user.username))
elif action == 'hide':
log = log.format(report_id, 'Hid', torrent_id,
flask.url_for('view_torrent', torrent_id=torrent_id),
report_user.username,
flask.url_for('view_user', user_name=report_user.username))
torrent.hidden = True
report.status = 1
else:
log = log.format(report_id, 'Closed', torrent_id,
flask.url_for('view_torrent', torrent_id=torrent_id),
report_user.username,
flask.url_for('view_user', user_name=report_user.username))
report.status = 2
adminlog = models.AdminLog(log=log, admin_id=flask.g.user.id)
db.session.add(adminlog)
models.Report.remove_reviewed(torrent_id)
db.session.commit()
flask.flash('Closed report #{}'.format(report.id), 'success')
@ -949,6 +969,7 @@ def _create_user_class_choices(user):
choices.append(('trusted', 'Trusted'))
if flask.g.user.is_superadmin:
choices.append(('moderator', 'Moderator'))
choices.append(('disabled', 'Disabled'))
if user:
if user.is_moderator:

View File

@ -28,6 +28,8 @@
<dd>{{ user.email }}</dd>
<dt>User class:</dt>
<dd>{{ level }}</dd>
<dt>User status:</dt>
<dd>{{ user.userstatus_str }}</dt>
{%- if g.user.is_superadmin -%}
<dt>Last login IP:</dt>
<dd>{{ user.ip_string }}</dd><br>