mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Streamline ap routes (part 15: filter out activities that are both sent direct and Announced)
This commit is contained in:
parent
f82c2fe9b4
commit
7942793c20
2 changed files with 17 additions and 15 deletions
|
@ -427,9 +427,11 @@ def shared_inbox():
|
||||||
log_incoming_ap(id, APLOG_DUPLICATE, APLOG_IGNORED, request_json if store_ap_json else None, 'Activity about local content which is already present')
|
log_incoming_ap(id, APLOG_DUPLICATE, APLOG_IGNORED, request_json if store_ap_json else None, 'Activity about local content which is already present')
|
||||||
return '', 200
|
return '', 200
|
||||||
|
|
||||||
|
id = object['id']
|
||||||
|
|
||||||
redis_client = get_redis_connection()
|
redis_client = get_redis_connection()
|
||||||
if redis_client.exists(id): # Something is sending same activity multiple times
|
if redis_client.exists(id): # Something is sending same activity multiple times
|
||||||
log_incoming_ap(id, APLOG_DUPLICATE, APLOG_IGNORED, request_json if store_ap_json else None, 'Unnecessary retry attempt')
|
log_incoming_ap(id, APLOG_DUPLICATE, APLOG_IGNORED, request_json if store_ap_json else None, 'Already aware of this activity')
|
||||||
return '', 200
|
return '', 200
|
||||||
redis_client.set(id, 1, ex=90) # Save the activity ID into redis, to avoid duplicate activities
|
redis_client.set(id, 1, ex=90) # Save the activity ID into redis, to avoid duplicate activities
|
||||||
|
|
||||||
|
@ -631,7 +633,7 @@ def process_inbox_request(request_json, store_ap_json):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# Now that we have the community and the user from an Announce, we can save repeating code by removing it
|
# Now that we have the community and the user from an Announce, we can save repeating code by removing it
|
||||||
# core_activity is checked for its Type, but request_json is passed to any other functions
|
# core_activity is checked for its Type, but the original request_json is sometimes passed to any other functions
|
||||||
announced = True
|
announced = True
|
||||||
core_activity = request_json['object']
|
core_activity = request_json['object']
|
||||||
else:
|
else:
|
||||||
|
@ -990,7 +992,7 @@ def process_inbox_request(request_json, store_ap_json):
|
||||||
Is Announced if a remote Admin or Mod is banning a remote user from one of their communities (a remote user could also be one of our local users)
|
Is Announced if a remote Admin or Mod is banning a remote user from one of their communities (a remote user could also be one of our local users)
|
||||||
(e.g. lemmy.ml is banning piefed.social/u/troll or lemmy.world/u/troll from lemmy.ml/c/memes)
|
(e.g. lemmy.ml is banning piefed.social/u/troll or lemmy.world/u/troll from lemmy.ml/c/memes)
|
||||||
|
|
||||||
Same activity can be sent direct and Announced, but one will be filtered out when shared_inbox() checks for it as a duplicate (TODO, when the 'streamline ap routes' process is complete)
|
Same activity can be sent direct and Announced, but one will be filtered out when shared_inbox() checks for it as a duplicate
|
||||||
|
|
||||||
We currently don't receive a Block if a remote Admin is banning a user of a different instance from their site (it's hacked by all the relevant communities Announcing a community ban)
|
We currently don't receive a Block if a remote Admin is banning a user of a different instance from their site (it's hacked by all the relevant communities Announcing a community ban)
|
||||||
This may change in the future, so it's something to monitor
|
This may change in the future, so it's something to monitor
|
||||||
|
@ -1045,7 +1047,7 @@ def process_inbox_request(request_json, store_ap_json):
|
||||||
|
|
||||||
if remove_data:
|
if remove_data:
|
||||||
community_ban_remove_data(blocker.id, community.id, blocked)
|
community_ban_remove_data(blocker.id, community.id, blocked)
|
||||||
ban_user(blocker, blocked, community, request_json)
|
ban_user(blocker, blocked, community, core_activity)
|
||||||
log_incoming_ap(id, APLOG_USERBAN, APLOG_SUCCESS, request_json if store_ap_json else None)
|
log_incoming_ap(id, APLOG_USERBAN, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -1171,7 +1173,7 @@ def process_inbox_request(request_json, store_ap_json):
|
||||||
log_incoming_ap(id, APLOG_USERBAN, APLOG_FAILURE, request_json if store_ap_json else None, 'Does not have permission')
|
log_incoming_ap(id, APLOG_USERBAN, APLOG_FAILURE, request_json if store_ap_json else None, 'Does not have permission')
|
||||||
return
|
return
|
||||||
|
|
||||||
unban_user(unblocker, unblocked, community, request_json)
|
unban_user(unblocker, unblocked, community, core_activity)
|
||||||
log_incoming_ap(id, APLOG_USERBAN, APLOG_SUCCESS, request_json if store_ap_json else None)
|
log_incoming_ap(id, APLOG_USERBAN, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -1512,19 +1512,19 @@ def community_ban_remove_data(blocker_id, community_id, blocked):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
def ban_user(blocker, blocked, community, request_json):
|
def ban_user(blocker, blocked, community, core_activity):
|
||||||
existing = CommunityBan.query.filter_by(community_id=community.id, user_id=blocked.id).first()
|
existing = CommunityBan.query.filter_by(community_id=community.id, user_id=blocked.id).first()
|
||||||
if not existing:
|
if not existing:
|
||||||
new_ban = CommunityBan(community_id=community.id, user_id=blocked.id, banned_by=blocker.id)
|
new_ban = CommunityBan(community_id=community.id, user_id=blocked.id, banned_by=blocker.id)
|
||||||
if 'summary' in request_json['object']:
|
if 'summary' in core_activity:
|
||||||
new_ban.reason=request_json['object']['summary']
|
reason = core_activity['summary']
|
||||||
reason = request_json['object']['summary']
|
|
||||||
else:
|
else:
|
||||||
reason = ''
|
reason = ''
|
||||||
if 'expires' in request_json and datetime.fromisoformat(request_json['object']['expires']) > datetime.now(timezone.utc):
|
new_ban.reason = reason
|
||||||
new_ban.ban_until = datetime.fromisoformat(request_json['object']['expires'])
|
if 'expires' in core_activity and datetime.fromisoformat(core_activity['expires']) > datetime.now(timezone.utc):
|
||||||
elif 'endTime' in request_json and datetime.fromisoformat(request_json['object']['endTime']) > datetime.now(timezone.utc):
|
new_ban.ban_until = core_activity['expires']
|
||||||
new_ban.ban_until = datetime.fromisoformat(request_json['object']['endTime'])
|
elif 'endTime' in core_activity and datetime.fromisoformat(core_activity['endTime']) > datetime.now(timezone.utc):
|
||||||
|
new_ban.ban_until = core_activity['endTime']
|
||||||
db.session.add(new_ban)
|
db.session.add(new_ban)
|
||||||
|
|
||||||
community_membership_record = CommunityMember.query.filter_by(community_id=community.id, user_id=blocked.id).first()
|
community_membership_record = CommunityMember.query.filter_by(community_id=community.id, user_id=blocked.id).first()
|
||||||
|
@ -1556,8 +1556,8 @@ def ban_user(blocker, blocked, community, request_json):
|
||||||
add_to_modlog_activitypub('ban_user', blocker, community_id=community.id, link_text=blocked.display_name(), link=f'u/{blocked.link()}', reason=reason)
|
add_to_modlog_activitypub('ban_user', blocker, community_id=community.id, link_text=blocked.display_name(), link=f'u/{blocked.link()}', reason=reason)
|
||||||
|
|
||||||
|
|
||||||
def unban_user(blocker, blocked, community, request_json):
|
def unban_user(blocker, blocked, community, core_activity):
|
||||||
reason = request_json['object']['summary'] if 'summary' in request_json['object'] else ''
|
reason = core_activity['summary'] if 'summary' in core_activity else ''
|
||||||
db.session.query(CommunityBan).filter(CommunityBan.community_id == community.id, CommunityBan.user_id == blocked.id).delete()
|
db.session.query(CommunityBan).filter(CommunityBan.community_id == community.id, CommunityBan.user_id == blocked.id).delete()
|
||||||
community_membership_record = CommunityMember.query.filter_by(community_id=community.id, user_id=blocked.id).first()
|
community_membership_record = CommunityMember.query.filter_by(community_id=community.id, user_id=blocked.id).first()
|
||||||
if community_membership_record:
|
if community_membership_record:
|
||||||
|
|
Loading…
Add table
Reference in a new issue