mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 03: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:
|
||||
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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -13,44 +13,46 @@
|
|||
{% from "_formhelpers.html" import render_menu_with_button %}
|
||||
|
||||
{% if g.user and g.user.is_moderator %}
|
||||
<h2>User Information</h2><br>
|
||||
<div class="row" style="margin-bottom: 20px;">
|
||||
<div class="col-sm-2" style="max-width: 150px;">
|
||||
<img class="avatar" src="{{ user.gravatar_url() }}">
|
||||
</div>
|
||||
<div class="col-sm-10">
|
||||
<dl class="dl-horizontal">
|
||||
<dt>User ID:</dt>
|
||||
<dd>{{ user.id }}</dd>
|
||||
<dt>Account created on:</dt>
|
||||
<dd>{{ user.created_time }}</dd>
|
||||
<dt>Email address:</dt>
|
||||
<dd>{{ user.email }}</dd>
|
||||
<dt>User class:</dt>
|
||||
<dd>{{ level }}</dd>
|
||||
{%- if g.user.is_superadmin -%}
|
||||
<dt>Last login IP:</dt>
|
||||
<dd>{{ user.ip_string }}</dd><br>
|
||||
{%- endif -%}
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
{% if admin_form %}
|
||||
<form method="POST">
|
||||
{{ admin_form.csrf_token }}
|
||||
<h2>User Information</h2><br>
|
||||
<div class="row" style="margin-bottom: 20px;">
|
||||
<div class="col-sm-2" style="max-width: 150px;">
|
||||
<img class="avatar" src="{{ user.gravatar_url() }}">
|
||||
</div>
|
||||
<div class="col-sm-10">
|
||||
<dl class="dl-horizontal">
|
||||
<dt>User ID:</dt>
|
||||
<dd>{{ user.id }}</dd>
|
||||
<dt>Account created on:</dt>
|
||||
<dd>{{ user.created_time }}</dd>
|
||||
<dt>Email address:</dt>
|
||||
<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>
|
||||
{%- endif -%}
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
{% if admin_form %}
|
||||
<form method="POST">
|
||||
{{ admin_form.csrf_token }}
|
||||
|
||||
<div class="form-group row">
|
||||
<div class="col-md-6">
|
||||
{{ render_menu_with_button(admin_form.user_class) }}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<br>
|
||||
{% endif %}
|
||||
<div class="form-group row">
|
||||
<div class="col-md-6">
|
||||
{{ render_menu_with_button(admin_form.user_class) }}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<br>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<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>
|
||||
|
||||
{% include "search_results.html" %}
|
||||
|
|
Loading…
Reference in a new issue