Skip to content

Commit 87974bf

Browse files
committed
Add visibility check for authenticators in uds_js function
1 parent 95e0259 commit 87974bf

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

server/src/uds/web/util/configjs.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def uds_js(request: 'ExtendedHttpRequest') -> str:
8585

8686
logger.debug('Authenticators PRE: %s', authenticators)
8787

88+
use_hidden: bool = tag is not None and tag != 'disabled'
8889
# No tag, and there are authenticators, let's use the tag of first one
8990
if not tag and authenticators: # Keep disabled as tag if present
9091
tag = authenticators[0].small_name
@@ -101,6 +102,14 @@ def _get_auth_info(auth: Authenticator) -> dict[str, typing.Any]:
101102
'priority': auth.priority,
102103
'is_custom': auth_type.is_custom(),
103104
}
105+
106+
def _is_auth_visible(auth: Authenticator) -> bool:
107+
"""
108+
Check if the authenticator is visible for the current request.
109+
This is used to filter out authenticators that are not allowed
110+
for the current user or request.
111+
"""
112+
return auth.type_is_valid() and (auth.state == consts.auth.VISIBLE or (auth.state == consts.auth.HIDDEN and use_hidden))
104113

105114
config: dict[str, typing.Any] = {
106115
'version': consts.system.VERSION,
@@ -110,7 +119,7 @@ def _get_auth_info(auth: Authenticator) -> dict[str, typing.Any]:
110119
'authenticators': [
111120
_get_auth_info(auth)
112121
for auth in authenticators
113-
if auth.type_is_valid() and auth.state == consts.auth.VISIBLE
122+
if _is_auth_visible(auth)
114123
],
115124
'mfa': request.session.get('mfa', None),
116125
'tag': tag,

0 commit comments

Comments
 (0)