Skip to content

Commit 1eb9b40

Browse files
committed
feat: add ckanext.vip_portal.free_access_by_default config option
1 parent ef438f6 commit 1eb9b40

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ ckanext.vip_portal.free_anonymous_access = true
4646
# (optional, default: true).
4747
ckanext.vip_portal.free_authenticated_access = false
4848

49+
# Unless endpoint is blocked by one of IVipAccess implementations,
50+
# it can be accessed by anyone. Use it in combination with IVipAccess
51+
# interface if you want to leave the portal generally open and
52+
# block only certain endpoints
53+
# (optional, default: false).
54+
ckanext.vip_portal.free_access_by_default = true
55+
4956
# Allow anonymous access to login pages
5057
# (optional, default: true).
5158
ckanext.vip_portal.allow_login = false

ckanext/vip_portal/config.py

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
CONFIG_FREE_USER = "ckanext.vip_portal.free_authenticated_access"
1616
DEFAULT_FREE_USER = True
1717

18+
CONFIG_FREE_UNDEFINED = "ckanext.vip_portal.free_access_by_default"
19+
DEFAULT_FREE_UNDEFINED = False
20+
1821
CONFIG_ALLOW_LOGIN = "ckanext.vip_portal.allow_login"
1922
DEFAULT_ALLOW_LOGIN = True
2023

@@ -71,6 +74,13 @@ def free_authenticated_access() -> bool:
7174
tk.config.get(CONFIG_FREE_USER, DEFAULT_FREE_USER)
7275
)
7376

77+
78+
def free_access_by_default() -> bool:
79+
return tk.asbool(
80+
tk.config.get(CONFIG_FREE_UNDEFINED, DEFAULT_FREE_UNDEFINED)
81+
)
82+
83+
7484
def allowed_endpoints() -> list[tuple[str, Any]]:
7585
endpoints: list[tuple[str, Any]] = essential_endpoints.copy()
7686

ckanext/vip_portal/interfaces.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import enum
4-
from typing import Optional
4+
from typing import Optional, Union
55
from flask import Response
66
from ckan.plugins import Interface
77

@@ -14,7 +14,7 @@ class Access(enum.Enum):
1414

1515
class IVipPortal(Interface):
1616
def check_vip_access_for_endpoint(
17-
self, endpoint: tuple[str, str], user: Optional[str]
17+
self, endpoint: Union[tuple[str, str], tuple[None, None]], user: Optional[str]
1818
) -> Access:
1919
return Access.unknown
2020

ckanext/vip_portal/utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from __future__ import annotations
2-
from typing import Optional
2+
from typing import Optional, Union
33

44
import ckan.plugins.toolkit as tk
55
from ckan.plugins import PluginImplementations
66

77
from . import config, interfaces
88

99

10-
def is_free_endpoint(endpoint: tuple[str, str], user: Optional[str]) -> bool:
10+
def is_free_endpoint(endpoint: Union[tuple[str, str], tuple[None, None]], user: Optional[str]) -> bool:
1111
for p in PluginImplementations(interfaces.IVipPortal):
1212
access = p.check_vip_access_for_endpoint(endpoint, user)
1313

@@ -17,7 +17,7 @@ def is_free_endpoint(endpoint: tuple[str, str], user: Optional[str]) -> bool:
1717
if access is interfaces.Access.forbidden:
1818
return False
1919

20-
return False
20+
return config.free_access_by_default()
2121

2222

2323
def is_free_path(path: str, user: Optional[str]) -> bool:

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = ckanext-vip-portal
3-
version = 0.1.1
3+
version = 0.1.2
44
description =
55
long_description = file: README.md
66
long_description_content_type = text/markdown

0 commit comments

Comments
 (0)