From 706aa6fb49a87bfbf7c5b93726107d0e6802a5f0 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 7 Feb 2024 11:22:33 +0000 Subject: [PATCH 1/2] Update tasks.py - Exclude temporary settings when exporting data --- tasks.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tasks.py b/tasks.py index 39bd16a4590..c09cf8f26ff 100644 --- a/tasks.py +++ b/tasks.py @@ -504,8 +504,25 @@ def export_records( with open(tmpfile, 'r') as f_in: data = json.loads(f_in.read()) + data_out = [] + if include_permissions is False: for entry in data: + model_name = entry.get('model', None) + + # Ignore any temporary settings (start with underscore) + if model_name in ['common.inventreesetting', 'common.inventreeusersetting']: + if entry['fields'].get('key', '').startswith('_'): + continue + + if model_name == 'auth.group': + entry['fields']['permissions'] = [] + + if model_name == 'auth.user': + entry['fields']['user_permissions'] = [] + + data_out.append(entry) + if 'model' in entry: # Clear out any permissions specified for a group if entry['model'] == 'auth.group': @@ -517,7 +534,7 @@ def export_records( # Write the processed data to file with open(filename, 'w') as f_out: - f_out.write(json.dumps(data, indent=2)) + f_out.write(json.dumps(data_out, indent=2)) print('Data export completed') From 489199743d467353a9428903a0012087f7ee1db9 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 7 Feb 2024 11:43:59 +0000 Subject: [PATCH 2/2] Remove duplicate code --- tasks.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tasks.py b/tasks.py index c09cf8f26ff..2ca62f074d2 100644 --- a/tasks.py +++ b/tasks.py @@ -523,15 +523,6 @@ def export_records( data_out.append(entry) - if 'model' in entry: - # Clear out any permissions specified for a group - if entry['model'] == 'auth.group': - entry['fields']['permissions'] = [] - - # Clear out any permissions specified for a user - if entry['model'] == 'auth.user': - entry['fields']['user_permissions'] = [] - # Write the processed data to file with open(filename, 'w') as f_out: f_out.write(json.dumps(data_out, indent=2))