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

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: 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:

View file

@ -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:

View file

@ -13,44 +13,46 @@
{% from "_formhelpers.html" import render_menu_with_button %} {% from "_formhelpers.html" import render_menu_with_button %}
{% if g.user and g.user.is_moderator %} {% if g.user and g.user.is_moderator %}
<h2>User Information</h2><br> <h2>User Information</h2><br>
<div class="row" style="margin-bottom: 20px;"> <div class="row" style="margin-bottom: 20px;">
<div class="col-sm-2" style="max-width: 150px;"> <div class="col-sm-2" style="max-width: 150px;">
<img class="avatar" src="{{ user.gravatar_url() }}"> <img class="avatar" src="{{ user.gravatar_url() }}">
</div> </div>
<div class="col-sm-10"> <div class="col-sm-10">
<dl class="dl-horizontal"> <dl class="dl-horizontal">
<dt>User ID:</dt> <dt>User ID:</dt>
<dd>{{ user.id }}</dd> <dd>{{ user.id }}</dd>
<dt>Account created on:</dt> <dt>Account created on:</dt>
<dd>{{ user.created_time }}</dd> <dd>{{ user.created_time }}</dd>
<dt>Email address:</dt> <dt>Email address:</dt>
<dd>{{ user.email }}</dd> <dd>{{ user.email }}</dd>
<dt>User class:</dt> <dt>User class:</dt>
<dd>{{ level }}</dd> <dd>{{ level }}</dd>
{%- if g.user.is_superadmin -%} <dt>User status:</dt>
<dt>Last login IP:</dt> <dd>{{ user.userstatus_str }}</dt>
<dd>{{ user.ip_string }}</dd><br> {%- if g.user.is_superadmin -%}
{%- endif -%} <dt>Last login IP:</dt>
</dl> <dd>{{ user.ip_string }}</dd><br>
</div> {%- endif -%}
</div> </dl>
{% if admin_form %} </div>
<form method="POST"> </div>
{{ admin_form.csrf_token }} {% if admin_form %}
<form method="POST">
{{ admin_form.csrf_token }}
<div class="form-group row"> <div class="form-group row">
<div class="col-md-6"> <div class="col-md-6">
{{ render_menu_with_button(admin_form.user_class) }} {{ render_menu_with_button(admin_form.user_class) }}
</div> </div>
</div> </div>
</form> </form>
<br> <br>
{% endif %} {% endif %}
{% endif %} {% endif %}
<h3> <h3>
Browsing <span class="text-{{ user.userlevel_color }}">{{ user.username }}</span>'{{ '' if user.username[-1] == 's' else 's' }} torrents Browsing <span class="text-{{ user.userlevel_color }}">{{ user.username }}</span>'{{ '' if user.username[-1] == 's' else 's' }} torrents
</h3> </h3>
{% include "search_results.html" %} {% include "search_results.html" %}