forked from gergely/calendar-social
Make it possible to lock profiles
Locked profiles cannot be followed
This commit is contained in:
parent
496b5b6c04
commit
61f10f951c
@ -246,6 +246,9 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods
|
|||||||
#: The display name
|
#: The display name
|
||||||
display_name = db.Column(db.Unicode(length=80), nullable=False)
|
display_name = db.Column(db.Unicode(length=80), nullable=False)
|
||||||
|
|
||||||
|
#: If locked, a profile cannot be followed without the owner’s consent
|
||||||
|
locked = db.Column(db.Boolean(), default=False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fqn(self):
|
def fqn(self):
|
||||||
"""The fully qualified name of the profile
|
"""The fully qualified name of the profile
|
||||||
@ -290,7 +293,8 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods
|
|||||||
|
|
||||||
return Profile.query \
|
return Profile.query \
|
||||||
.join(UserFollow.followed) \
|
.join(UserFollow.followed) \
|
||||||
.filter(UserFollow.follower == self)
|
.filter(UserFollow.follower == self) \
|
||||||
|
.filter(UserFollow.accepted_at.isnot(None))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def follower_list(self):
|
def follower_list(self):
|
||||||
@ -303,7 +307,8 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods
|
|||||||
|
|
||||||
return Profile.query \
|
return Profile.query \
|
||||||
.join(UserFollow.follower) \
|
.join(UserFollow.follower) \
|
||||||
.filter(UserFollow.followed == self)
|
.filter(UserFollow.followed == self) \
|
||||||
|
.filter(UserFollow.accepted_at.isnot(None))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self):
|
def url(self):
|
||||||
@ -324,7 +329,9 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods
|
|||||||
if not isinstance(follower, Profile):
|
if not isinstance(follower, Profile):
|
||||||
raise TypeError('Folloer must be a Profile object')
|
raise TypeError('Folloer must be a Profile object')
|
||||||
|
|
||||||
user_follow = UserFollow(follower=follower, followed=self, accepted_at=datetime.utcnow())
|
timestamp = None if self.locked else datetime.utcnow()
|
||||||
|
|
||||||
|
user_follow = UserFollow(follower=follower, followed=self, accepted_at=timestamp)
|
||||||
db.session.add(user_follow)
|
db.session.add(user_follow)
|
||||||
notification = self.notify(follower, self, NotificationAction.follow)
|
notification = self.notify(follower, self, NotificationAction.follow)
|
||||||
|
|
||||||
|
@ -82,3 +82,36 @@ def test_follow_ui(client):
|
|||||||
assert follow.follower == follower
|
assert follow.follower == follower
|
||||||
assert follow.followed == followed
|
assert follow.followed == followed
|
||||||
assert follow.accepted_at is not None
|
assert follow.accepted_at is not None
|
||||||
|
|
||||||
|
|
||||||
|
def test_locked_profile(database):
|
||||||
|
"""Test following a locked profile
|
||||||
|
"""
|
||||||
|
|
||||||
|
follower_user = User(username='follower',
|
||||||
|
email='follower@example.com',
|
||||||
|
password='passworder',
|
||||||
|
active=True)
|
||||||
|
followed_user = User(username='followed', email='followed@example.com')
|
||||||
|
follower = Profile(display_name='Follower', user=follower_user)
|
||||||
|
followed = Profile(display_name='Followed', user=followed_user, locked=True)
|
||||||
|
db.session.add_all([follower, followed])
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
user_follow = followed.follow(follower=follower)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
# The new follower record should have the fields set correctly
|
||||||
|
assert user_follow.followed == followed
|
||||||
|
assert user_follow.follower == follower
|
||||||
|
assert not user_follow.accepted_at
|
||||||
|
|
||||||
|
# There should be a notification about the follow
|
||||||
|
notification = Notification.query.one()
|
||||||
|
|
||||||
|
assert notification.actor == follower
|
||||||
|
assert notification.item == followed
|
||||||
|
assert notification.action == NotificationAction.follow
|
||||||
|
|
||||||
|
assert follower not in followed.follower_list
|
||||||
|
assert followed not in follower.followed_list
|
||||||
|
Loading…
Reference in New Issue
Block a user