Add user permission checks for series editing and enhance author display method
This commit is contained in:
@@ -1047,6 +1047,27 @@ class Series(SeriesBase):
|
||||
return self.description
|
||||
else:
|
||||
return f"{self.examination} ({self.plane})"
|
||||
|
||||
def user_can_edit(self, user, allow_if_can_edit_cases=True) -> bool:
|
||||
"""Check if the user can edit the series.
|
||||
|
||||
Args:
|
||||
user (User): The user to check.
|
||||
Returns:
|
||||
bool: True if the user can edit the series, False otherwise.
|
||||
"""
|
||||
if user.is_superuser:
|
||||
return True
|
||||
|
||||
if self.author.filter(id=user.id).exists():
|
||||
return True
|
||||
|
||||
if allow_if_can_edit_cases:
|
||||
# Check if user can edit any of the cases this series is in
|
||||
for case in self.case.all():
|
||||
if case.check_user_can_edit(user):
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_full_str(self):
|
||||
if self.case:
|
||||
|
||||
Reference in New Issue
Block a user