36 lines
681 B
Python
36 lines
681 B
Python
def is_admin(user):
|
|
return (
|
|
user.is_authenticated
|
|
and (
|
|
user.is_staff
|
|
or user.is_superuser
|
|
)
|
|
)
|
|
|
|
|
|
def can_edit_note(user, note):
|
|
if not user.is_authenticated:
|
|
return False
|
|
|
|
return (
|
|
is_admin(user)
|
|
or note.author_id == user.id
|
|
)
|
|
|
|
|
|
def can_complete_note(user, note):
|
|
if not user.is_authenticated:
|
|
return False
|
|
|
|
if note.kind != 'task':
|
|
return False
|
|
|
|
return (
|
|
(note.is_public and not note.recipients.exists())
|
|
or is_admin(user)
|
|
or note.author_id == user.id
|
|
or note.recipients.filter(
|
|
pk=user.pk,
|
|
).exists()
|
|
)
|