Skip to content
Snippets Groups Projects
Verified Commit 86e23ad6 authored by Peter Bolha's avatar Peter Bolha :ok_hand_tone1:
Browse files

fix: handle unknown user error

parent 3b52d3a3
No related branches found
No related tags found
1 merge request!98fix: handle unknown user error
Pipeline #488081 passed
...@@ -24,7 +24,7 @@ from perun.proxygui.api.heuristic_api import AuthEventLoggingQueries ...@@ -24,7 +24,7 @@ from perun.proxygui.api.heuristic_api import AuthEventLoggingQueries
from perun.proxygui.jwt import SingletonJWTServiceProvider from perun.proxygui.jwt import SingletonJWTServiceProvider
from perun.proxygui.logout_manager import LogoutManager from perun.proxygui.logout_manager import LogoutManager
from perun.proxygui.user_manager import UserManager from perun.proxygui.user_manager import UserManager
from perun.utils.CustomExceptions import InvalidJWTError from perun.utils.CustomExceptions import InvalidJWTError, UserNotExistsException
from perun.utils.Notification import NotificationType from perun.utils.Notification import NotificationType
from perun.utils.consent_framework.consent_manager import ConsentManager from perun.utils.consent_framework.consent_manager import ConsentManager
...@@ -611,6 +611,7 @@ def construct_gui_blueprint(cfg, auth: OIDCAuthentication): ...@@ -611,6 +611,7 @@ def construct_gui_blueprint(cfg, auth: OIDCAuthentication):
"HeuristicData.html", "HeuristicData.html",
redirect_url=REDIRECT_URL, redirect_url=REDIRECT_URL,
selected=False, selected=False,
user_not_exists=False,
) )
try: try:
...@@ -621,13 +622,25 @@ def construct_gui_blueprint(cfg, auth: OIDCAuthentication): ...@@ -621,13 +622,25 @@ def construct_gui_blueprint(cfg, auth: OIDCAuthentication):
f"integer" f"integer"
), HTTPStatus.BAD_REQUEST ), HTTPStatus.BAD_REQUEST
name = user_manager.get_user_name(user_id) try:
name = user_manager.get_user_name(user_id)
except UserNotExistsException:
user_not_exists_message = f"User with ID {user_id} does not exist."
return render_template(
"HeuristicData.html",
redirect_url=REDIRECT_URL,
selected=False,
user_not_exists=True,
user_not_exists_message=user_not_exists_message,
)
auth_event.get_auth_logs(user_id) auth_event.get_auth_logs(user_id)
return render_template( return render_template(
"HeuristicData.html", "HeuristicData.html",
redirect_url=REDIRECT_URL, redirect_url=REDIRECT_URL,
selected=True, selected=True,
user_not_exists=False,
user=user_id, user=user_id,
name=name, name=name,
last_n_times=auth_event.get_last_n_times(), last_n_times=auth_event.get_last_n_times(),
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
{% block contentwrapper %} {% block contentwrapper %}
<div class="window {% if cfg.css_framework == 'MUNI' %}framework_muni{% else %}framework_bootstrap5 bg-light{% endif %}"> <div class="window {% if cfg.css_framework == 'MUNI' %}framework_muni{% else %}framework_bootstrap5 bg-light{% endif %}">
<div id="content"> <div id="content">
<div class="wrap{% if not cfg.css_framework == 'MUNI' %} container{% endif %}"> <div class="box-bg{% if not cfg.css_framework == 'MUNI' %} container{%
endif %}">
{% block content %} {% block content %}
{% if selected %} {% if selected %}
<div class="content"> <div class="content">
...@@ -126,7 +127,22 @@ ...@@ -126,7 +127,22 @@
<br/> <br/>
<h3><span>{{ _("Specify a Perun user ID to gather data:") }}</span></h3> <h3><span>{{ _("Specify a Perun user ID to gather data:") }}</span></h3>
<form action="{{ url_for('gui.heuristics') }}" method="get"> <form action="{{ url_for('gui.heuristics') }}" method="get">
<input type="number" id="user_id" name="user_id" min="1" required placeholder="User ID"> <div class="u-pb-30">
<input type="number" id="user_id" name="user_id" min="1" required placeholder="User ID">
</div>
{% if user_not_exists %}
{% if not cfg.css_framework == 'MUNI' %}
<div class="bd-callout bd-callout-danger">
{{ user_not_exists_message }}
</div>
{% else %}
<div class="message message--common message--common-error"
role="alert">
<span class="message__icon icon icon-exclamation-triangle"></span>
<p class="message__desc">{{ user_not_exists_message }}</p>
</div>
{% endif %}
{% endif %}
<p class="btn-wrap"> <p class="btn-wrap">
<button class="btn btn-primary btn-s btn-accept" <button class="btn btn-primary btn-s btn-accept"
type="submit" name="submit"> type="submit" name="submit">
......
...@@ -6,6 +6,7 @@ from typing import Optional ...@@ -6,6 +6,7 @@ from typing import Optional
from perun.connector import AdaptersManager from perun.connector import AdaptersManager
from perun.connector import Logger from perun.connector import Logger
from perun.connector.adapters.AdaptersManager import AdaptersManagerNotExistsException
from sqlalchemy import MetaData, delete, select, update from sqlalchemy import MetaData, delete, select, update
from sqlalchemy.engine import Engine from sqlalchemy.engine import Engine
from sqlalchemy.orm.session import Session from sqlalchemy.orm.session import Session
...@@ -13,6 +14,7 @@ from sqlalchemy.orm.session import Session ...@@ -13,6 +14,7 @@ from sqlalchemy.orm.session import Session
from perun.proxygui import jwt from perun.proxygui import jwt
from perun.proxygui.jwt import SingletonJWTServiceProvider from perun.proxygui.jwt import SingletonJWTServiceProvider
from perun.utils.ConfigStore import ConfigStore from perun.utils.ConfigStore import ConfigStore
from perun.utils.CustomExceptions import UserNotExistsException
from perun.utils.DatabaseService import DatabaseService from perun.utils.DatabaseService import DatabaseService
from perun.utils.EmailService import EmailService from perun.utils.EmailService import EmailService
from perun.utils.Notification import NotificationType from perun.utils.Notification import NotificationType
...@@ -26,6 +28,7 @@ class UserManager: ...@@ -26,6 +28,7 @@ class UserManager:
) )
ADAPTERS_MANAGER_CFG = GLOBAL_CONFIG["adapters_manager"] ADAPTERS_MANAGER_CFG = GLOBAL_CONFIG["adapters_manager"]
ATTRS_MAP = ConfigStore.get_attributes_map(GLOBAL_CONFIG["attrs_cfg_path"]) ATTRS_MAP = ConfigStore.get_attributes_map(GLOBAL_CONFIG["attrs_cfg_path"])
self.USER_NOT_EXISTS_EXCEPTION_NAME = "UserNotExistsException"
self._ADAPTERS_MANAGER = AdaptersManager(ADAPTERS_MANAGER_CFG, ATTRS_MAP) self._ADAPTERS_MANAGER = AdaptersManager(ADAPTERS_MANAGER_CFG, ATTRS_MAP)
self._SUBJECT_ATTRIBUTE = USER_MANAGER_CFG.get( self._SUBJECT_ATTRIBUTE = USER_MANAGER_CFG.get(
...@@ -62,8 +65,17 @@ class UserManager: ...@@ -62,8 +65,17 @@ class UserManager:
return attr_value return attr_value
def extract_user_attribute(self, attr_name: str, user_id: int) -> Any: def extract_user_attribute(self, attr_name: str, user_id: int) -> Any:
user_attrs = self._ADAPTERS_MANAGER.get_user_attributes(user_id, [attr_name]) try:
return user_attrs.get(attr_name) user_attrs = self._ADAPTERS_MANAGER.get_user_attributes(
user_id, [attr_name]
)
return user_attrs.get(attr_name)
except AdaptersManagerNotExistsException as e:
# Wrap an exception to deal with it in the GUI
if self.USER_NOT_EXISTS_EXCEPTION_NAME in e.message:
raise UserNotExistsException(e.message)
raise e
def _revoke_ssp_sessions( def _revoke_ssp_sessions(
self, self,
......
class InvalidJWTError(Exception): class InvalidJWTError(Exception):
pass pass
class UserNotExistsException(Exception):
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment