Skip to content

Commit

Permalink
Inject QuotaAgent as dependecy and refactor _anon_user_api_value method
Browse files Browse the repository at this point in the history
  • Loading branch information
heisner-tillman committed Jul 29, 2023
1 parent 9d139fd commit d88bb3b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/galaxy/webapps/galaxy/services/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit d88bb3b

Please sign in to comment.