mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Streamline ap routes (part 05: add mods or sticky)
This commit is contained in:
parent
099f073f01
commit
3a9ffa7c53
1 changed files with 47 additions and 38 deletions
|
@ -896,18 +896,29 @@ def process_inbox_request(request_json, store_ap_json):
|
|||
log_incoming_ap(id, APLOG_LOCK, APLOG_FAILURE, request_json if store_ap_json else None, 'Lock: post not found')
|
||||
return
|
||||
|
||||
if request_json['type'] == 'Add': # remote site is adding a local user as a moderator, and is sending directly rather than announcing (happens if not subscribed)
|
||||
if core_activity['type'] == 'Add': # Add mods, or sticky a post
|
||||
mod = user
|
||||
community = find_community(request_json)
|
||||
if not announced:
|
||||
community = find_community(core_activity)
|
||||
if community:
|
||||
if not community.is_moderator(mod) and not community.is_instance_admin(mod):
|
||||
log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Does not have permission')
|
||||
return
|
||||
target = request_json['target']
|
||||
target = core_activity['target']
|
||||
featured_url = community.ap_featured_url
|
||||
moderators_url = community.ap_moderators_url
|
||||
if target == featured_url:
|
||||
post = Post.query.filter_by(ap_id=core_activity['object']).first()
|
||||
if post:
|
||||
post.sticky = True
|
||||
db.session.commit()
|
||||
log_incoming_ap(id, APLOG_ADD, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||
else:
|
||||
log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Cannot find: ' + core_activity['object'])
|
||||
return
|
||||
if target == moderators_url:
|
||||
new_mod = find_actor_or_create(request_json['object'], create_if_not_found=False)
|
||||
if new_mod and new_mod.is_local():
|
||||
new_mod = find_actor_or_create(core_activity['object'])
|
||||
if new_mod:
|
||||
existing_membership = CommunityMember.query.filter_by(community_id=community.id, user_id=new_mod.id).first()
|
||||
if existing_membership:
|
||||
existing_membership.is_moderator = True
|
||||
|
@ -917,10 +928,8 @@ def process_inbox_request(request_json, store_ap_json):
|
|||
db.session.commit()
|
||||
log_incoming_ap(id, APLOG_ADD, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||
else:
|
||||
log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Cannot find: ' + request_json['object'])
|
||||
log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Cannot find: ' + core_activity['object'])
|
||||
return
|
||||
else:
|
||||
# Lemmy might not send anything directly to sticky a post if no-one is subscribed (could not get it to generate the activity)
|
||||
log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Unknown target for Add')
|
||||
else:
|
||||
log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Add: cannot find community')
|
||||
|
@ -1157,35 +1166,35 @@ def process_inbox_request(request_json, store_ap_json):
|
|||
# log_incoming_ap(id, APLOG_LOCK, APLOG_FAILURE, request_json if store_ap_json else None, 'Lock: post not found')
|
||||
# return
|
||||
|
||||
if request_json['object']['type'] == 'Add': # Announce of adding mods or stickying a post
|
||||
target = request_json['object']['target']
|
||||
featured_url = community.ap_featured_url
|
||||
moderators_url = community.ap_moderators_url
|
||||
if target == featured_url:
|
||||
post = Post.query.filter_by(ap_id=request_json['object']['object']).first()
|
||||
if post:
|
||||
post.sticky = True
|
||||
db.session.commit()
|
||||
log_incoming_ap(id, APLOG_ADD, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||
else:
|
||||
log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Cannot find: ' + request_json['object']['object'])
|
||||
return
|
||||
if target == moderators_url:
|
||||
user = find_actor_or_create(request_json['object']['object'])
|
||||
if user:
|
||||
existing_membership = CommunityMember.query.filter_by(community_id=community.id, user_id=user.id).first()
|
||||
if existing_membership:
|
||||
existing_membership.is_moderator = True
|
||||
else:
|
||||
new_membership = CommunityMember(community_id=community.id, user_id=user.id, is_moderator=True)
|
||||
db.session.add(new_membership)
|
||||
db.session.commit()
|
||||
log_incoming_ap(id, APLOG_ADD, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||
else:
|
||||
log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Cannot find: ' + request_json['object']['object'])
|
||||
return
|
||||
log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Unknown target for Add')
|
||||
return
|
||||
#if request_json['object']['type'] == 'Add': # Announce of adding mods or stickying a post
|
||||
# target = request_json['object']['target']
|
||||
# featured_url = community.ap_featured_url
|
||||
# moderators_url = community.ap_moderators_url
|
||||
# if target == featured_url:
|
||||
# post = Post.query.filter_by(ap_id=request_json['object']['object']).first()
|
||||
# if post:
|
||||
# post.sticky = True
|
||||
# db.session.commit()
|
||||
# log_incoming_ap(id, APLOG_ADD, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||
# else:
|
||||
# log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Cannot find: ' + request_json['object']['object'])
|
||||
# return
|
||||
# if target == moderators_url:
|
||||
# user = find_actor_or_create(request_json['object']['object'])
|
||||
# if user:
|
||||
# existing_membership = CommunityMember.query.filter_by(community_id=community.id, user_id=user.id).first()
|
||||
# if existing_membership:
|
||||
# existing_membership.is_moderator = True
|
||||
# else:
|
||||
# new_membership = CommunityMember(community_id=community.id, user_id=user.id, is_moderator=True)
|
||||
# db.session.add(new_membership)
|
||||
# db.session.commit()
|
||||
# log_incoming_ap(id, APLOG_ADD, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||
# else:
|
||||
# log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Cannot find: ' + request_json['object']['object'])
|
||||
# return
|
||||
# log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Unknown target for Add')
|
||||
# return
|
||||
|
||||
if request_json['object']['type'] == 'Remove': # Announce of removing mods or unstickying a post
|
||||
target = request_json['object']['target']
|
||||
|
|
Loading…
Reference in a new issue