Skip to content

Commit 96ba8d7

Browse files
committed
add disable_default_fail option to checkpoints
1 parent e91f07e commit 96ba8d7

12 files changed

+28
-4
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Unreleased
44

55
- x
66

7+
## Version 6.1.4
8+
9+
- add disable_default_fail option to checkpoints
10+
711
## Version 6.1.3
812

913
- adjust fail_response to accept a callable to avoid out of context error

docs/Security/flask_imp_security-checkpoint.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ IS_LOGGED_IN = SessionCheckpoint(
7373
values_allowed=True,
7474
).action(
7575
pass_endpoint='blueprint.admin_page',
76-
message="Already logged in"
76+
message="Already logged in",
77+
disable_default_fail=True,
7778
)
7879

7980

docs/Security/flask_imp_security-checkpoint_callable.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def checkpoint_callable(
1616
pass_url: t.Optional[t.Union[str, t.Callable[[], t.Any]]] = None,
1717
message: t.Optional[str] = None,
1818
message_category: str = "message",
19+
disable_default_fail: bool = False,
1920
)
2021
```
2122

docs/SecurityCheckpoints/flask_imp_security-apikeycheckpoint.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ APIKeyCheckpoint(
1717
pass_url: t.Optional[t.Union[str, t.Callable[[], t.Any]]] = None,
1818
message: t.Optional[str] = None,
1919
message_category: str = "message",
20+
disable_default_fail: bool = False
2021
)
2122
```
2223

docs/SecurityCheckpoints/flask_imp_security-bearercheckpoint.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ BearerCheckpoint(
1515
pass_url: t.Optional[t.Union[str, t.Callable[[], t.Any]]] = None,
1616
message: t.Optional[str] = None,
1717
message_category: str = "message",
18+
disable_default_fail: bool = False
1819
)
1920
```
2021

docs/SecurityCheckpoints/flask_imp_security-createacheckpoint.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ MyCheckpoint(
2929
pass_url: t.Optional[t.Union[str, t.Callable[[], t.Any]]] = None,
3030
message: t.Optional[str] = None,
3131
message_category: str = "message",
32+
disable_default_fail: bool = False
3233
)
3334
```

docs/SecurityCheckpoints/flask_imp_security-sessioncheckpoint.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ SessionCheckpoint(
1616
pass_url: t.Optional[t.Union[str, t.Callable[[], t.Any]]] = None,
1717
message: t.Optional[str] = None,
1818
message_category: str = "message",
19+
disable_default_fail: bool = False
1920
)
2021
```
2122

@@ -99,7 +100,8 @@ IS_LOGGED_IN = SessionCheckpoint(
99100
values_allowed=True,
100101
).action(
101102
pass_endpoint='blueprint.admin_page',
102-
message="Already logged in"
103+
message="Already logged in",
104+
disable_default_fail=True
103105
)
104106

105107

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "flask-imp"
3-
version = "6.1.3"
3+
version = "6.1.4"
44
description = 'A Flask auto importer that allows your Flask apps to grow big.'
55
authors = [{ name = "David Carmichael", email = "david@uilix.com" }]
66
readme = "README.md"

src/flask_imp/security/_checkpoint.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ def inner(*args: t.Any, **kwargs: t.Any) -> t.Any:
149149
if request.is_json:
150150
return {"error": "Unauthorized"}, checkpoint_.fail_status
151151

152+
if checkpoint_.disable_default_fail:
153+
func(*args, **kwargs)
154+
152155
# Otherwise, abort with the specified status code
153156
return abort(checkpoint_.fail_status)
154157

src/flask_imp/security/_checkpoint_callable.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def checkpoint_callable(
2222
pass_url: t.Optional[t.Union[str, t.Callable[[], t.Any]]] = None,
2323
message: t.Optional[str] = None,
2424
message_category: str = "message",
25+
disable_default_fail: bool = False,
2526
) -> t.Callable[..., t.Any]:
2627
"""
2728
A decorator that evaluates if the passed in callable is truly.
@@ -98,6 +99,7 @@ def number():
9899
:param pass_url: the url to redirect to if the callable passes
99100
:param message: if a message is specified, a flash message is shown
100101
:param message_category: the category of the flash message
102+
:param disable_default_fail: if True, the callable will be called without default failure handling
101103
:return: the decorated callable, or abort(abort_status) response
102104
"""
103105

@@ -161,6 +163,9 @@ def inner(*args: t.Any, **kwargs: t.Any) -> t.Any:
161163

162164
raise TypeError("Pass URL must either be a string or a partial")
163165

166+
if not disable_default_fail:
167+
return func(*args, **kwargs)
168+
164169
return abort(fail_status)
165170

166171
return inner

0 commit comments

Comments
 (0)