From a3c3c142f762d3834491ba0113884f54345099c8 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 12 Jun 2025 12:04:28 +1000 Subject: [PATCH] Optionally exclude session information when exporting data (#9763) * Optionally exclude session information when exporting data * Add sessions.session table --- tasks.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tasks.py b/tasks.py index 03e583f823..3920fc1853 100644 --- a/tasks.py +++ b/tasks.py @@ -274,6 +274,7 @@ def content_excludes( allow_tokens: bool = True, allow_plugins: bool = True, allow_sso: bool = True, + allow_session: bool = True, ): """Returns a list of content types to exclude from import / export. @@ -282,6 +283,7 @@ def content_excludes( allow_tokens (bool): Allow tokens to be exported / imported allow_plugins (bool): Allow plugin information to be exported / imported allow_sso (bool): Allow SSO tokens to be exported / imported + allow_session (bool): Allow user session data to be exported / imported """ excludes = [ 'contenttypes', @@ -320,6 +322,11 @@ def content_excludes( excludes.append('socialaccount.socialapp') excludes.append('socialaccount.socialtoken') + # Optionally exclude user session information + if not allow_session: + excludes.append('sessions.session') + excludes.append('usersessions.usersession') + return ' '.join([f'--exclude {e}' for e in excludes]) @@ -829,6 +836,7 @@ def update( 'include_tokens': 'Include API tokens in the output file (default = False)', 'exclude_plugins': 'Exclude plugin data from the output file (default = False)', 'include_sso': 'Include SSO token data in the output file (default = False)', + 'include_session': 'Include user session data in the output file (default = False)', 'retain_temp': 'Retain temporary files (containing permissions) at end of process (default = False)', } ) @@ -840,6 +848,7 @@ def export_records( include_tokens=False, exclude_plugins=False, include_sso=False, + include_session=False, retain_temp=False, ): """Export all database records to a file. @@ -873,6 +882,7 @@ def export_records( excludes = content_excludes( allow_tokens=include_tokens, allow_plugins=not exclude_plugins, + allow_session=include_session, allow_sso=include_sso, )