Updates for broadcast changes

This commit is contained in:
Mouse Reeve 2020-05-13 18:23:54 -07:00
parent e76f96eb6c
commit 3e02123a0d
3 changed files with 11 additions and 11 deletions

View file

@ -86,9 +86,9 @@ def shared_inbox(request):
def get_public_key(key_actor):
try:
user = models.User.objects.get(actor=key_actor)
user = models.User.objects.get(remote_id=key_actor)
public_key = user.public_key
actor = user.actor
actor = user.remote_id
except models.User.DoesNotExist:
response = requests.get(
key_actor,
@ -149,7 +149,7 @@ def handle_follow(activity):
# figure out who they want to follow -- not using get_or_create because
# we only allow you to follow local users
try:
to_follow = models.User.objects.get(actor=activity['object'])
to_follow = models.User.objects.get(remote_id=activity['object'])
except models.User.DoesNotExist:
return False
# figure out who the actor is
@ -189,7 +189,7 @@ def handle_unfollow(activity):
obj = activity['object']
try:
requester = get_or_create_remote_user(obj['actor'])
to_unfollow = models.User.objects.get(actor=obj['object'])
to_unfollow = models.User.objects.get(remote_id=obj['object'])
except models.User.DoesNotExist:
return False
@ -200,7 +200,7 @@ def handle_unfollow(activity):
def handle_follow_accept(activity):
''' hurray, someone remote accepted a follow request '''
# figure out who they want to follow
requester = models.User.objects.get(actor=activity['object']['actor'])
requester = models.User.objects.get(remote_id=activity['object']['actor'])
# figure out who they are
accepter = get_or_create_remote_user(activity['actor'])
@ -218,7 +218,7 @@ def handle_follow_accept(activity):
@app.task
def handle_follow_reject(activity):
''' someone is rejecting a follow request '''
requester = models.User.objects.get(actor=activity['object']['actor'])
requester = models.User.objects.get(remote_id=activity['object']['actor'])
rejecter = get_or_create_remote_user(activity['actor'])
try:

View file

@ -22,10 +22,10 @@ class FedireadsModel(models.Model):
abstract = True
@receiver(models.signals.post_save, sender=FedireadsModel)
@receiver(models.signals.post_save)
def execute_after_save(sender, instance, created, *args, **kwargs):
''' set the remote_id after save (when the id is available) '''
if not created:
if not created or not hasattr(instance, 'get_remote_id'):
return
instance.remote_id = instance.get_remote_id()
instance.save()

View file

@ -14,7 +14,7 @@ from fedireads.broadcast import make_signature
from fedireads.activitypub import get_follow_request
from fedireads.settings import DOMAIN
Sender = namedtuple('Sender', ('actor', 'private_key', 'public_key'))
Sender = namedtuple('Sender', ('remote_id', 'private_key', 'public_key'))
class Signature(TestCase):
def setUp(self):
@ -67,7 +67,7 @@ class Signature(TestCase):
def test_remote_signer(self):
responses.add(
responses.GET,
self.fake_remote.actor,
self.fake_remote.remote_id,
json={'publicKey': {
'publicKeyPem': self.fake_remote.public_key
}},
@ -82,7 +82,7 @@ class Signature(TestCase):
def test_nonexistent_signer(self):
responses.add(
responses.GET,
self.fake_remote.actor,
self.fake_remote.remote_id,
json={'error': 'not found'},
status=404)