From 7d44379d31f00b33d983bb78ea358794d116a5e2 Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Wed, 11 Dec 2024 23:24:57 -0600 Subject: [PATCH] Deletion handlers: Make protocol implementation explicit; tweak handler check. --- src/codehelp/deletion_handler.py | 4 ++-- src/gened/base.py | 2 +- src/gened/data_deletion.py | 6 +++--- src/starburst/deletion_handler.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/codehelp/deletion_handler.py b/src/codehelp/deletion_handler.py index 01da0f8..d697f3f 100644 --- a/src/codehelp/deletion_handler.py +++ b/src/codehelp/deletion_handler.py @@ -4,11 +4,11 @@ """Implementation of personal data deletion for CodeHelp.""" -from gened.data_deletion import register_handler +from gened.data_deletion import DeletionHandler, register_handler from gened.db import get_db -class CodeHelpDeletionHandler: +class CodeHelpDeletionHandler(DeletionHandler): """CodeHelp implementation of personal data deletion.""" def delete_user_data(self, user_id: int) -> None: diff --git a/src/gened/base.py b/src/gened/base.py index 851a22e..9f0f0e1 100644 --- a/src/gened/base.py +++ b/src/gened/base.py @@ -181,7 +181,7 @@ def create_app_base(import_name: str, app_config: dict[str, Any], instance_path: app.config.from_mapping(total_config) # verify deletion handler is registered - if data_deletion.get_handler() is None: + if not data_deletion.has_handler(): app.logger.error("No deletion handler registered. All Gen-Ed applications must provide one.") sys.exit(1) diff --git a/src/gened/data_deletion.py b/src/gened/data_deletion.py index 5fdccc1..266ab7c 100644 --- a/src/gened/data_deletion.py +++ b/src/gened/data_deletion.py @@ -32,9 +32,9 @@ def register_handler(handler: DeletionHandler) -> None: _handler = handler -def get_handler() -> DeletionHandler | None: - """Get the registered deletion handler.""" - return _handler +def has_handler() -> bool: + """Return whether a deletion handler has been registered (True) or not (False).""" + return _handler is not None def delete_user_data(user_id: int) -> None: diff --git a/src/starburst/deletion_handler.py b/src/starburst/deletion_handler.py index 1f667b2..b6d2df1 100644 --- a/src/starburst/deletion_handler.py +++ b/src/starburst/deletion_handler.py @@ -2,11 +2,11 @@ # # SPDX-License-Identifier: AGPL-3.0-only -from gened.data_deletion import register_handler +from gened.data_deletion import DeletionHandler, register_handler from gened.db import get_db -class StarburstDeletionHandler: +class StarburstDeletionHandler(DeletionHandler): """Handler for deleting Starburst user data.""" def delete_user_data(self, user_id: int) -> None: