Skip to content

Commit

Permalink
Merge pull request #2443 from FJNR-inc/develop
Browse files Browse the repository at this point in the history
new release
  • Loading branch information
MelanieFJNR authored May 24, 2024
2 parents 7e1d4cb + 70f5cb8 commit 4c725db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 9 additions & 0 deletions log_management/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def export_anonymous_chrono_data_all(self, request, queryset):
export_anonymous_chrono_data_all.short_description = \
'export_anonymous_chrono_data_all'

def export_anonymous_chrono_data_selected(self, request, queryset):
targetIds = list(queryset.all().values_list('id', flat=True))
export_anonymous_chrono_data.delay(request.user.id, targetIds=targetIds)


export_anonymous_chrono_data_selected.short_description = \
'export_anonymous_chrono_data_selected'


class LogAdmin(admin.ModelAdmin):
list_display = ('source', 'level', 'error_code', 'message', 'created')
Expand Down Expand Up @@ -61,6 +69,7 @@ class ActionLogAdmin(admin.ModelAdmin):
actions = [
export_anonymous_chrono_data_month,
export_anonymous_chrono_data_all,
export_anonymous_chrono_data_selected,
]
list_display = (
'id',
Expand Down
8 changes: 4 additions & 4 deletions log_management/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,25 @@ class Meta:
verbose_name_plural = _("Action Logs")

@classmethod
def anonymize_data(cls, start_date=None, end_date=None):
def anonymize_data(cls, start_date=None, end_date=None, targetIds=None):
"""
Return a list of dict, one per ActionLog, where any reference to a
user has been modified to a new UUID. We only want either the user
or the session in a user column
:params start_date: date to filter the range
:params end_date: date to filter the range
:params targetIds: a list of ids to filter the data
return nothing but will send an email when export is ready
"""
anonymized_data = []
user_uuid_matching = {}
session_uuid_matching = {}
queryset = cls.objects.filter(id__in=targetIds) if targetIds else cls.objects.all()
if start_date and end_date:
queryset = cls.objects.filter(
queryset = queryset.objects.filter(
created__gte=start_date,
created__lte=end_date,
)
else:
queryset = cls.objects.all()

for action in queryset:
anonymized_action = {}
Expand Down
4 changes: 2 additions & 2 deletions log_management/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@shared_task()
def export_anonymous_chrono_data(admin_id, start_date=None, end_date=None):
def export_anonymous_chrono_data(admin_id, start_date=None, end_date=None, targetIds=None):
"""
Allow an admin to export chrono data between 2 dates.
Data will be anonymized and sent by email to the admin as CSV.
Expand All @@ -26,7 +26,7 @@ def export_anonymous_chrono_data(admin_id, start_date=None, end_date=None):
if end_date : end_date = datetime.datetime.strptime(
end_date, '%Y-%m-%d %H:%M:%S %z')

anonymized_actions = ActionLog.anonymize_data(start_date, end_date)
anonymized_actions = ActionLog.anonymize_data(start_date, end_date, targetIds)

# Create a csv
export_data = []
Expand Down

0 comments on commit 4c725db

Please sign in to comment.