From d88bb3b62d033a3208232cda5a733fc018b4d726 Mon Sep 17 00:00:00 2001 From: Tillman Date: Mon, 24 Jul 2023 16:51:18 +0200 Subject: [PATCH] Inject QuotaAgent as dependecy and refactor _anon_user_api_value method --- lib/galaxy/webapps/galaxy/services/users.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/services/users.py b/lib/galaxy/webapps/galaxy/services/users.py index 6181593a1539..83d8a47392b7 100644 --- a/lib/galaxy/webapps/galaxy/services/users.py +++ b/lib/galaxy/webapps/galaxy/services/users.py @@ -27,6 +27,7 @@ ) from galaxy.model import User from galaxy.queue_worker import send_local_control_task +from galaxy.quota import QuotaAgent from galaxy.schema import APIKeyModel from galaxy.schema.schema import ( AnonUserModel, @@ -56,12 +57,14 @@ def __init__( api_key_manager: api_keys.ApiKeyManager, user_serializer: UserSerializer, user_deserializer: UserDeserializer, + quota_agent: QuotaAgent, ): super().__init__(security) self.user_manager = user_manager self.api_key_manager = api_key_manager self.user_serializer = user_serializer self.user_deserializer = user_deserializer + self.quota_agent = quota_agent def recalculate_disk_usage( self, @@ -120,8 +123,8 @@ def _anon_user_api_value(self, trans: ProvidesHistoryContext): # Can't return info about this user, may not have a history yet. # return {} raise glx_exceptions.MessageException(err_msg="The user has no history, which should always be the case.") - usage = trans.app.quota_agent.get_usage(trans, history=trans.history) - percent = trans.app.quota_agent.get_percent(trans=trans, usage=usage) + usage = self.quota_agent.get_usage(trans, history=trans.history) + percent = self.quota_agent.get_percent(trans=trans, usage=usage) usage = usage or 0 return { "total_disk_usage": int(usage),