Skip to content

Commit

Permalink
Added properties setting to NoSecurityStore
Browse files Browse the repository at this point in the history
  • Loading branch information
puehringer committed Feb 19, 2025
1 parent 4ea51c6 commit 4e3cf6b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 7 additions & 4 deletions visyn_core/security/store/no_security_store.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import Any

from ... import manager
from ..model import User
Expand All @@ -8,12 +9,13 @@


class NoSecurityStore(BaseStore):
def __init__(self, user: str, roles: list[str]):
def __init__(self, user: str, roles: list[str], properties: dict[str, Any]):
self.user = user
self.roles = roles
self.properties = properties

def load_from_request(self, req):
return User(id=self.user, roles=self.roles)
return User(id=self.user, roles=self.roles, properties=self.properties)


def create():
Expand All @@ -24,8 +26,9 @@ def create():
if manager.settings.visyn_core.security.store.no_security_store.enable:
_log.info("Adding NoSecurityStore")
return NoSecurityStore(
manager.settings.visyn_core.security.store.no_security_store.user,
manager.settings.visyn_core.security.store.no_security_store.roles,
user=manager.settings.visyn_core.security.store.no_security_store.user,
roles=manager.settings.visyn_core.security.store.no_security_store.roles,
properties=manager.settings.visyn_core.security.store.no_security_store.properties,
)

return None
1 change: 1 addition & 0 deletions visyn_core/settings/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class NoSecurityStoreSettings(BaseModel):
enable: bool = False
user: str = "admin"
roles: list[str] = []
properties: dict[str, Any] = {}


class SecurityStoreSettings(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion visyn_core/tests/test_security_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def test_no_security_store(client: TestClient):
manager.settings.visyn_core.security.store.no_security_store.enable = True
manager.settings.visyn_core.security.store.no_security_store.user = "test_name"
manager.settings.visyn_core.security.store.no_security_store.roles = ["test_role"]
manager.settings.visyn_core.security.store.no_security_store.properties = {"id": 123, "name": "test"}

store = create_no_security_store()
assert store is not None
Expand All @@ -205,7 +206,7 @@ def test_no_security_store(client: TestClient):
assert user_info != '"not_yet_logged_in"'
assert user_info["name"] == "test_name"
assert user_info["roles"] == ["test_role"]
assert user_info["properties"] == {}
assert user_info["properties"] == {"id": 123, "name": "test"}


def test_user_login_hooks(client: TestClient):
Expand Down

0 comments on commit 4e3cf6b

Please sign in to comment.