|
|
|
|
@ -17,6 +17,7 @@ class DataAccess(BaseModel): |
|
|
|
|
shared_with = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='shared_data') |
|
|
|
|
model_name = models.CharField(max_length=50) |
|
|
|
|
model_id = models.UUIDField() |
|
|
|
|
store_id = models.CharField(max_length=100, default="") # a value matching LeStorage directory sub-stores. Matches the name of the directory. |
|
|
|
|
granted_at = models.DateTimeField(auto_now_add=True) |
|
|
|
|
|
|
|
|
|
def delete_dependencies(self): |
|
|
|
|
@ -35,33 +36,23 @@ class DataAccess(BaseModel): |
|
|
|
|
"""Create an access log for a list of users """ |
|
|
|
|
model_class = model_registry.get_model(self.model_name) |
|
|
|
|
if model_class: |
|
|
|
|
try: |
|
|
|
|
obj = model_class.objects.get(id=self.model_id) |
|
|
|
|
store_id = None |
|
|
|
|
if isinstance(obj, SideStoreModel): |
|
|
|
|
store_id = obj.store_id |
|
|
|
|
|
|
|
|
|
for user in users: |
|
|
|
|
for user in users: |
|
|
|
|
logger.info(f'=== create ModelLog for: {operation} > {users}') |
|
|
|
|
|
|
|
|
|
logger.info(f'=== create ModelLog for: {operation} > {users}') |
|
|
|
|
|
|
|
|
|
existing_log = ModelLog.objects.filter(user=user, model_id=self.model_id, operation=operation).first() |
|
|
|
|
if existing_log: |
|
|
|
|
existing_log.date = timezone.now() |
|
|
|
|
existing_log.model_operation = operation |
|
|
|
|
existing_log.save() |
|
|
|
|
else: |
|
|
|
|
ModelLog.objects.create( |
|
|
|
|
user=user, |
|
|
|
|
model_id=self.model_id, |
|
|
|
|
model_name=self.model_name, |
|
|
|
|
operation=operation, |
|
|
|
|
date=timezone.now(), |
|
|
|
|
store_id=store_id |
|
|
|
|
) |
|
|
|
|
except ObjectDoesNotExist: |
|
|
|
|
logger.warn(f'!!! object does not exists any more: {self.model_name} : {self.model_id} : {operation}') |
|
|
|
|
pass |
|
|
|
|
existing_log = ModelLog.objects.filter(user=user, model_id=self.model_id, operation=operation).first() |
|
|
|
|
if existing_log: |
|
|
|
|
existing_log.date = timezone.now() |
|
|
|
|
existing_log.model_operation = operation |
|
|
|
|
existing_log.save() |
|
|
|
|
else: |
|
|
|
|
ModelLog.objects.create( |
|
|
|
|
user=user, |
|
|
|
|
model_id=self.model_id, |
|
|
|
|
model_name=self.model_name, |
|
|
|
|
operation=operation, |
|
|
|
|
date=timezone.now(), |
|
|
|
|
store_id=self.store_id |
|
|
|
|
) |
|
|
|
|
else: |
|
|
|
|
logger.warn(f'!!!model not found: {self.model_name}') |
|
|
|
|
|
|
|
|
|
|