#31 API POST Compensation

* adds support for POST of new compensations
* adds shared_users property to BaseObject and Compensation to simplify fetching of shared users (Compensation inherits from intervention)
* extends compensation admin index
* modifies compensation manager which led to invisibility of deleted entries in the admin backend
* fixes bug in sanitize_db.py where CREATED useractions would be removed if they are not found on any log but still are used on the .created attribute of the objects
This commit is contained in:
2022-01-24 14:41:56 +01:00
parent 5ad1b35dc0
commit fa01733815
8 changed files with 237 additions and 10 deletions

View File

@@ -10,6 +10,7 @@ import uuid
from abc import abstractmethod
from django.contrib import messages
from django.db.models import QuerySet
from konova.tasks import celery_send_mail_shared_access_removed, celery_send_mail_shared_access_given, \
celery_send_mail_shared_data_recorded, celery_send_mail_shared_data_unrecorded, \
@@ -124,7 +125,7 @@ class BaseObject(BaseResource):
self.log.add(action)
# Send mail
shared_users = self.users.all().values_list("id", flat=True)
shared_users = self.shared_users.values_list("id", flat=True)
for user_id in shared_users:
celery_send_mail_shared_data_deleted.delay(self.identifier, user_id)
@@ -464,6 +465,15 @@ class ShareableObjectMixin(models.Model):
# Set new shared users
self.share_with_list(users)
@property
def shared_users(self) -> QuerySet:
""" Shortcut for fetching the users which have shared access on this object
Returns:
users (QuerySet)
"""
return self.users.all()
class GeoReferencedMixin(models.Model):
geometry = models.ForeignKey("konova.Geometry", null=True, blank=True, on_delete=models.SET_NULL)