From cf3dec5768d12e116477968d867f63d2b134162a Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Tue, 4 Jun 2024 09:44:10 +1200 Subject: [PATCH] profile_id or user_name.lower() everywhere #194 --- app/activitypub/routes.py | 14 +++++++------- app/activitypub/util.py | 2 +- app/admin/routes.py | 1 + app/cli.py | 4 ++-- app/community/routes.py | 6 +++--- app/models.py | 2 +- app/templates/base.html | 4 ++-- app/templates/user/_user_nav.html | 2 +- app/templates/user/filters.html | 2 +- app/templates/user/notifications.html | 2 +- app/templates/user/show_profile.html | 2 +- app/topic/routes.py | 2 +- app/user/routes.py | 10 +++++----- app/user/utils.py | 2 +- app/utils.py | 2 +- 15 files changed, 29 insertions(+), 28 deletions(-) diff --git a/app/activitypub/routes.py b/app/activitypub/routes.py index 52918213..8d99def9 100644 --- a/app/activitypub/routes.py +++ b/app/activitypub/routes.py @@ -255,17 +255,17 @@ def user_profile(actor): server = current_app.config['SERVER_NAME'] actor_data = { "@context": default_context(), "type": "Person" if not user.bot else "Service", - "id": f"https://{server}/u/{actor}", - "preferredUsername": actor, + "id": f"https://{server}/u/{actor.lower()}", + "preferredUsername": actor.lower(), "name": user.title if user.title else user.user_name, - "inbox": f"https://{server}/u/{actor}/inbox", - "outbox": f"https://{server}/u/{actor}/outbox", + "inbox": f"https://{server}/u/{actor.lower()}/inbox", + "outbox": f"https://{server}/u/{actor.lower()}/outbox", "discoverable": user.searchable, "indexable": user.indexable, "manuallyApprovesFollowers": False if not user.ap_manually_approves_followers else user.ap_manually_approves_followers, "publicKey": { - "id": f"https://{server}/u/{actor}#main-key", - "owner": f"https://{server}/u/{actor}", + "id": f"https://{server}/u/{actor.lower()}#main-key", + "owner": f"https://{server}/u/{actor.lower()}", "publicKeyPem": user.public_key # .replace("\n", "\\n") #LOOKSWRONG }, "endpoints": { @@ -1390,7 +1390,7 @@ def process_user_follow_request(request_json, activitypublog_id, remote_user_id) "type": "Accept", "id": f"https://{current_app.config['SERVER_NAME']}/activities/accept/" + gibberish(32) } - if post_request(remote_user.ap_inbox_url, accept, local_user.private_key, f"https://{current_app.config['SERVER_NAME']}/u/{local_user.user_name}#main-key"): + if post_request(remote_user.ap_inbox_url, accept, local_user.private_key, f"{local_user.profile_id()}#main-key"): activity_log.result = 'success' else: activity_log.exception_message = 'Error sending Accept' diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 773783ca..74776ab3 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -496,7 +496,7 @@ def refresh_user_profile_task(user_id): {'user_id': user.id, 'indexable': new_indexable}) - user.user_name = activity_json['preferredUsername'] + user.user_name = activity_json['preferredUsername'].lower() if 'name' in activity_json: user.title = activity_json['name'] user.about_html = parse_summary(activity_json) diff --git a/app/admin/routes.py b/app/admin/routes.py index 6faa4f5d..54d676d1 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -726,6 +726,7 @@ def admin_users_add(): user = User() if form.validate_on_submit(): user.user_name = form.user_name.data + user.title = form.user_name.data user.set_password(form.password.data) user.about = form.about.data user.email = form.email.data diff --git a/app/cli.py b/app/cli.py index 7680ee29..eb9eb0c3 100644 --- a/app/cli.py +++ b/app/cli.py @@ -158,9 +158,9 @@ def register(app): admin_user.roles.append(admin_role) admin_user.verified = True admin_user.last_seen = utcnow() - admin_user.ap_profile_id = f"https://{current_app.config['SERVER_NAME']}/u/{admin_user.user_name}" + admin_user.ap_profile_id = f"https://{current_app.config['SERVER_NAME']}/u/{admin_user.user_name.lower()}" admin_user.ap_public_url = f"https://{current_app.config['SERVER_NAME']}/u/{admin_user.user_name}" - admin_user.ap_inbox_url = f"https://{current_app.config['SERVER_NAME']}/u/{admin_user.user_name}/inbox" + admin_user.ap_inbox_url = f"https://{current_app.config['SERVER_NAME']}/u/{admin_user.user_name.lower()}/inbox" db.session.add(admin_user) db.session.commit() diff --git a/app/community/routes.py b/app/community/routes.py index 4ff97afd..5d40ae36 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -386,7 +386,7 @@ def subscribe(actor): db.session.add(join_request) db.session.commit() follow = { - "actor": f"https://{current_app.config['SERVER_NAME']}/u/{current_user.user_name}", + "actor": current_user.profile_id(), "to": [community.ap_profile_id], "object": community.ap_profile_id, "type": "Follow", @@ -426,7 +426,7 @@ def unsubscribe(actor): if '@' in actor: # this is a remote community, so activitypub is needed undo_id = f"https://{current_app.config['SERVER_NAME']}/activities/undo/" + gibberish(15) follow = { - "actor": f"https://{current_app.config['SERVER_NAME']}/u/{current_user.user_name}", + "actor": current_user.profile_id(), "to": [community.ap_profile_id], "object": community.ap_profile_id, "type": "Follow", @@ -478,7 +478,7 @@ def join_then_add(actor): db.session.add(join_request) db.session.commit() follow = { - "actor": f"https://{current_app.config['SERVER_NAME']}/u/{current_user.user_name}", + "actor": current_user.profile_id(), "to": [community.ap_profile_id], "object": community.ap_profile_id, "type": "Follow", diff --git a/app/models.py b/app/models.py index e2075c94..ac30fa65 100644 --- a/app/models.py +++ b/app/models.py @@ -836,7 +836,7 @@ class User(UserMixin, db.Model): join(CommunityMember).filter(CommunityMember.is_banned == False, CommunityMember.user_id == self.id).all() def profile_id(self): - result = self.ap_profile_id if self.ap_profile_id else f"https://{current_app.config['SERVER_NAME']}/u/{self.user_name}" + result = self.ap_profile_id if self.ap_profile_id else f"https://{current_app.config['SERVER_NAME']}/u/{self.user_name.lower()}" return result def public_url(self): diff --git a/app/templates/base.html b/app/templates/base.html index 67772d3c..65ce463e 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -192,9 +192,9 @@