2nd
This commit is contained in:
@@ -24,6 +24,8 @@ class TodoItem(db.Model):
|
||||
creator_display_name = db.Column(db.String(128))
|
||||
creator_email = db.Column(db.String(256))
|
||||
starred = db.Column(db.Boolean, default=False)
|
||||
is_public = db.Column(db.Boolean, default=False)
|
||||
tags = db.Column(JSON, default=list)
|
||||
|
||||
# Relationships
|
||||
responsible_users = db.relationship('TodoItemResponsible', back_populates='todo', cascade='all, delete-orphan')
|
||||
@@ -46,6 +48,8 @@ class TodoItem(db.Model):
|
||||
'creator_display_name': self.creator_display_name,
|
||||
'creator_email': self.creator_email,
|
||||
'starred': self.starred,
|
||||
'is_public': self.is_public,
|
||||
'tags': self.tags if self.tags else [],
|
||||
'responsible_users': [r.ad_account for r in self.responsible_users],
|
||||
'followers': [f.ad_account for f in self.followers]
|
||||
}
|
||||
@@ -87,9 +91,21 @@ class TodoItem(db.Model):
|
||||
|
||||
def can_view(self, user_ad):
|
||||
"""Check if user can view this todo"""
|
||||
# Public todos can be viewed by anyone
|
||||
if self.is_public:
|
||||
return True
|
||||
# Private todos can be viewed by creator, responsible users, and followers
|
||||
if self.can_edit(user_ad):
|
||||
return True
|
||||
return any(f.ad_account == user_ad for f in self.followers)
|
||||
|
||||
def can_follow(self, user_ad):
|
||||
"""Check if user can follow this todo"""
|
||||
# Anyone can follow public todos
|
||||
if self.is_public:
|
||||
return True
|
||||
# For private todos, only creator/responsible can add followers
|
||||
return False
|
||||
|
||||
class TodoItemResponsible(db.Model):
|
||||
__tablename__ = 'todo_item_responsible'
|
||||
|
Reference in New Issue
Block a user