mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 13:49:59 +00:00
Add logging to report view and add option to disable (ban) a user for superadmins
This commit is contained in:
parent
570ee1225a
commit
708e0da5a1
|
@ -518,6 +518,15 @@ class User(db.Model):
|
||||||
elif self.level >= UserLevelType.MODERATOR:
|
elif self.level >= UserLevelType.MODERATOR:
|
||||||
return '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
|
@property
|
||||||
def userlevel_color(self):
|
def userlevel_color(self):
|
||||||
if self.level == UserLevelType.REGULAR:
|
if self.level == UserLevelType.REGULAR:
|
||||||
|
|
|
@ -338,6 +338,9 @@ def view_user(user_name):
|
||||||
elif selection == 'moderator':
|
elif selection == 'moderator':
|
||||||
user.level = models.UserLevelType.MODERATOR
|
user.level = models.UserLevelType.MODERATOR
|
||||||
log = "[{}]({}) changed to moderator user".format(user_name, url)
|
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)
|
adminlog = models.AdminLog(log=log, admin_id=flask.g.user.id)
|
||||||
db.session.add(user)
|
db.session.add(user)
|
||||||
|
@ -871,19 +874,36 @@ def view_reports():
|
||||||
report_id = report_action.report.data
|
report_id = report_action.report.data
|
||||||
torrent = models.Torrent.by_id(torrent_id)
|
torrent = models.Torrent.by_id(torrent_id)
|
||||||
report = models.Report.by_id(report_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:
|
if not torrent or not report or report.status != 0:
|
||||||
flask.abort(404)
|
flask.abort(404)
|
||||||
else:
|
else:
|
||||||
|
log = "Report #{}: {} [#{}]({}), reported by [{}]({})"
|
||||||
if action == 'delete':
|
if action == 'delete':
|
||||||
torrent.deleted = True
|
torrent.deleted = True
|
||||||
report.status = 1
|
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':
|
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
|
torrent.hidden = True
|
||||||
report.status = 1
|
report.status = 1
|
||||||
else:
|
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
|
report.status = 2
|
||||||
|
|
||||||
|
adminlog = models.AdminLog(log=log, admin_id=flask.g.user.id)
|
||||||
|
db.session.add(adminlog)
|
||||||
|
|
||||||
models.Report.remove_reviewed(torrent_id)
|
models.Report.remove_reviewed(torrent_id)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('Closed report #{}'.format(report.id), 'success')
|
flask.flash('Closed report #{}'.format(report.id), 'success')
|
||||||
|
@ -949,6 +969,7 @@ def _create_user_class_choices(user):
|
||||||
choices.append(('trusted', 'Trusted'))
|
choices.append(('trusted', 'Trusted'))
|
||||||
if flask.g.user.is_superadmin:
|
if flask.g.user.is_superadmin:
|
||||||
choices.append(('moderator', 'Moderator'))
|
choices.append(('moderator', 'Moderator'))
|
||||||
|
choices.append(('disabled', 'Disabled'))
|
||||||
|
|
||||||
if user:
|
if user:
|
||||||
if user.is_moderator:
|
if user.is_moderator:
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
<dd>{{ user.email }}</dd>
|
<dd>{{ user.email }}</dd>
|
||||||
<dt>User class:</dt>
|
<dt>User class:</dt>
|
||||||
<dd>{{ level }}</dd>
|
<dd>{{ level }}</dd>
|
||||||
|
<dt>User status:</dt>
|
||||||
|
<dd>{{ user.userstatus_str }}</dt>
|
||||||
{%- if g.user.is_superadmin -%}
|
{%- if g.user.is_superadmin -%}
|
||||||
<dt>Last login IP:</dt>
|
<dt>Last login IP:</dt>
|
||||||
<dd>{{ user.ip_string }}</dd><br>
|
<dd>{{ user.ip_string }}</dd><br>
|
||||||
|
|
Loading…
Reference in a new issue