kopia lustrzana https://github.com/snarfed/bridgy-fed
don't allow Followers from and to the same protocol
also make from and to requiredcd
rodzic
e6f72f33b6
commit
65e1479d88
11
models.py
11
models.py
|
@ -488,8 +488,8 @@ class Follower(ndb.Model):
|
|||
STATUSES = ('active', 'inactive')
|
||||
|
||||
# these are both subclasses of User
|
||||
from_ = ndb.KeyProperty(name='from')
|
||||
to = ndb.KeyProperty()
|
||||
from_ = ndb.KeyProperty(name='from', required=True)
|
||||
to = ndb.KeyProperty(required=True)
|
||||
|
||||
follow = ndb.KeyProperty(Object) # last follow activity
|
||||
status = ndb.StringProperty(choices=STATUSES, default='active')
|
||||
|
@ -502,6 +502,13 @@ class Follower(ndb.Model):
|
|||
# dest = ndb.StringProperty()
|
||||
# last_follow = JsonProperty()
|
||||
|
||||
def _pre_put_hook(self):
|
||||
if self.from_.kind() == 'Fake' and self.to.kind() == 'Fake':
|
||||
return
|
||||
|
||||
# we're a bridge! stick with bridging.
|
||||
assert self.from_.kind() != self.to.kind(), f'from {self.from_} to {self.to}'
|
||||
|
||||
def _post_put_hook(self, future):
|
||||
logger.info(f'Wrote {self}')
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ from .testutil import Fake, TestCase
|
|||
import common
|
||||
from models import AtpNode, Follower, Object, OBJECT_EXPIRE_AGE, User
|
||||
import protocol
|
||||
from web import Web
|
||||
|
||||
from .test_activitypub import ACTOR
|
||||
|
||||
|
@ -216,6 +217,13 @@ class FollowerTest(TestCase):
|
|||
g.user = self.make_user('foo', cls=Fake)
|
||||
self.other_user = self.make_user('bar', cls=Fake)
|
||||
|
||||
def test_from_to_same_type_fails(self):
|
||||
with self.assertRaises(AssertionError):
|
||||
Follower(from_=Web.key_for('foo'), to=Web.key_for('bar')).put()
|
||||
|
||||
with self.assertRaises(AssertionError):
|
||||
Follower.get_or_create(from_=Web(id='foo'), to=Web(id='bar'))
|
||||
|
||||
def test_get_or_create(self):
|
||||
follower = Follower.get_or_create(from_=g.user, to=self.other_user)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue