diff --git a/nyaa/forms.py b/nyaa/forms.py index 68ec1ad..b80a2d4 100644 --- a/nyaa/forms.py +++ b/nyaa/forms.py @@ -408,6 +408,7 @@ class UploadForm(FlaskForm): class UserForm(FlaskForm): user_class = SelectField('Change User Class') + activate_user = SubmitField('Activate User') def validate_user_class(form, field): if not field.data: diff --git a/nyaa/models.py b/nyaa/models.py index 5e846d9..154e548 100644 --- a/nyaa/models.py +++ b/nyaa/models.py @@ -611,6 +611,10 @@ class User(db.Model): def is_banned(self): return self.status == UserStatusType.BANNED + @property + def is_active(self): + return self.status != UserStatusType.INACTIVE + @property def age(self): '''Account age in seconds''' diff --git a/nyaa/templates/user.html b/nyaa/templates/user.html index 8658a4b..6d73267 100644 --- a/nyaa/templates/user.html +++ b/nyaa/templates/user.html @@ -42,14 +42,21 @@ {% if admin_form %} -
-
-
- {{ admin_form.csrf_token }} + + {{ admin_form.csrf_token }} +
+
{{ render_menu_with_button(admin_form.user_class) }} - +
-
+ {% if not user.is_active %} +
+
+ {{ admin_form.activate_user(class="btn btn-primary") }} +
+
+ {% endif %} +
{% endif %}
diff --git a/nyaa/views/users.py b/nyaa/views/users.py index 52a67d6..6abca7d 100644 --- a/nyaa/views/users.py +++ b/nyaa/views/users.py @@ -47,20 +47,24 @@ def view_user(user_name): 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(): selection = admin_form.user_class.data - log = None - if selection == 'regular': - user.level = models.UserLevelType.REGULAR - log = "[{}]({}) changed to regular user".format(user_name, url) - elif selection == 'trusted': - user.level = models.UserLevelType.TRUSTED - log = "[{}]({}) changed to trusted user".format(user_name, url) - elif selection == 'moderator': - user.level = models.UserLevelType.MODERATOR - log = "[{}]({}) changed to moderator user".format(user_name, url) + mapping = {'regular': models.UserLevelType.REGULAR, + 'trusted': models.UserLevelType.TRUSTED, + 'moderator': models.UserLevelType.MODERATOR} + + if mapping[selection] != user.level: + user.level = mapping[selection] + log = "[{}]({}) changed to {} user".format(user_name, url, selection) + adminlog = models.AdminLog(log=log, admin_id=flask.g.user.id) + db.session.add(adminlog) + + 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(adminlog) db.session.commit() return flask.redirect(url)