adds store_id for DataAccess

sync3
Laurent 5 months ago
parent 8d1b3dbdc9
commit 9a93e2d6ad
  1. 18
      sync/migrations/0007_dataaccess_store_id.py
  2. 13
      sync/models/data_access.py

@ -0,0 +1,18 @@
# Generated by Django 5.1 on 2025-06-12 13:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sync', '0006_alter_modellog_operation'),
]
operations = [
migrations.AddField(
model_name='dataaccess',
name='store_id',
field=models.CharField(default='', max_length=100),
),
]

@ -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,14 +36,7 @@ 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:
logger.info(f'=== create ModelLog for: {operation} > {users}')
existing_log = ModelLog.objects.filter(user=user, model_id=self.model_id, operation=operation).first()
@ -57,11 +51,8 @@ class DataAccess(BaseModel):
model_name=self.model_name,
operation=operation,
date=timezone.now(),
store_id=store_id
store_id=self.store_id
)
except ObjectDoesNotExist:
logger.warn(f'!!! object does not exists any more: {self.model_name} : {self.model_id} : {operation}')
pass
else:
logger.warn(f'!!!model not found: {self.model_name}')

Loading…
Cancel
Save