mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-03 00:31:25 -08:00
account deletion federation #126
This commit is contained in:
parent
e22b3ba4a8
commit
7da8c96677
4 changed files with 22 additions and 12 deletions
|
@ -1,3 +1,4 @@
|
|||
from time import sleep
|
||||
from typing import List, Tuple
|
||||
|
||||
from flask import request, abort, g, current_app, json, flash, render_template
|
||||
|
@ -30,23 +31,24 @@ def unsubscribe_from_everything_then_delete_task(user_id):
|
|||
|
||||
# federate deletion of account
|
||||
if user.is_local():
|
||||
instances = Instance.query.all()
|
||||
site = Site.query.get(1)
|
||||
instances = Instance.query.filter(Instance.dormant == False).all()
|
||||
payload = {
|
||||
"@context": default_context(),
|
||||
"actor": user.ap_profile_id,
|
||||
"id": f"{user.ap_profile_id}#delete",
|
||||
"object": user.ap_profile_id,
|
||||
"actor": user.profile_id(),
|
||||
"id": f"{user.profile_id()}#delete",
|
||||
"object": user.profile_id(),
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"type": "Delete"
|
||||
}
|
||||
for instance in instances:
|
||||
if instance.inbox and instance.id != 1:
|
||||
post_request(instance.inbox, payload, site.private_key,
|
||||
f"https://{current_app.config['SERVER_NAME']}#main-key")
|
||||
if instance.inbox and instance.online() and instance.id != 1: # instance id 1 is always the current instance
|
||||
post_request(instance.inbox, payload, user.private_key, f"{user.profile_id()}#main-key")
|
||||
|
||||
sleep(5)
|
||||
|
||||
user.banned = True
|
||||
user.deleted = True
|
||||
user.delete_dependencies()
|
||||
db.session.commit()
|
||||
|
|
|
@ -39,6 +39,9 @@
|
|||
{{ render_field(form.import_file) }}
|
||||
{{ render_field(form.submit) }}
|
||||
</form>
|
||||
<p class="mt-4 pt-4">
|
||||
<a class="btn btn-warning" href="{{ url_for('user.delete_account') }}">{{ _('Delete account') }}</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -15,7 +15,7 @@ from app.models import Post, Community, CommunityMember, User, PostReply, PostVo
|
|||
InstanceBlock, NotificationSubscription
|
||||
from app.user import bp
|
||||
from app.user.forms import ProfileForm, SettingsForm, DeleteAccountForm, ReportUserForm, FilterEditForm
|
||||
from app.user.utils import purge_user_then_delete
|
||||
from app.user.utils import purge_user_then_delete, unsubscribe_from_community
|
||||
from app.utils import get_setting, render_template, markdown_to_html, user_access, markdown_to_text, shorten_string, \
|
||||
is_image_url, ensure_directory_exists, gibberish, file_get_contents, community_membership, user_filters_home, \
|
||||
user_filters_posts, user_filters_replies, moderating_communities, joined_communities, theme_list, blocked_instances, \
|
||||
|
@ -471,7 +471,7 @@ def delete_account():
|
|||
|
||||
# to verify the deletes, remote servers will GET /u/<actor> so we can't fully delete the account until the POSTs are done
|
||||
current_user.banned = True
|
||||
|
||||
current_user.email = f'deleted_{current_user.id}@deleted.com'
|
||||
db.session.commit()
|
||||
|
||||
if current_app.debug:
|
||||
|
@ -495,7 +495,13 @@ def delete_account():
|
|||
def send_deletion_requests(user_id):
|
||||
user = User.query.get(user_id)
|
||||
if user:
|
||||
instances = Instance.query.all()
|
||||
# unsubscribe
|
||||
communities = CommunityMember.query.filter_by(user_id=user_id).all()
|
||||
for membership in communities:
|
||||
community = Community.query.get(membership.community_id)
|
||||
unsubscribe_from_community(community, user)
|
||||
|
||||
instances = Instance.query.filter(Instance.dormant == False).all()
|
||||
payload = {
|
||||
"@context": default_context(),
|
||||
"actor": user.profile_id(),
|
||||
|
|
|
@ -69,7 +69,6 @@ def purge_user_then_delete_task(user_id):
|
|||
# federate deletion of account
|
||||
if user.is_local():
|
||||
instances = Instance.query.all()
|
||||
site = Site.query.get(1)
|
||||
payload = {
|
||||
"@context": default_context(),
|
||||
"actor": user.ap_profile_id,
|
||||
|
|
Loading…
Add table
Reference in a new issue