From 8dfd5c407d6539c55b93fe0d32fe74df3b1509b1 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 2 Sep 2023 22:34:29 +0100 Subject: [PATCH] Readd "Sync with Forums" button to profile picture settings --- app/blueprints/users/profile.py | 23 ++++++++++++++++++++++- app/tasks/forumtasks.py | 4 ++-- app/templates/users/profile_edit.html | 9 ++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/blueprints/users/profile.py b/app/blueprints/users/profile.py index b4cad6ca..6e1cdc05 100644 --- a/app/blueprints/users/profile.py +++ b/app/blueprints/users/profile.py @@ -22,8 +22,10 @@ from flask_babel import gettext from flask_login import current_user, login_required from sqlalchemy import func, text -from app.models import User, db, Package, PackageReview, PackageState, PackageType +from app.models import User, db, Package, PackageReview, PackageState, PackageType, UserRank from app.utils import get_daterange_options +from app.tasks.forumtasks import check_forum_account + from . import bp @@ -235,6 +237,25 @@ def profile(username): medals_unlocked=unlocked, medals_locked=locked) +@bp.route("/users//check-forums/", methods=["POST"]) +@login_required +def user_check_forums(username): + user = User.query.filter_by(username=username).first() + if user is None: + abort(404) + + if current_user != user and not current_user.rank.atLeast(UserRank.MODERATOR): + abort(403) + + if user.forums_username is None: + abort(404) + + task = check_forum_account.delay(user.forums_username, force_replace_pic=True) + next_url = url_for("users.profile", username=username) + + return redirect(url_for("tasks.check", id=task.id, r=next_url)) + + @bp.route("/user/stats/") @login_required def statistics_redirect(): diff --git a/app/tasks/forumtasks.py b/app/tasks/forumtasks.py index c5569db8..f7c3e52d 100644 --- a/app/tasks/forumtasks.py +++ b/app/tasks/forumtasks.py @@ -28,7 +28,7 @@ from .usertasks import set_profile_picture_from_url @celery.task() -def check_forum_account(forums_username): +def check_forum_account(forums_username, force_replace_pic=False): print("### Checking " + forums_username, file=sys.stderr) try: profile = get_profile("https://forum.minetest.net", forums_username) @@ -69,7 +69,7 @@ def check_forum_account(forums_username): print(f"####### User pp {user.profile_pic}", file=sys.stderr) pic_needs_replacing = user.profile_pic is None or user.profile_pic == "" or \ - user.profile_pic.startswith("https://forum.minetest.net") + user.profile_pic.startswith("https://forum.minetest.net") or force_replace_pic if pic_needs_replacing and pic.startswith("https://forum.minetest.net"): print(f"####### Queueing", file=sys.stderr) set_profile_picture_from_url.delay(user.username, pic) diff --git a/app/templates/users/profile_edit.html b/app/templates/users/profile_edit.html index c2436423..63c1d6ab 100644 --- a/app/templates/users/profile_edit.html +++ b/app/templates/users/profile_edit.html @@ -21,7 +21,14 @@ {% endif %}
- {% if user.email %} + {% if user.forums_username %} +
+ + +
+ {% endif %} + {% if user.profile_pic %} + {% elif user.email %} Gravatar