-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Fixes #12124] GNIP 100: Assets #12179
Conversation
ef0d851
to
c04e13a
Compare
geonode/assets/utils.py
Outdated
return HttpResponse(status=401) | ||
|
||
|
||
def get_default_asset(resource: ResourceBase) -> Asset or None: |
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.
I would rename this. i suggest to call it get_resource_asset
otherwise i would expect to have a the value of DEFAULT_ASSET_HANDLER
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.
It returns an Asset, not an AssetHandler.
The first one is the default default bc at the moment we have only a single Asset.
When we'll have multiple assets per resource there will be a way to choose the default one (highest priority?, a pluggable selector?)
get_resource_asset
would imply there is only one asset per resource
geonode/base/models.py
Outdated
asset_handler_registry.get_handler(instance).remove_data(instance) | ||
|
||
|
||
signals.post_delete.connect(cleanup_asset_data, sender=LocalAsset) |
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.
If you connect the signal to "Asset" it should work without defining (in the future) one for each asset
signals.post_delete.connect(cleanup_asset_data, sender=Asset)
if self.resource_type == "dataset": | ||
allowed_file = select_relevant_files(get_allowed_extensions(), self.files) | ||
from geonode.assets.utils import get_default_asset | ||
from geonode.geoserver.helpers import select_relevant_files |
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.
Can we just move on top this imports? This API si widely called. Having this here means re-import them everytime. They are cached, yes but part of them can be still re-imported:
https://stackoverflow.com/a/46662587/7597536
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.
that would create a circular reference error
if file: | ||
manager = StorageManager(remote_files={"base_file": file}) | ||
manager.clone_remote_files() | ||
create_asset_and_link( |
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.
Instead of cloning the remote files and then copy them again in the settings.ASSET_ROOT
, whey dont we improve the clone_remote_files
by giving a destination path? In this way we can avoid to perform 3 operations on the file.
In geonode deployment with a huge quanity of document, this file system work can be an issue
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.
keeping the current behaviour so far
geonode/resource/manager.py
Outdated
links = self._copy_data(instance, target=_resource) | ||
files = [] | ||
for link in links: | ||
files.extend(link.asset.location) |
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.
cant' we just return the location from the _copy_data
function instead of the whole object? If yes, this for
is not needed
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.
adding as comment
# we're just merging all the files together: it won't work once we have multiple assets per resource
# TODO: get the files from the proper Asset
geonode/base/api/views.py
Outdated
|
||
def _get_file(self, request, pk, attachment: bool): | ||
asset = get_object_or_404(Asset, pk=pk) | ||
if bad_response := get_perms_response(request, 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.
can't this be replaced by the IsOwnerOrAdmin
permission class? If yes, let's improve the perms class (if needed)
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.
nope: assets have their own permission semantic:
As described in the issue, step 0 is "visibile if owner or admin, or if user has read access on at least one resource attached to the asset"
Furthermore, we may want to make permission also more complex, for instance including group admin or permission directly attached to the Asset. The get_perms_response
will encapsulate such logic.
ce319e1
to
49d489b
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #12179 +/- ##
==========================================
+ Coverage 64.03% 64.18% +0.14%
==========================================
Files 870 882 +12
Lines 52221 52788 +567
Branches 6487 6530 +43
==========================================
+ Hits 33438 33880 +442
- Misses 17281 17400 +119
- Partials 1502 1508 +6 |
closed in favor of #12338 |
First implementation of assets.
Also these changes are needed: GeoNode/geonode-importer#235
Checklist
For all pull requests:
The following are required only for core and extension modules (they are welcomed, but not required, for contrib modules):
Submitting the PR does not require you to check all items, but by the time it gets merged, they should be either satisfied or inapplicable.