kopia lustrzana https://gitlab.com/marnanel/chapeau
Lists which don't exist, but default to empty, get created on first write.
test_read_from_outbox passes again.2019-08-17
rodzic
eaa8de0771
commit
d65b43e3a9
|
@ -174,7 +174,8 @@ def is_local(url):
|
|||
|
||||
def find(url,
|
||||
local_only=False,
|
||||
do_not_fetch=False):
|
||||
do_not_fetch=False,
|
||||
object_to_store=None):
|
||||
"""
|
||||
Finds an object.
|
||||
|
||||
|
@ -202,7 +203,8 @@ def find(url,
|
|||
is_local = parsed_url.hostname in settings.ALLOWED_HOSTS
|
||||
|
||||
if is_local:
|
||||
return find_local(parsed_url.path)
|
||||
return find_local(parsed_url.path,
|
||||
object_to_store=object_to_store)
|
||||
else:
|
||||
if local_only:
|
||||
logger.info('find: url==%s but is_local==False; ignoring',
|
||||
|
@ -210,4 +212,5 @@ def find(url,
|
|||
return None
|
||||
|
||||
return find_remote(
|
||||
url=url)
|
||||
url=url,
|
||||
do_not_fetch=do_not_fetch)
|
||||
|
|
|
@ -22,7 +22,7 @@ class Activity(thing.Object):
|
|||
def go_into_outbox_if_local(self):
|
||||
|
||||
from django_kepi.models.collection import Collection
|
||||
from django_kepi.find import find_local
|
||||
from django_kepi.find import find
|
||||
|
||||
if not self.is_local:
|
||||
return
|
||||
|
@ -36,7 +36,8 @@ class Activity(thing.Object):
|
|||
outbox_url = actor['outbox']
|
||||
logger.debug(' -- which is %s', outbox_url)
|
||||
|
||||
outbox = find_local(outbox_url,
|
||||
outbox = find(outbox_url,
|
||||
local_only=True,
|
||||
object_to_store=self)
|
||||
|
||||
##############################
|
||||
|
|
|
@ -436,7 +436,29 @@ class UserCollectionView(KepiView):
|
|||
except Collection.DoesNotExist:
|
||||
|
||||
if self._default_to_existing:
|
||||
logger.debug(' -- does not exist; doing nothing')
|
||||
logger.debug(' -- does not exist; creating it')
|
||||
|
||||
try:
|
||||
owner = Actor.objects.get(
|
||||
remote_url = None,
|
||||
f_preferredUsername = username,
|
||||
)
|
||||
except Actor.DoesNotExist:
|
||||
logger.debug(' -- but user %s doesn\'t exist; bailing',
|
||||
username)
|
||||
return
|
||||
|
||||
the_collection = Collection(
|
||||
owner = owner,
|
||||
name = listname)
|
||||
|
||||
the_collection.save()
|
||||
|
||||
the_collection.append(request.activity)
|
||||
|
||||
logger.debug(' -- done: collection is %s',
|
||||
the_collection)
|
||||
|
||||
return
|
||||
else:
|
||||
logger.debug(' -- does not exist; 404')
|
||||
|
@ -517,27 +539,14 @@ class OutboxView(UserCollectionView):
|
|||
|
||||
_default_to_existing = True
|
||||
|
||||
def activity_store(self, request, *args, **kwargs):
|
||||
# XXX this is too similar to the same method
|
||||
# XXX in InboxView; move it into a superclass
|
||||
|
||||
from django_kepi.models.collection import Collection
|
||||
|
||||
inbox_name = Collection.build_name(
|
||||
username = kwargs['username'],
|
||||
collectionname = 'outbox',
|
||||
def activity_store(self, request,
|
||||
username, *args, **kwargs):
|
||||
super().activity_store(
|
||||
request,
|
||||
username = username,
|
||||
listname = 'outbox',
|
||||
)
|
||||
|
||||
inbox = Collection.get(
|
||||
name = inbox_name,
|
||||
create_if_missing = True,
|
||||
)
|
||||
|
||||
logger.debug('%s: storing %s',
|
||||
inbox_name, request.activity)
|
||||
|
||||
inbox.append(request.activity)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
logger.debug('Outbox: received %s',
|
||||
str(request.body, 'UTF-8'))
|
||||
|
|
|
@ -76,6 +76,9 @@ BOOST = {
|
|||
|
||||
class TestOutbox(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
settings.KEPI['LOCAL_OBJECT_HOSTNAME'] = 'testserver'
|
||||
|
||||
# XXX Add a boolean flag about whether to authenticate self
|
||||
def _get(self,
|
||||
url,
|
||||
|
|
Ładowanie…
Reference in New Issue