|
|
|
|
@ -313,53 +313,6 @@ class UserDataAccessApi(HierarchyApiView): |
|
|
|
|
'message': str(e) |
|
|
|
|
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # Get all GRANT_ACCESS and REVOKE_ACCESS logs for the user, ordered by date |
|
|
|
|
# all_logs = ModelLog.objects.filter( |
|
|
|
|
# Q(users=request.user) & |
|
|
|
|
# (Q(operation='GRANT_ACCESS') | Q(operation='REVOKE_ACCESS')) |
|
|
|
|
# ).order_by('date') |
|
|
|
|
|
|
|
|
|
# # Track latest status for each (model_name, model_id) |
|
|
|
|
# active_grants = {} |
|
|
|
|
|
|
|
|
|
# # Process logs chronologically to determine current access state |
|
|
|
|
# for log in all_logs: |
|
|
|
|
# if log.operation == 'GRANT_ACCESS': |
|
|
|
|
# active_grants[log.model_id] = log |
|
|
|
|
# elif log.operation == 'REVOKE_ACCESS': |
|
|
|
|
# if log.model_id in active_grants and active_grants[log.model_id].date < log.date: |
|
|
|
|
# del active_grants[log.model_id] |
|
|
|
|
|
|
|
|
|
# # Convert active_grants dict to list of grant logs |
|
|
|
|
# active_grants = list(active_grants.values()) |
|
|
|
|
|
|
|
|
|
# def _add_children_recursively(self, instance, data_dict): |
|
|
|
|
# """ |
|
|
|
|
# Recursively add all children of an instance to the data dictionary. |
|
|
|
|
# """ |
|
|
|
|
# child_models = instance.get_children_by_model() |
|
|
|
|
|
|
|
|
|
# for child_model_name, children in child_models.items(): |
|
|
|
|
# for child in children: |
|
|
|
|
# if isinstance(child, BaseModel): |
|
|
|
|
# serializer = get_serializer(child, child_model_name) |
|
|
|
|
# data_dict[child_model_name][child.id] = serializer.data |
|
|
|
|
# self._add_children_recursively(child, data_dict) |
|
|
|
|
|
|
|
|
|
# def _add_parents_recursively(self, instance, data_dict): |
|
|
|
|
# """ |
|
|
|
|
# Recursively add all parents of an instance to the data dictionary. |
|
|
|
|
# """ |
|
|
|
|
# parent_models = instance.get_parents_by_model() |
|
|
|
|
|
|
|
|
|
# for parent_model_name, parent in parent_models.items(): |
|
|
|
|
# if isinstance(parent, BaseModel): |
|
|
|
|
# serializer = get_serializer(parent, parent_model_name) |
|
|
|
|
# data_dict[parent_model_name][parent.id] = serializer.data |
|
|
|
|
# self._add_parents_recursively(parent, data_dict) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DataAccessViewSet(viewsets.ModelViewSet): |
|
|
|
|
queryset = DataAccess.objects.all() |
|
|
|
|
serializer_class = DataAccessSerializer |
|
|
|
|
|