Skip to content

Commit

Permalink
Debug and test Package_show unauthorized issue [#6]
Browse files Browse the repository at this point in the history
  • Loading branch information
NTaherifar committed Jul 1, 2024
1 parent e2d4369 commit fbf079b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
5 changes: 3 additions & 2 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ CKAN__LICENSES_GROUP_URL= file:///shared/public/licenses.json
CKAN__DISPLAY_TIMEZONE=Australia/Sydney

# Extensions
CKAN__PLUGINS="envvars oidc_pkce auscope_theme contact scheming_datasets composite image_view text_view recline_view datastore datapusher spatial_metadata spatial_query doi s3filestore"
# CKAN__PLUGINS="envvars oidc_pkce igsn_theme contact scheming_datasets composite image_view text_view recline_view datastore datapusher spatial_metadata spatial_query doi s3filestore"
CKAN__PLUGINS="envvars oidc_pkce auscope_theme contact scheming_datasets scheming_organizations composite image_view text_view recline_view datastore datapusher spatial_metadata spatial_query doi dcat dcat_json_interface structured_data"
# CKAN__PLUGINS="envvars oidc_pkce igsn_theme contact scheming_datasets scheming_organizations composite image_view text_view recline_view datastore datapusher spatial_metadata spatial_query doi dcat dcat_json_interface structured_data"


CKAN__HARVEST__MQ__TYPE=redis
CKAN__HARVEST__MQ__HOSTNAME=redis
Expand Down
4 changes: 2 additions & 2 deletions ckan/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ RUN pip install -e "git+https://github.com/EnviDat/ckanext-composite.git#egg=cka
RUN pip install -e "git+https://github.com/AuScope/ckanext-zippreview.git@master#egg=ckanext-zippreview"

# ### DCAT plugins ###
# RUN pip install -r "https://raw.githubusercontent.com/ckan/ckanext-dcat/master/requirements.txt"
# RUN pip install -e "git+https://github.com/AuScope/ckanext-dcat.git@auscope_customise#egg=ckanext-dcat"
RUN pip install -r "https://raw.githubusercontent.com/ckan/ckanext-dcat/master/requirements.txt"
RUN pip install -e "git+https://github.com/AuScope/ckanext-dcat.git@auscope_customise#egg=ckanext-dcat"

# Clone the extension(s) your are writing for your own project in the `src` folder
# to get them mounted in this image at runtime
Expand Down
4 changes: 2 additions & 2 deletions ckan/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ RUN pip install -e "git+https://github.com/AuScope/ckanext-zippreview.git@master


### DCAT plugins - used for exposing schema.org descriptions to search engines ###
# RUN pip install -r "https://raw.githubusercontent.com/ckan/ckanext-dcat/master/requirements.txt"
# RUN pip install -e "git+https://github.com/AuScope/ckanext-dcat.git@auscope_customise#egg=ckanext-dcat"
RUN pip install -r "https://raw.githubusercontent.com/ckan/ckanext-dcat/master/requirements.txt"
RUN pip install -e "git+https://github.com/AuScope/ckanext-dcat.git@auscope_customise#egg=ckanext-dcat"

# Clone the extension(s) your are writing for your own project in the `src` folder
# to get them mounted in this image at runtime
Expand Down
33 changes: 33 additions & 0 deletions ckan/src/ckanext-igsn-theme/ckanext/igsn_theme/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import ckan.authz as authz
from datetime import date
from ckan.logic import NotFound
import simplejson as json
import logging

def igsn_theme_hello():
return "Hello, igsn_theme!"
Expand Down Expand Up @@ -76,6 +78,36 @@ def get_user_role_in_organization(org_id):

user_role = authz.users_role_for_group_or_org(org_id, toolkit.c.user)
return user_role

def custom_structured_data(dataset_id, profiles=None, _format='jsonld'):
'''
Returns a string containing the structured data of the given
dataset id and using the given profiles (if no profiles are supplied
the default profiles are used).
This string can be used in the frontend.
'''
context = {'ignore_auth': True}

if not profiles:
profiles = ['schemaorg']

data = toolkit.get_action('dcat_dataset_show')(
context,
{
'id': dataset_id,
'profiles': profiles,
'format': _format,
}
)
# parse result again to prevent UnicodeDecodeError and add formatting
try:
json_data = json.loads(data)
return json.dumps(json_data, sort_keys=True,
indent=4, separators=(',', ': '), cls=json.JSONEncoderForHTML)
except ValueError:
# result was not JSON, return anyway
return data

def get_helpers():
return {
Expand All @@ -88,4 +120,5 @@ def get_helpers():
'current_date': current_date,
"get_package": get_package,
"get_user_role_in_organization" : get_user_role_in_organization,
"custom_structured_data" : custom_structured_data
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@
{% endblock %}

{% endblock %}

{% block structured_data %}
{#
h.structured_data is defined in the 'structured_data' plugin,
you have to activate the plugin (or implement the method yourself)
to make use of this feature.
More information about structured data:
https://developers.google.com/search/docs/guides/intro-structured-data
#}
{% if h.helper_available('structured_data') %}
<script type="application/ld+json">
{{ h.custom_structured_data(pkg.id)|safe }}
</script>
{% endif %}
{% endblock %}

0 comments on commit fbf079b

Please sign in to comment.