mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
profile_id or user_name.lower() everywhere #194
This commit is contained in:
parent
82704ae421
commit
cf3dec5768
15 changed files with 29 additions and 28 deletions
|
@ -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'
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -192,9 +192,9 @@
|
|||
</ul>
|
||||
</li>
|
||||
<li class="nav-item dropdown{% if active_parent == 'account' %} active{% endif %}">
|
||||
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="/u/{{ current_user.user_name }}" aria-haspopup="true" aria-expanded="false">{{ _('Account') }}</a>
|
||||
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="/u/{{ current_user.user_name.lower() }}" aria-haspopup="true" aria-expanded="false">{{ _('Account') }}</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item{% if active_child == 'view_profile' %} active{% endif %}" href="/u/{{ current_user.user_name }}">{{ _('View profile') }}</a></li>
|
||||
<li><a class="dropdown-item{% if active_child == 'view_profile' %} active{% endif %}" href="/u/{{ current_user.user_name.lower() }}">{{ _('View profile') }}</a></li>
|
||||
<li><a class="dropdown-item{% if active_child == 'edit_profile' %} active{% endif %}" href="/user/settings">{{ _('Edit profile & settings') }}</a></li>
|
||||
<li><a class="dropdown-item{% if active_child == 'chats' %} active{% endif %}" href="/chat">{{ _('Chats') }}</a></li>
|
||||
</ul>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<a href="/user/settings" class="btn {{ 'btn-primary' if request.path == '/user/settings' else 'btn-outline-secondary' }}">
|
||||
{{ _('Settings') }}
|
||||
</a>
|
||||
<a href="/u/{{ current_user.user_name }}/profile" class="btn {{ 'btn-primary' if request.path.endswith('/profile') else 'btn-outline-secondary' }}">
|
||||
<a href="/u/{{ current_user.user_name.lower() }}/profile" class="btn {{ 'btn-primary' if request.path.endswith('/profile') else 'btn-outline-secondary' }}">
|
||||
{{ _('Profile') }}
|
||||
</a>
|
||||
<a href="/user/settings/filters" class="btn {{ 'btn-primary' if request.path == '/user/settings/filters' else 'btn-outline-secondary' }}">
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
</tr>
|
||||
{% for user in blocked_users %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('activitypub.user_profile', actor=user.ap_id if user.ap_id is not none else user.user_name) }}">{{ user.display_name() }}</a></td>
|
||||
<td><a href="{{ url_for('activitypub.user_profile', actor=user.ap_id if user.ap_id is not none else user.user_name.lower()) }}">{{ user.display_name() }}</a></td>
|
||||
<td><a class="no-underline confirm_first" href="{{ url_for('user.unblock_profile', actor=user.link()) }}" rel="nofollow"><span class="fe fe-delete"> {{ _('Unblock') }}</span></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<a class="w-100 btn btn-primary" href="/u/{{ current_user.user_name }}/profile">{{ _('Profile') }}</a>
|
||||
<a class="w-100 btn btn-primary" href="/u/{{ current_user.user_name.lower() }}/profile">{{ _('Profile') }}</a>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<a class="w-100 btn btn-primary" href="/user/settings">{{ _('Settings') }}</a>
|
||||
|
|
|
@ -151,7 +151,7 @@
|
|||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<a class="w-100 btn btn-primary" href="/u/{{ user.user_name }}/profile">{{ _('Profile') }}</a>
|
||||
<a class="w-100 btn btn-primary" href="/u/{{ user.user_name.lower() }}/profile">{{ _('Profile') }}</a>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<a class="w-100 btn btn-primary" href="/user/settings">{{ _('Settings') }}</a>
|
||||
|
|
|
@ -273,7 +273,7 @@ def send_community_follow(community_id, join_request_id, user_id):
|
|||
user = User.query.get(user_id)
|
||||
community = Community.query.get(community_id)
|
||||
follow = {
|
||||
"actor": f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name}",
|
||||
"actor": current_user.profile_id(),
|
||||
"to": [community.ap_profile_id],
|
||||
"object": community.ap_profile_id,
|
||||
"type": "Follow",
|
||||
|
|
|
@ -704,7 +704,7 @@ def import_settings_task(user_id, filename):
|
|||
db.session.add(join_request)
|
||||
db.session.commit()
|
||||
follow = {
|
||||
"actor": f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name}",
|
||||
"actor": current_user.profile_id(),
|
||||
"to": [community.ap_profile_id],
|
||||
"object": community.ap_profile_id,
|
||||
"type": "Follow",
|
||||
|
@ -875,16 +875,16 @@ def fediverse_redirect(actor):
|
|||
if form.validate_on_submit():
|
||||
redirect_url = ''
|
||||
if form.instance_type.data == 'mastodon':
|
||||
redirect_url = f'https://{form.instance_url.data}/@{user.user_name}@{current_app.config["SERVER_NAME"]}'
|
||||
redirect_url = f'https://{form.instance_url.data}/@{user.user_name.lower()}@{current_app.config["SERVER_NAME"]}'
|
||||
elif form.instance_type.data == 'lemmy':
|
||||
flash(_("Lemmy can't follow profiles, sorry"), 'error')
|
||||
return render_template('user/fediverse_redirect.html', form=form, user=user, send_to='', current_app=current_app)
|
||||
elif form.instance_type.data == 'friendica':
|
||||
redirect_url = f'https://{form.instance_url.data}/search?q={user.user_name}@{current_app.config["SERVER_NAME"]}'
|
||||
redirect_url = f'https://{form.instance_url.data}/search?q={user.user_name.lower()}@{current_app.config["SERVER_NAME"]}'
|
||||
elif form.instance_type.data == 'hubzilla':
|
||||
redirect_url = f'https://{form.instance_url.data}/search?q={user.user_name}@{current_app.config["SERVER_NAME"]}'
|
||||
redirect_url = f'https://{form.instance_url.data}/search?q={user.user_name.lower()}@{current_app.config["SERVER_NAME"]}'
|
||||
elif form.instance_type.data == 'pixelfed':
|
||||
redirect_url = f'https://{form.instance_url.data}/i/results?q={user.user_name}@{current_app.config["SERVER_NAME"]}'
|
||||
redirect_url = f'https://{form.instance_url.data}/i/results?q={user.user_name.lower()}@{current_app.config["SERVER_NAME"]}'
|
||||
|
||||
resp = make_response(redirect(redirect_url))
|
||||
resp.set_cookie('remote_instance_url', form.instance_url.data, expires=datetime(year=2099, month=12, day=30))
|
||||
|
|
|
@ -93,7 +93,7 @@ def purge_user_then_delete_task(user_id):
|
|||
def unsubscribe_from_community(community, user):
|
||||
undo_id = f"https://{current_app.config['SERVER_NAME']}/activities/undo/" + gibberish(15)
|
||||
follow = {
|
||||
"actor": f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name}",
|
||||
"actor": user.profile_id(),
|
||||
"to": [community.ap_profile_id],
|
||||
"object": community.ap_profile_id,
|
||||
"type": "Follow",
|
||||
|
|
|
@ -753,7 +753,7 @@ def finalize_user_setup(user, application_required=False):
|
|||
user.public_key = public_key
|
||||
user.ap_profile_id = f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name}".lower()
|
||||
user.ap_public_url = f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name}"
|
||||
user.ap_inbox_url = f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name}/inbox"
|
||||
user.ap_inbox_url = f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name.lower()}/inbox"
|
||||
db.session.commit()
|
||||
send_welcome_email(user, application_required)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue