mirror of
https://github.com/sb745/NyaaV3.git
synced 2025-03-12 13:56:55 +02:00
user page: add manual activation button for mods (#472)
* user page: add manual activation button for mods Moderators can press this button on inactive users to manually activate their accounts. Furthermore, the admin form code has been refactored a bit, reducing some code duplication.
This commit is contained in:
parent
59db958977
commit
bb9a62f71b
4 changed files with 34 additions and 18 deletions
|
@ -408,6 +408,7 @@ class UploadForm(FlaskForm):
|
||||||
|
|
||||||
class UserForm(FlaskForm):
|
class UserForm(FlaskForm):
|
||||||
user_class = SelectField('Change User Class')
|
user_class = SelectField('Change User Class')
|
||||||
|
activate_user = SubmitField('Activate User')
|
||||||
|
|
||||||
def validate_user_class(form, field):
|
def validate_user_class(form, field):
|
||||||
if not field.data:
|
if not field.data:
|
||||||
|
|
|
@ -611,6 +611,10 @@ class User(db.Model):
|
||||||
def is_banned(self):
|
def is_banned(self):
|
||||||
return self.status == UserStatusType.BANNED
|
return self.status == UserStatusType.BANNED
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_active(self):
|
||||||
|
return self.status != UserStatusType.INACTIVE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def age(self):
|
def age(self):
|
||||||
'''Account age in seconds'''
|
'''Account age in seconds'''
|
||||||
|
|
|
@ -42,14 +42,21 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if admin_form %}
|
{% if admin_form %}
|
||||||
<div class="row">
|
<form method="POST">
|
||||||
<div class="col-md-6">
|
{{ admin_form.csrf_token }}
|
||||||
<form method="POST">
|
<div class="row">
|
||||||
{{ admin_form.csrf_token }}
|
<div class="col-md-6">
|
||||||
{{ render_menu_with_button(admin_form.user_class) }}
|
{{ render_menu_with_button(admin_form.user_class) }}
|
||||||
</form>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{% if not user.is_active %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
{{ admin_form.activate_user(class="btn btn-primary") }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</form>
|
||||||
<br>
|
<br>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -47,20 +47,24 @@ def view_user(user_name):
|
||||||
url = flask.url_for('users.view_user', user_name=user.username)
|
url = flask.url_for('users.view_user', user_name=user.username)
|
||||||
if flask.request.method == 'POST' and admin_form and not doban and admin_form.validate():
|
if flask.request.method == 'POST' and admin_form and not doban and admin_form.validate():
|
||||||
selection = admin_form.user_class.data
|
selection = admin_form.user_class.data
|
||||||
log = None
|
mapping = {'regular': models.UserLevelType.REGULAR,
|
||||||
if selection == 'regular':
|
'trusted': models.UserLevelType.TRUSTED,
|
||||||
user.level = models.UserLevelType.REGULAR
|
'moderator': models.UserLevelType.MODERATOR}
|
||||||
log = "[{}]({}) changed to regular user".format(user_name, url)
|
|
||||||
elif selection == 'trusted':
|
if mapping[selection] != user.level:
|
||||||
user.level = models.UserLevelType.TRUSTED
|
user.level = mapping[selection]
|
||||||
log = "[{}]({}) changed to trusted user".format(user_name, url)
|
log = "[{}]({}) changed to {} user".format(user_name, url, selection)
|
||||||
elif selection == 'moderator':
|
adminlog = models.AdminLog(log=log, admin_id=flask.g.user.id)
|
||||||
user.level = models.UserLevelType.MODERATOR
|
db.session.add(adminlog)
|
||||||
log = "[{}]({}) changed to moderator user".format(user_name, url)
|
|
||||||
|
if admin_form.activate_user.data and not user.is_banned:
|
||||||
|
user.status = models.UserStatusType.ACTIVE
|
||||||
|
adminlog = models.AdminLog("[{}]({}) was manually activated"
|
||||||
|
.format(user_name, url),
|
||||||
|
admin_id=flask.g.user.id)
|
||||||
|
db.session.add(adminlog)
|
||||||
|
|
||||||
adminlog = models.AdminLog(log=log, admin_id=flask.g.user.id)
|
|
||||||
db.session.add(user)
|
db.session.add(user)
|
||||||
db.session.add(adminlog)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return flask.redirect(url)
|
return flask.redirect(url)
|
||||||
|
|
Loading…
Add table
Reference in a new issue