adds store_id for DataAccess

sync3
Laurent 5 months ago
parent 8d1b3dbdc9
commit 9a93e2d6ad
  1. 18
      sync/migrations/0007_dataaccess_store_id.py
  2. 43
      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') shared_with = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='shared_data')
model_name = models.CharField(max_length=50) model_name = models.CharField(max_length=50)
model_id = models.UUIDField() 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) granted_at = models.DateTimeField(auto_now_add=True)
def delete_dependencies(self): def delete_dependencies(self):
@ -35,33 +36,23 @@ class DataAccess(BaseModel):
"""Create an access log for a list of users """ """Create an access log for a list of users """
model_class = model_registry.get_model(self.model_name) model_class = model_registry.get_model(self.model_name)
if model_class: if model_class:
try: for user in users:
obj = model_class.objects.get(id=self.model_id) logger.info(f'=== create ModelLog for: {operation} > {users}')
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()
if existing_log:
existing_log = ModelLog.objects.filter(user=user, model_id=self.model_id, operation=operation).first() existing_log.date = timezone.now()
if existing_log: existing_log.model_operation = operation
existing_log.date = timezone.now() existing_log.save()
existing_log.model_operation = operation else:
existing_log.save() ModelLog.objects.create(
else: user=user,
ModelLog.objects.create( model_id=self.model_id,
user=user, model_name=self.model_name,
model_id=self.model_id, operation=operation,
model_name=self.model_name, date=timezone.now(),
operation=operation, store_id=self.store_id
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
else: else:
logger.warn(f'!!!model not found: {self.model_name}') logger.warn(f'!!!model not found: {self.model_name}')

Loading…
Cancel
Save