-
Notifications
You must be signed in to change notification settings - Fork 48
feat: allow update of parent asset on UI #1957
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
Open
joshuaunity
wants to merge
15
commits into
main
Choose a base branch
from
feat/allow-update-of-parentasset-on-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c397dea
feat: alloow update of parent asst on UI
joshuaunity 09f6189
Merge branch 'main' into feat/allow-update-of-parentasset-on-ui
joshuaunity 0dfca88
refactor: add order to query for fetching all accounts assets to prop…
joshuaunity e6cb96d
Merge branch 'feat/allow-update-of-parentasset-on-ui' of github.com:F…
joshuaunity 53d87c5
fix: fixed issue where you cant update an asset properties if the use…
joshuaunity ac916eb
fix: fixed validation logic with edgecase causing test to fail
joshuaunity 7dc4678
fix: fixed another edge case with existing name validator
joshuaunity eafa38a
fix: final fix v1.0
joshuaunity 72a916e
fix: final fix v2.0
joshuaunity 9f87a5a
Merge branch 'main' into feat/allow-update-of-parentasset-on-ui
joshuaunity 5c140d2
fix: final fix v2.1
joshuaunity 61ff39d
Merge branch 'main' into feat/allow-update-of-parentasset-on-ui
joshuaunity e07e02f
feat: remove current asset form parent list
joshuaunity 49d5813
feat: validation for parent asset id while updating
joshuaunity 3b391fe
Merge branch 'main' into feat/allow-update-of-parentasset-on-ui
joshuaunity 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 hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -209,17 +209,23 @@ def validate_name_is_unique_under_parent(self, data, **kwargs): | |
| Here, we can only check if we have all information (a full form), | ||
| which usually is at creation time. | ||
| """ | ||
| if "name" in data and "parent_asset_id" in data: | ||
| asset = db.session.scalars( | ||
| select(GenericAsset) | ||
| .filter_by( | ||
| name=data["name"], | ||
| parent_asset_id=data.get("parent_asset_id"), | ||
| ) | ||
| .limit(1) | ||
| ).first() | ||
|
|
||
| if asset: | ||
| if "name" in data: | ||
| parent_id = data.get("parent_asset_id", None) | ||
|
|
||
| query = select(GenericAsset).filter_by( | ||
| name=data["name"], | ||
| parent_asset_id=parent_id, | ||
| ) | ||
|
|
||
| current_editing_id = getattr(self, "context", {}).get("asset_id") | ||
|
|
||
| if current_editing_id is not None: | ||
| query = query.filter(GenericAsset.id != current_editing_id) | ||
|
|
||
| existing_asset = db.session.scalars(query).first() | ||
|
|
||
| if existing_asset: | ||
| err_msg = f"An asset with the name '{data['name']}' already exists under parent asset {data.get('parent_asset_id')}" | ||
| raise ValidationError(err_msg, "name") | ||
|
|
||
|
|
@@ -233,11 +239,24 @@ def validate_generic_asset_type(self, generic_asset_type_id: int, **kwargs): | |
|
|
||
| @validates("parent_asset_id") | ||
| def validate_parent_asset(self, parent_asset_id: int | None, **kwargs): | ||
| if parent_asset_id is not None: | ||
| parent_asset = db.session.get(GenericAsset, parent_asset_id) | ||
| if not parent_asset: | ||
| if parent_asset_id is None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You added a second condition, so a short docstring would be nice: """
""" |
||
| return | ||
|
|
||
| parent_asset = db.session.get(GenericAsset, parent_asset_id) | ||
| if not parent_asset: | ||
| raise ValidationError( | ||
| f"Parent GenericAsset with id {parent_asset_id} doesn't exist." | ||
| ) | ||
|
|
||
| # Check account consistency (using context) | ||
| # Safely get the asset from context, defaulting to None if creating new | ||
| current_asset = self.context.get("asset") | ||
|
|
||
| # If editing an existing asset (context exists) | ||
| if current_asset and current_asset.account_id: | ||
| if parent_asset.account_id != current_asset.account_id: | ||
| raise ValidationError( | ||
| f"Parent GenericAsset with id {parent_asset_id} doesn't exist." | ||
| "Parent asset must belong to the same account as the child asset." | ||
| ) | ||
|
|
||
| @validates("account_id") | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
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.
Just add a comment: "validating the path data ourselves, as we want to add context information (current asset).
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.
Ok sure, I can do that, I should be home in a few hours