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
|
return self.description
|
||||||
else:
|
else:
|
||||||
return f"{self.examination} ({self.plane})"
|
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):
|
def get_full_str(self):
|
||||||
if self.case:
|
if self.case:
|
||||||
|
|||||||
+1
-1
@@ -2740,7 +2740,7 @@ def case_order_dicom(request, pk):
|
|||||||
# TODO: don't try to order non stack series
|
# TODO: don't try to order non stack series
|
||||||
for series in case.series.all():
|
for series in case.series.all():
|
||||||
try:
|
try:
|
||||||
if request.user in series.get_author_objects():
|
if series.check_user_can_edit(request.user):
|
||||||
series.order_by_dicom()
|
series.order_by_dicom()
|
||||||
else:
|
else:
|
||||||
fail.append(f"{series.pk}: invalid permission")
|
fail.append(f"{series.pk}: invalid permission")
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ class AuthorMixin():
|
|||||||
|
|
||||||
return self.author.filter(id=user.id).exists()
|
return self.author.filter(id=user.id).exists()
|
||||||
|
|
||||||
|
def get_author_display(self):
|
||||||
|
return ", ".join([i.username for i in self.get_author_objects()])
|
||||||
|
|
||||||
|
|
||||||
class UserConfigurablePaginationMixin:
|
class UserConfigurablePaginationMixin:
|
||||||
default_per_page = 25
|
default_per_page = 25
|
||||||
|
|||||||
+1
-11
@@ -387,7 +387,7 @@ class SeriesImageBase(models.Model):
|
|||||||
super().save(*args, **kwargs) # Call the "real" save() method.
|
super().save(*args, **kwargs) # Call the "real" save() method.
|
||||||
|
|
||||||
|
|
||||||
class SeriesBase(models.Model):
|
class SeriesBase(models.Model, AuthorMixin):
|
||||||
info = models.TextField(
|
info = models.TextField(
|
||||||
blank=True,
|
blank=True,
|
||||||
help_text="Description of stack, for admin organisation, will not be visible when taking",
|
help_text="Description of stack, for admin organisation, will not be visible when taking",
|
||||||
@@ -444,16 +444,6 @@ class SeriesBase(models.Model):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_author_objects(self):
|
|
||||||
"""Returns a list of authors"""
|
|
||||||
if self.author:
|
|
||||||
return self.author.all()
|
|
||||||
else:
|
|
||||||
return ["None"]
|
|
||||||
|
|
||||||
def get_author_display(self):
|
|
||||||
return ", ".join([i.username for i in self.get_author_objects()])
|
|
||||||
|
|
||||||
def get_examination(self):
|
def get_examination(self):
|
||||||
"""Returns a comma seperated text list of regions"""
|
"""Returns a comma seperated text list of regions"""
|
||||||
return str(self.examination)
|
return str(self.examination)
|
||||||
|
|||||||
Reference in New Issue
Block a user