Clean instance on logout + fixed InstancesDebugger.py
This commit is contained in:
@@ -16,6 +16,7 @@ from ..auth.utils import (
|
|||||||
logout_user,
|
logout_user,
|
||||||
get_user_info
|
get_user_info
|
||||||
)
|
)
|
||||||
|
from ..core.instances import InstancesManager
|
||||||
|
|
||||||
|
|
||||||
def setup_auth_routes(app, rt, mount_auth_app=True, sqlite_db_path="Users.db", base_url=None):
|
def setup_auth_routes(app, rt, mount_auth_app=True, sqlite_db_path="Users.db", base_url=None):
|
||||||
@@ -181,6 +182,9 @@ def setup_auth_routes(app, rt, mount_auth_app=True, sqlite_db_path="Users.db", b
|
|||||||
if refresh_token:
|
if refresh_token:
|
||||||
logout_user(refresh_token)
|
logout_user(refresh_token)
|
||||||
|
|
||||||
|
# release memory
|
||||||
|
InstancesManager.clear_session(session)
|
||||||
|
|
||||||
# Clear session
|
# Clear session
|
||||||
session.clear()
|
session.clear()
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ class InstancesDebugger(SingleInstance):
|
|||||||
super().__init__(parent, _id=_id)
|
super().__init__(parent, _id=_id)
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
|
s_name = InstancesManager.get_session_user_name
|
||||||
instances = self._get_instances()
|
instances = self._get_instances()
|
||||||
nodes, edges = from_parent_child_list(
|
nodes, edges = from_parent_child_list(
|
||||||
instances,
|
instances,
|
||||||
id_getter=lambda x: f"{InstancesManager.get_session_id(x.get_session())}-{x.get_id()}",
|
id_getter=lambda x: x.get_full_id(),
|
||||||
label_getter=lambda x: x.get_prefix(),
|
label_getter=lambda x: f"{s_name(x.get_session())}-{x.get_prefix()}",
|
||||||
parent_getter=lambda x: x.get_parent().get_id() if x.get_parent() else None
|
parent_getter=lambda x: x.get_full_parent_id()
|
||||||
)
|
)
|
||||||
for edge in edges:
|
for edge in edges:
|
||||||
edge["color"] = "green"
|
edge["color"] = "green"
|
||||||
|
|||||||
@@ -86,6 +86,13 @@ class BaseInstance:
|
|||||||
def get_prefix(self) -> str:
|
def get_prefix(self) -> str:
|
||||||
return self._prefix
|
return self._prefix
|
||||||
|
|
||||||
|
def get_full_id(self) -> str:
|
||||||
|
return f"{InstancesManager.get_session_id(self._session)}-{self._id}"
|
||||||
|
|
||||||
|
def get_full_parent_id(self) -> Optional[str]:
|
||||||
|
parent = self.get_parent()
|
||||||
|
return parent.get_full_id() if parent else None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def compute_prefix(cls):
|
def compute_prefix(cls):
|
||||||
return f"mf-{pascal_to_snake(cls.__name__)}"
|
return f"mf-{pascal_to_snake(cls.__name__)}"
|
||||||
@@ -177,10 +184,33 @@ class InstancesManager:
|
|||||||
return "** UNKNOWN USER **"
|
return "** UNKNOWN USER **"
|
||||||
return session["user_info"].get("id", "** INVALID SESSION **")
|
return session["user_info"].get("id", "** INVALID SESSION **")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_session_user_name(session):
|
||||||
|
if session is None:
|
||||||
|
return "** NOT LOGGED IN **"
|
||||||
|
if "user_info" not in session:
|
||||||
|
return "** UNKNOWN USER **"
|
||||||
|
return session["user_info"].get("username", "** INVALID SESSION **")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def reset():
|
def reset():
|
||||||
InstancesManager.instances.clear()
|
InstancesManager.instances.clear()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def clear_session(session):
|
||||||
|
"""
|
||||||
|
Remove all instances belonging to the given session.
|
||||||
|
:param session:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
session_id = InstancesManager.get_session_id(session)
|
||||||
|
|
||||||
|
InstancesManager.instances = {
|
||||||
|
key: instance
|
||||||
|
for key, instance in InstancesManager.instances.items()
|
||||||
|
if key[0] != session_id
|
||||||
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def dynamic_get(parent: BaseInstance, component_type: str, instance_id: str):
|
def dynamic_get(parent: BaseInstance, component_type: str, instance_id: str):
|
||||||
logger.debug(f"Dynamic get: {component_type=} {instance_id=}")
|
logger.debug(f"Dynamic get: {component_type=} {instance_id=}")
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ def from_parent_child_list(
|
|||||||
id_getter: Callable = None,
|
id_getter: Callable = None,
|
||||||
label_getter: Callable = None,
|
label_getter: Callable = None,
|
||||||
parent_getter: Callable = None,
|
parent_getter: Callable = None,
|
||||||
ghost_color: str = "#ff9999",
|
ghost_color: str = "#cccccc",
|
||||||
root_color: str | None = "#ff9999"
|
root_color: str | None = "#ff9999"
|
||||||
) -> tuple[list, list]:
|
) -> tuple[list, list]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user