Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/211.canada.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Resource URLs are now only stored as relative paths in SOLR. The request hostname is prepended during `package_show`
5 changes: 4 additions & 1 deletion ckan/lib/dictization/model_dictize.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,17 @@ def resource_dictize(res: model.Resource, context: Context) -> dict[str, Any]:
url = resource['url']
## for_edit is only called at the times when the dataset is to be edited
## in the frontend. Without for_edit the whole qualified url is returned.

# (canada fork only): do not store qualified URIs in SOLR.
# NOTE: super important for language domain support!!!
if resource.get('url_type') == 'upload' and not context.get('for_edit'):
url = url.rsplit('/')[-1]
cleaned_name = munge.munge_filename(url)
resource['url'] = h.url_for('resource.download',
id=resource['package_id'],
resource_id=res.id,
filename=cleaned_name,
qualified=True)
qualified=False) # (canada fork only): unqualified
elif resource['url'] and not urlsplit(url).scheme \
and not context.get('for_edit'):
resource['url'] = u'http://' + url.lstrip('/')
Expand Down
8 changes: 6 additions & 2 deletions ckan/lib/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ def notify(self, entity: Any, operation: str) -> None:
'model': model,
'ignore_auth': True,
'validate': False,
'use_cache': False
'use_cache': False,
# (canada fork only): non-qualified res_url for lang domain support
'for_index': True,
}), {'id': entity.id}), operation)
elif operation == domain_object.DomainObjectOperation.deleted:
dispatch_by_operation(entity.__class__.__name__,
Expand Down Expand Up @@ -208,7 +210,9 @@ def rebuild(package_id: Optional[str] = None,
'model': model,
'ignore_auth': True,
'validate': False,
'use_cache': False
'use_cache': False,
# (canada fork only): non-qualified res_url for lang domain support
'for_index': True,
})

if package_id:
Expand Down
16 changes: 16 additions & 0 deletions ckan/logic/action/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import sqlalchemy
from sqlalchemy import text

# (canada fork only): non-qualified res_url for lang domain support
from flask import request


import ckan
import ckan.lib.dictization
Expand Down Expand Up @@ -1093,6 +1096,19 @@ def package_show(context: Context, data_dict: DataDict) -> ActionResult.PackageS
for item in plugins.PluginImplementations(plugins.IPackageController):
item.after_dataset_show(context, package_dict)

# (canada fork only): non-qualified res_url for lang domain support
if not context.get('for_index'):
try:
current_domain = request.host_url.rstrip('/')
except RuntimeError:
current_domain = config['ckan.site_url'].rstrip('/')
for res_dict in package_dict['resources']:
if(
res_dict.get('url_type') == 'upload' and
res_dict.get('url', '').startswith('/')
):
res_dict['url'] = current_domain + res_dict['url']

return package_dict


Expand Down