Skip to content

Commit

Permalink
Merge pull request datopian#4 from datopian/fix/allow-dcat-access
Browse files Browse the repository at this point in the history
Make catalog and dataset endpoints accessible for DCAT
  • Loading branch information
zelima authored Apr 27, 2020
2 parents a7b6465 + de4e73a commit e63dd91
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ckanext/noanonaccess/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ class AuthMiddleware(object):
def __init__(self, app, app_conf):
self.app = app
def __call__(self, environ, start_response):
# Get the dcat_access variable from the config object
dcat_access = config.get('ckanext.noanonaccess.allow_dcat')
# List of extensions to be made accessible if dcat_access is True
ext = ['.jsonld','.xml','.ttl','.n3']
# List of catalog endpoints
catalog_endpoint = config.get('ckanext.dcat.catalog_endpoint')
catalog_endpoints = ['/catalog']
if catalog_endpoint:
catalog_endpoint = catalog_endpoint.split('/{_format}')
catalog_endpoints.append(catalog_endpoint[0])
# we putting only UI behind login so API paths should remain accessible
# also, allow access to dataset download and uploaded files
if '/api/' in environ['PATH_INFO'] or '/datastore/dump/' in environ['PATH_INFO']:
Expand All @@ -24,6 +34,11 @@ def __call__(self, environ, start_response):
elif 'repoze.who.identity' in environ or self._get_user_for_apikey(environ):
# if logged in via browser cookies or API key, all pages accessible
return self.app(environ,start_response)
elif dcat_access and (environ['PATH_INFO'].endswith(tuple(ext))
or environ['PATH_INFO'].startswith(tuple(catalog_endpoints))):
# If dcat_acess is enabled in the .env file make dataset and
# catalog pages accessible
return self.app(environ,start_response)
else:
# otherwise only login/reset are accessible
if (environ['PATH_INFO'] == '/user/login' or environ['PATH_INFO'] == '/user/_logout'
Expand Down

0 comments on commit e63dd91

Please sign in to comment.