Put user last accessed updating behind a feature flag

This commit is contained in:
Joseph Schorr 2019-01-02 13:46:28 -05:00
parent a6b5b4d6e3
commit 4ba4d9141b
5 changed files with 22 additions and 4 deletions

View file

@ -550,3 +550,6 @@ class DefaultConfig(ImmutableConfig):
# Defines the maximum number of pages the user can paginate before they are limited # Defines the maximum number of pages the user can paginate before they are limited
SEARCH_MAX_RESULT_PAGE_COUNT = 10 SEARCH_MAX_RESULT_PAGE_COUNT = 10
# Feature Flag: Whether to record when users were last accessed.
FEATURE_USER_LAST_ACCESSED = True

View file

@ -162,6 +162,9 @@ def calculate_image_aggregate_size(ancestors_str, image_size, parent_image):
def update_last_accessed(token_or_user): def update_last_accessed(token_or_user):
""" Updates the `last_accessed` field on the given token or user. If the existing field's value """ 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. """ 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)) threshold = timedelta(seconds=config.app_config.get('LAST_ACCESSED_UPDATE_THRESHOLD_S', 120))
if (token_or_user.last_accessed is not None and if (token_or_user.last_accessed is not None and
datetime.utcnow() - token_or_user.last_accessed < threshold): datetime.utcnow() - token_or_user.last_accessed < threshold):

View file

@ -1,3 +1,5 @@
import features
from app import avatar from app import avatar
from data import model from data import model
from data.database import User, FederatedLogin, Team as TeamTable, Repository, RobotAccountMetadata from data.database import User, FederatedLogin, Team as TeamTable, Repository, RobotAccountMetadata
@ -25,7 +27,8 @@ class RobotPreOCIModel(RobotInterface):
'name': robot_name, 'name': robot_name,
'token': robot_tuple.get(FederatedLogin.service_ident) if include_token else None, 'token': robot_tuple.get(FederatedLogin.service_ident) if include_token else None,
'created': robot_tuple.get(User.creation_date), '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), 'description': robot_tuple.get(RobotAccountMetadata.description),
'unstructured_metadata': robot_tuple.get(RobotAccountMetadata.unstructured_json), 'unstructured_metadata': robot_tuple.get(RobotAccountMetadata.unstructured_json),
} }
@ -58,7 +61,8 @@ class RobotPreOCIModel(RobotInterface):
robot_dict['repositories'].append(repository_name) robot_dict['repositories'].append(repository_name)
robots[robot_name] = RobotWithPermissions(robot_dict['name'], robot_dict['token'], robots[robot_name] = RobotWithPermissions(robot_dict['name'], robot_dict['token'],
robot_dict['created'], robot_dict['created'],
robot_dict['last_accessed'], (robot_dict['last_accessed']
if features.USER_LAST_ACCESSED else None),
robot_dict['teams'], robot_dict['teams'],
robot_dict['repositories'], robot_dict['repositories'],
robot_dict['description']) robot_dict['description'])

View file

@ -44,7 +44,8 @@
<td ng-class="TableService.tablePredicateClass('created_datetime', options.predicate, options.reverse)"> <td ng-class="TableService.tablePredicateClass('created_datetime', options.predicate, options.reverse)">
<a ng-click="TableService.orderBy('created_datetime', options)">Created</a> <a ng-click="TableService.orderBy('created_datetime', options)">Created</a>
</td> </td>
<td ng-class="TableService.tablePredicateClass('last_accessed_datetime', options.predicate, options.reverse)"> <td ng-class="TableService.tablePredicateClass('last_accessed_datetime', options.predicate, options.reverse)"
quay-show="Features.USER_LAST_ACCESSED">
<a ng-click="TableService.orderBy('last_accessed_datetime', options)">Last Accessed</a> <a ng-click="TableService.orderBy('last_accessed_datetime', options)">Last Accessed</a>
</td> </td>
<td class="options-col"></td> <td class="options-col"></td>
@ -92,7 +93,7 @@
<td> <td>
<time-ago datetime="robotInfo.created"></time-ago> <time-ago datetime="robotInfo.created"></time-ago>
</td> </td>
<td> <td quay-show="Features.USER_LAST_ACCESSED">
<time-ago datetime="robotInfo.last_accessed"></time-ago> <time-ago datetime="robotInfo.last_accessed"></time-ago>
</td> </td>
<td class="options-col"> <td class="options-col">

View file

@ -784,6 +784,13 @@ CONFIG_SCHEMA = {
'pattern': '^[0-9]+(w|m|d|h|s)$', '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 Flag: Permanent Sessions.
'FEATURE_PERMANENT_SESSIONS': { 'FEATURE_PERMANENT_SESSIONS': {
'type': 'boolean', 'type': 'boolean',