forked from gergely/calendar-social
Make it possible to lock profiles
Locked profiles cannot be followed
This commit is contained in:
@@ -246,6 +246,9 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods
|
||||
#: The display name
|
||||
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
|
||||
def fqn(self):
|
||||
"""The fully qualified name of the profile
|
||||
@@ -290,7 +293,8 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods
|
||||
|
||||
return Profile.query \
|
||||
.join(UserFollow.followed) \
|
||||
.filter(UserFollow.follower == self)
|
||||
.filter(UserFollow.follower == self) \
|
||||
.filter(UserFollow.accepted_at.isnot(None))
|
||||
|
||||
@property
|
||||
def follower_list(self):
|
||||
@@ -303,7 +307,8 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods
|
||||
|
||||
return Profile.query \
|
||||
.join(UserFollow.follower) \
|
||||
.filter(UserFollow.followed == self)
|
||||
.filter(UserFollow.followed == self) \
|
||||
.filter(UserFollow.accepted_at.isnot(None))
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
@@ -324,7 +329,9 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods
|
||||
if not isinstance(follower, Profile):
|
||||
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)
|
||||
notification = self.notify(follower, self, NotificationAction.follow)
|
||||
|
||||
|
Reference in New Issue
Block a user