diff --git a/config.py b/config.py index 856bb20d5..4d78b1abf 100644 --- a/config.py +++ b/config.py @@ -550,3 +550,6 @@ class DefaultConfig(ImmutableConfig): # Defines the maximum number of pages the user can paginate before they are limited SEARCH_MAX_RESULT_PAGE_COUNT = 10 + + # Feature Flag: Whether to record when users were last accessed. + FEATURE_USER_LAST_ACCESSED = True diff --git a/data/model/_basequery.py b/data/model/_basequery.py index a0b0c2d8a..0e20a516c 100644 --- a/data/model/_basequery.py +++ b/data/model/_basequery.py @@ -162,6 +162,9 @@ def calculate_image_aggregate_size(ancestors_str, image_size, parent_image): def update_last_accessed(token_or_user): """ Updates the `last_accessed` field on the given token or user. If the existing field's value is within the configured threshold, the update is skipped. """ + if not config.app_config.get('FEATURE_USER_LAST_ACCESSED'): + return + threshold = timedelta(seconds=config.app_config.get('LAST_ACCESSED_UPDATE_THRESHOLD_S', 120)) if (token_or_user.last_accessed is not None and datetime.utcnow() - token_or_user.last_accessed < threshold): diff --git a/endpoints/api/robot_models_pre_oci.py b/endpoints/api/robot_models_pre_oci.py index 6f5396440..20cd83bf1 100644 --- a/endpoints/api/robot_models_pre_oci.py +++ b/endpoints/api/robot_models_pre_oci.py @@ -1,3 +1,5 @@ +import features + from app import avatar from data import model from data.database import User, FederatedLogin, Team as TeamTable, Repository, RobotAccountMetadata @@ -25,7 +27,8 @@ class RobotPreOCIModel(RobotInterface): 'name': robot_name, 'token': robot_tuple.get(FederatedLogin.service_ident) if include_token else None, 'created': robot_tuple.get(User.creation_date), - 'last_accessed': robot_tuple.get(User.last_accessed), + 'last_accessed': (robot_tuple.get(User.last_accessed) + if features.USER_LAST_ACCESSED else None), 'description': robot_tuple.get(RobotAccountMetadata.description), 'unstructured_metadata': robot_tuple.get(RobotAccountMetadata.unstructured_json), } @@ -58,7 +61,8 @@ class RobotPreOCIModel(RobotInterface): robot_dict['repositories'].append(repository_name) robots[robot_name] = RobotWithPermissions(robot_dict['name'], robot_dict['token'], robot_dict['created'], - robot_dict['last_accessed'], + (robot_dict['last_accessed'] + if features.USER_LAST_ACCESSED else None), robot_dict['teams'], robot_dict['repositories'], robot_dict['description']) diff --git a/static/directives/robots-manager.html b/static/directives/robots-manager.html index 87f041afe..d2a265247 100644 --- a/static/directives/robots-manager.html +++ b/static/directives/robots-manager.html @@ -44,7 +44,8 @@ Created - + Last Accessed @@ -92,7 +93,7 @@ - + diff --git a/util/config/schema.py b/util/config/schema.py index 684d07d17..64226fc4e 100644 --- a/util/config/schema.py +++ b/util/config/schema.py @@ -784,6 +784,13 @@ CONFIG_SCHEMA = { 'pattern': '^[0-9]+(w|m|d|h|s)$', }, + # Feature Flag: User last accessed. + 'FEATURE_USER_LAST_ACCESSED': { + 'type': 'boolean', + 'description': 'Whether to record the last time a user was accessed. Defaults to True', + 'x-example': True, + }, + # Feature Flag: Permanent Sessions. 'FEATURE_PERMANENT_SESSIONS': { 'type': 'boolean',