-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DON'T MERGE] LITE-29320 LITE-29322 Draft for XVS extension enhanced filtering and … #138
Closed
+120
−23
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,155 @@ | ||
from typing import List, Optional | ||
|
||
|
||
from pydantic import BaseModel | ||
from pydantic import BaseModel, validator | ||
from fastapi_filter import FilterDepends, with_prefix | ||
from fastapi_filter.contrib.sqlalchemy import Filter | ||
|
||
from connect_ext_ppr.models.deployment import ( | ||
Deployment, DeploymentRequest, MarketplaceConfiguration, | ||
) | ||
from connect_ext_ppr.models.ppr import PPRVersion | ||
from connect_ext_ppr.models.replicas import Product, Account | ||
from connect_ext_ppr.models.task import Task | ||
|
||
|
||
# TODO: Make mixin | ||
def restrict_sortable_fields_base(value, allowed_field_names): | ||
if value is None: | ||
return None | ||
|
||
for field_name in value: | ||
field_name = field_name.replace("+", "").replace("-", "") # | ||
|
||
if field_name not in allowed_field_names: | ||
raise ValueError(f"You may only sort by: {', '.join(allowed_field_names)}") | ||
|
||
return value | ||
|
||
|
||
class ProductFilter(Filter): | ||
name: Optional[str] | ||
name__ilike: Optional[str] | ||
|
||
class Constants(Filter.Constants): | ||
model = Product | ||
|
||
|
||
class VendorFilter(Filter): | ||
name: Optional[str] | ||
name__ilike: Optional[str] | ||
|
||
class Constants(Filter.Constants): | ||
model = Account | ||
|
||
|
||
class DeploymentFilter(Filter): | ||
id: Optional[str] | ||
hub_id: Optional[str] | ||
hub__name: Optional[str] # custom filter | ||
hub__name__like: Optional[str] # custom filter | ||
product_id: Optional[str] | ||
product: Optional[ProductFilter] = FilterDepends(with_prefix('product', ProductFilter)) | ||
status: Optional[str] | ||
vendor_id: Optional[str] | ||
vendor: Optional[VendorFilter] = FilterDepends(with_prefix('vendor', VendorFilter)) | ||
|
||
order_by: Optional[list[str]] | ||
custom_order_by: Optional[str] | ||
|
||
@validator("order_by") | ||
@classmethod | ||
def restrict_sortable_fields(cls, value): | ||
return restrict_sortable_fields_base(value, ['id', 'product_id']) | ||
|
||
@validator("hub__name", "hub__name__like", "custom_order_by") | ||
@classmethod | ||
def validate_hub_name(cls, value): | ||
pass | ||
|
||
class Constants(Filter.Constants): | ||
model = Deployment | ||
|
||
|
||
class PPRVersionFilter(Filter): | ||
id: Optional[str] | ||
version: Optional[int] | ||
status: Optional[str] | ||
description: Optional[str] | ||
description__ilike: Optional[str] | ||
|
||
order_by: Optional[List[str]] | ||
|
||
@validator("order_by") | ||
@classmethod | ||
def restrict_sortable_fields(cls, value): | ||
return restrict_sortable_fields_base(value, ['version']) | ||
|
||
class Constants(Filter.Constants): | ||
model = PPRVersion | ||
|
||
|
||
class DeploymentRequestFilter(Filter): | ||
status: Optional[str] | ||
delegate_l2: Optional[bool] | ||
|
||
"""For specific deployment""" | ||
id: Optional[str] | ||
manually: Optional[bool] | ||
ppr: Optional[PPRVersionFilter] = FilterDepends(with_prefix('ppr', PPRVersionFilter)) | ||
status: Optional[str] | ||
|
||
order_by: Optional[List[str]] | ||
|
||
@validator("order_by") | ||
@classmethod | ||
def restrict_sortable_fields(cls, value): | ||
return restrict_sortable_fields_base(value, ['id']) | ||
|
||
class Constants(Filter.Constants): | ||
model = DeploymentRequest | ||
|
||
|
||
class DeploymentRequestExtendedFilter(DeploymentRequestFilter): | ||
"""For all deployments""" | ||
delegate_l2: Optional[bool] | ||
|
||
deployment_id: Optional[str] | ||
deployment: Optional[DeploymentFilter] = FilterDepends( | ||
with_prefix('deployment', DeploymentFilter), | ||
) | ||
|
||
@validator("order_by") | ||
@classmethod | ||
def restrict_sortable_fields(cls, value): | ||
return restrict_sortable_fields_base(value, ['id', 'deployment_id']) | ||
|
||
|
||
class MarketplaceConfigurationFilter(Filter): | ||
"""For specific DeploymentRequest""" | ||
marketplace: Optional[str] | ||
ppr: Optional[PPRVersionFilter] = FilterDepends(with_prefix('ppr', PPRVersionFilter)) | ||
|
||
order_by: Optional[List[str]] | ||
|
||
class Constants(Filter.Constants): | ||
model = MarketplaceConfiguration | ||
|
||
|
||
class DeploymentRequestExtendedFilter(DeploymentRequestFilter): | ||
id: Optional[str] | ||
|
||
deployment: Optional[DeploymentFilter] = FilterDepends( | ||
with_prefix('deployment', DeploymentFilter), | ||
) | ||
|
||
class Constants(Filter.Constants): | ||
model = DeploymentRequest | ||
class MarketplaceConfigurationExtendedFilter(MarketplaceConfigurationFilter): | ||
"""For Deployment""" | ||
ppr: Optional[PPRVersionFilter] = FilterDepends(with_prefix('ppr', PPRVersionFilter)) | ||
|
||
|
||
class PricingBatchFilter(BaseModel): | ||
marketplace_id: Optional[str] | ||
|
||
|
||
class TaskFilter(Filter): | ||
id: Optional[str] | ||
status: Optional[str] | ||
|
||
order_by: Optional[List[str]] | ||
|
||
@validator("order_by") | ||
@classmethod | ||
def restrict_sortable_fields(cls, value): | ||
return restrict_sortable_fields_base(value, ['id']) | ||
|
||
class Constants(Filter.Constants): | ||
model = Task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a cost of custom cases