Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,16 +1032,18 @@ def import_records(

auth_data = []
load_data = []
user_pk_pairing = {}

for entry in data:
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
# Clear out any permissions specified for a user and store the user's primary key for later
if entry['model'] == 'auth.user':
entry['fields']['user_permissions'] = []
user_pk_pairing[entry['fields']['username']] = entry['pk']

# Save auth data for later
if entry['model'].startswith('auth.'):
Expand All @@ -1052,6 +1054,18 @@ def import_records(
warning('WARNING: Invalid entry in data file')
print(entry)

# User profiles should have the same primary key as auth.user, fix this if not the case
for entry in load_data:
if 'model' not in entry or 'fields' not in entry:
continue

if not entry['model'].startswith('users.userprofile'):
continue

user_profile_username = entry['fields']['user'][0]
# Set user profile primary key to corresponding auth.user primary key
entry['pk'] = user_pk_pairing[user_profile_username]

# Write the auth file data
with open(authfile, 'w', encoding='utf-8') as f_out:
f_out.write(json.dumps(auth_data, indent=2))
Expand Down
Loading