mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-03 00:31:25 -08:00
Merge pull request 'Local Only Communities' (#165) from freamon/pyfedi:reject_follows into main
Reviewed-on: https://codeberg.org/rimu/pyfedi/pulls/165
This commit is contained in:
commit
aff00042c7
1 changed files with 26 additions and 2 deletions
|
@ -514,6 +514,11 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
|
|||
db.session.commit()
|
||||
return
|
||||
community = find_actor_or_create(community_ap_id, community_only=True)
|
||||
if community and community.local_only:
|
||||
activity_log.exception_message = 'Remote Create in local_only community'
|
||||
activity_log.result = 'ignored'
|
||||
db.session.commit()
|
||||
return
|
||||
user = find_actor_or_create(user_ap_id)
|
||||
if (user and not user.is_local()) and community:
|
||||
user.last_seen = community.last_active = site.last_active = utcnow()
|
||||
|
@ -774,9 +779,28 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
|
|||
follow_id = request_json['id']
|
||||
user = find_actor_or_create(user_ap_id)
|
||||
community = find_actor_or_create(community_ap_id, community_only=True)
|
||||
if community and community.local_only:
|
||||
# todo: send Deny activity
|
||||
if community and community.local_only and user:
|
||||
activity_log.exception_message = 'Local only cannot be followed by remote users'
|
||||
|
||||
# send reject message to deny the follow
|
||||
reject = {
|
||||
"@context": default_context(),
|
||||
"actor": community.ap_profile_id,
|
||||
"to": [
|
||||
user.ap_profile_id
|
||||
],
|
||||
"object": {
|
||||
"actor": user.ap_profile_id,
|
||||
"to": None,
|
||||
"object": community.ap_profile_id,
|
||||
"type": "Follow",
|
||||
"id": follow_id
|
||||
},
|
||||
"type": "Reject",
|
||||
"id": f"https://{current_app.config['SERVER_NAME']}/activities/reject/" + gibberish(32)
|
||||
}
|
||||
# Lemmy doesn't yet understand Reject/Follow, so send without worrying about response for now.
|
||||
post_request(user.ap_inbox_url, reject, community.private_key, f"https://{current_app.config['SERVER_NAME']}/c/{community.name}#main-key")
|
||||
else:
|
||||
if user is not None and community is not None:
|
||||
# check if user is banned from this community
|
||||
|
|
Loading…
Add table
Reference in a new issue