Skip to content

Commit

Permalink
Merge pull request #17335 from davelopez/fix_quotas_id_encoding
Browse files Browse the repository at this point in the history
Fix quotas ID encoding
  • Loading branch information
nsoranzo authored Jan 22, 2024
2 parents 6d58253 + 0618dd8 commit a11f77d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/galaxy/quota/_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing_extensions import Literal

from galaxy.schema.fields import (
DecodedDatabaseIdField,
EncodedDatabaseIdField,
ModelClassField,
)
from galaxy.schema.schema import (
Expand Down Expand Up @@ -107,7 +107,7 @@ class QuotaBase(Model, WithModelClass):
"""Base model containing common fields for Quotas."""

model_class: QUOTA = ModelClassField(QUOTA)
id: DecodedDatabaseIdField = Field(
id: EncodedDatabaseIdField = Field(
...,
title="ID",
description="The `encoded identifier` of the quota.",
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/webapps/galaxy/services/quotas.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def index(self, trans: ProvidesUserContext, deleted: bool = False) -> QuotaSumma
encoded_id = Security.security.encode_id(quota.id)
item["url"] = url_for(route, id=encoded_id)
rval.append(item)
return QuotaSummaryList.model_construct(root=rval)
return QuotaSummaryList(root=rval)

def show(self, trans: ProvidesUserContext, id: DecodedDatabaseIdField, deleted: bool = False) -> QuotaDetails:
"""Displays information about a quota."""
quota = self.quota_manager.get_quota(trans, id, deleted=deleted)
rval = quota.to_dict(view="element", value_mapper={"total_disk_usage": float})
return QuotaDetails.model_construct(**rval)
return QuotaDetails(**rval)

def create(self, trans: ProvidesUserContext, params: CreateQuotaParams) -> CreateQuotaResult:
"""Creates a new quota."""
Expand All @@ -71,7 +71,7 @@ def create(self, trans: ProvidesUserContext, params: CreateQuotaParams) -> Creat
item = quota.to_dict()
item["url"] = url_for("quota", id=Security.security.encode_id(quota.id))
item["message"] = message
return CreateQuotaResult.model_construct(**item)
return CreateQuotaResult(**item)

def update(self, trans: ProvidesUserContext, id: DecodedDatabaseIdField, params: UpdateQuotaParams) -> str:
"""Modifies a quota."""
Expand Down
12 changes: 12 additions & 0 deletions test/integration/test_quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ def test_index(self):
json_response = index_response.json()
assert len(json_response) > 0

def test_index_returns_encoded_ids(self):
quota = self._create_quota_with_name("test-index-encoded-quota")
created_quota_id = quota["id"]
index_response = self._get("quotas")
index_response.raise_for_status()
json_response = index_response.json()
assert len(json_response) > 0
quota_ids = [quota["id"] for quota in json_response]
for quota_id in quota_ids:
assert isinstance(quota_id, str)
assert created_quota_id in quota_ids

def test_index_deleted(self):
quota = self._create_quota_with_name("test-index-deleted-quota")
quota_id = quota["id"]
Expand Down

0 comments on commit a11f77d

Please sign in to comment.