Fixes person/author confusion and public keys
This commit is contained in:
		@@ -42,6 +42,9 @@ class Signature:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def naive_parse(activity_objects, activity_json):
 | 
					def naive_parse(activity_objects, activity_json):
 | 
				
			||||||
    ''' this navigates circular import issues '''
 | 
					    ''' this navigates circular import issues '''
 | 
				
			||||||
 | 
					    if activity_json.get('publicKeyPem'):
 | 
				
			||||||
 | 
					        # ugh
 | 
				
			||||||
 | 
					        activity_json['type'] = 'PublicKey'
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        activity_type = activity_json['type']
 | 
					        activity_type = activity_json['type']
 | 
				
			||||||
        serializer = activity_objects[activity_type]
 | 
					        serializer = activity_objects[activity_type]
 | 
				
			||||||
@@ -82,7 +85,6 @@ class ActivityObject:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def to_model(self, model=None, instance=None, allow_create=True, save=True):
 | 
					    def to_model(self, model=None, instance=None, allow_create=True, save=True):
 | 
				
			||||||
        ''' convert from an activity to a model instance '''
 | 
					        ''' convert from an activity to a model instance '''
 | 
				
			||||||
        # figure out the right model -- wish I had a better way for this
 | 
					 | 
				
			||||||
        model = model or get_model_from_type(self.type)
 | 
					        model = model or get_model_from_type(self.type)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # only reject statuses if we're potentially creating them
 | 
					        # only reject statuses if we're potentially creating them
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -67,4 +67,4 @@ class Author(ActivityObject):
 | 
				
			|||||||
    librarythingKey: str = ''
 | 
					    librarythingKey: str = ''
 | 
				
			||||||
    goodreadsKey: str = ''
 | 
					    goodreadsKey: str = ''
 | 
				
			||||||
    wikipediaLink: str = ''
 | 
					    wikipediaLink: str = ''
 | 
				
			||||||
    type: str = 'Person'
 | 
					    type: str = 'Author'
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -391,6 +391,9 @@ class Inbox(TestCase):
 | 
				
			|||||||
                name='hi', remote_id='https://example.com/list/22',
 | 
					                name='hi', remote_id='https://example.com/list/22',
 | 
				
			||||||
                user=self.local_user)
 | 
					                user=self.local_user)
 | 
				
			||||||
        activity = {
 | 
					        activity = {
 | 
				
			||||||
 | 
					            'type': 'Update',
 | 
				
			||||||
 | 
					            'to': [], 'cc': [], 'actor': 'hi',
 | 
				
			||||||
 | 
					            'id': 'sdkjf',
 | 
				
			||||||
            'object': {
 | 
					            'object': {
 | 
				
			||||||
                "id": "https://example.com/list/22",
 | 
					                "id": "https://example.com/list/22",
 | 
				
			||||||
                "type": "BookList",
 | 
					                "type": "BookList",
 | 
				
			||||||
@@ -617,11 +620,16 @@ class Inbox(TestCase):
 | 
				
			|||||||
        self.local_user.save()
 | 
					        self.local_user.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        datafile = pathlib.Path(__file__).parent.joinpath(
 | 
					        datafile = pathlib.Path(__file__).parent.joinpath(
 | 
				
			||||||
            'data/ap_user.json')
 | 
					            '../data/ap_user.json')
 | 
				
			||||||
        userdata = json.loads(datafile.read_bytes())
 | 
					        userdata = json.loads(datafile.read_bytes())
 | 
				
			||||||
        del userdata['icon']
 | 
					        del userdata['icon']
 | 
				
			||||||
        self.assertIsNone(self.local_user.name)
 | 
					        self.assertIsNone(self.local_user.name)
 | 
				
			||||||
        views.inbox.activity_task({'object': userdata})
 | 
					        views.inbox.activity_task({
 | 
				
			||||||
 | 
					            'type': 'Update',
 | 
				
			||||||
 | 
					            'to': [], 'cc': [], 'actor': 'hi',
 | 
				
			||||||
 | 
					            'id': 'sdkjf',
 | 
				
			||||||
 | 
					            'object': userdata
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
        user = models.User.objects.get(id=self.local_user.id)
 | 
					        user = models.User.objects.get(id=self.local_user.id)
 | 
				
			||||||
        self.assertEqual(user.name, 'MOUSE?? MOUSE!!')
 | 
					        self.assertEqual(user.name, 'MOUSE?? MOUSE!!')
 | 
				
			||||||
        self.assertEqual(user.username, 'mouse@example.com')
 | 
					        self.assertEqual(user.username, 'mouse@example.com')
 | 
				
			||||||
@@ -631,7 +639,7 @@ class Inbox(TestCase):
 | 
				
			|||||||
    def test_handle_update_edition(self):
 | 
					    def test_handle_update_edition(self):
 | 
				
			||||||
        ''' update an existing edition '''
 | 
					        ''' update an existing edition '''
 | 
				
			||||||
        datafile = pathlib.Path(__file__).parent.joinpath(
 | 
					        datafile = pathlib.Path(__file__).parent.joinpath(
 | 
				
			||||||
            'data/bw_edition.json')
 | 
					            '../data/bw_edition.json')
 | 
				
			||||||
        bookdata = json.loads(datafile.read_bytes())
 | 
					        bookdata = json.loads(datafile.read_bytes())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        models.Work.objects.create(
 | 
					        models.Work.objects.create(
 | 
				
			||||||
@@ -644,7 +652,12 @@ class Inbox(TestCase):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        with patch(
 | 
					        with patch(
 | 
				
			||||||
                'bookwyrm.activitypub.base_activity.set_related_field.delay'):
 | 
					                'bookwyrm.activitypub.base_activity.set_related_field.delay'):
 | 
				
			||||||
            views.inbox.activity_task({'object': bookdata})
 | 
					            views.inbox.activity_task({
 | 
				
			||||||
 | 
					                'type': 'Update',
 | 
				
			||||||
 | 
					                'to': [], 'cc': [], 'actor': 'hi',
 | 
				
			||||||
 | 
					                'id': 'sdkjf',
 | 
				
			||||||
 | 
					                'object': bookdata
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
        book = models.Edition.objects.get(id=book.id)
 | 
					        book = models.Edition.objects.get(id=book.id)
 | 
				
			||||||
        self.assertEqual(book.title, 'Piranesi')
 | 
					        self.assertEqual(book.title, 'Piranesi')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -652,7 +665,7 @@ class Inbox(TestCase):
 | 
				
			|||||||
    def test_handle_update_work(self):
 | 
					    def test_handle_update_work(self):
 | 
				
			||||||
        ''' update an existing edition '''
 | 
					        ''' update an existing edition '''
 | 
				
			||||||
        datafile = pathlib.Path(__file__).parent.joinpath(
 | 
					        datafile = pathlib.Path(__file__).parent.joinpath(
 | 
				
			||||||
            'data/bw_work.json')
 | 
					            '../data/bw_work.json')
 | 
				
			||||||
        bookdata = json.loads(datafile.read_bytes())
 | 
					        bookdata = json.loads(datafile.read_bytes())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        book = models.Work.objects.create(
 | 
					        book = models.Work.objects.create(
 | 
				
			||||||
@@ -662,7 +675,12 @@ class Inbox(TestCase):
 | 
				
			|||||||
        self.assertEqual(book.title, 'Test Book')
 | 
					        self.assertEqual(book.title, 'Test Book')
 | 
				
			||||||
        with patch(
 | 
					        with patch(
 | 
				
			||||||
                'bookwyrm.activitypub.base_activity.set_related_field.delay'):
 | 
					                'bookwyrm.activitypub.base_activity.set_related_field.delay'):
 | 
				
			||||||
            views.inbox.activity_task({'object': bookdata})
 | 
					            views.inbox.activity_task({
 | 
				
			||||||
 | 
					                'type': 'Update',
 | 
				
			||||||
 | 
					                'to': [], 'cc': [], 'actor': 'hi',
 | 
				
			||||||
 | 
					                'id': 'sdkjf',
 | 
				
			||||||
 | 
					                'object': bookdata
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
        book = models.Work.objects.get(id=book.id)
 | 
					        book = models.Work.objects.get(id=book.id)
 | 
				
			||||||
        self.assertEqual(book.title, 'Piranesi')
 | 
					        self.assertEqual(book.title, 'Piranesi')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user