Skip to content
Spera Alfredo Jeshoua edited this page May 14, 2025 · 6 revisions

VM Lab Project Structure Badge

Creating a new page

The code for each page must be in the /pages folder. Each page should also be specified in the PageNames class in /frontend/page_names.py like this:

DESCRIPTIVE_PAGE_NAME = PageEntry(
	"pages/page_file_name.py",
	"Page Label"
)

The page_setup function

This function should be the first (non-import) statement of each page. It configures the page layout, title, and access control for the current page, including:

  • authentication
  • authorization checks
  • optional execution of a callback function
  • debugging

Input

  • layout (Literal["centered", "wide"], default="wide"): Sets the page layout, either with centered content or a wider view.
  • title (str, default=None): The title of the page, displayed in the browser tab. If None, the title will be the file name.
  • access_control (Literal["free_access", "logged_in_only", "unregistered_only", "accepted_roles_only"], default="free_access"): Defines access control settings for the page:
    • "free_access": All users have unrestricted access.
    • "logged_in_only": Access is restricted to logged-in users.
    • "unregistered_only": Access is restricted to unregistered users.
    • "accepted_roles_only": Only users with specified roles in accepted_roles can access.
  • accepted_roles (list[Role], default=None): List of Roles granted access when access_control is set to "accepted_roles_only".
  • callback (Callable, default=None): Optional function executed after access control checks.
  • print_session_state (bool, default=False): Whether to print the current session_state at the start of the page for debugging.
  • logged_in_not_accepted_redirect (str, default=PageNames.MAIN_DASHBOARD): Page to redirect to if a logged-in user is not accepted.
  • unregistered_not_accepted_in_redirect (str, default=PageNames.LOGIN): Page to redirect to if an unregistered user attempts to access a restricted page.
  • role_not_accepted_redirect (str, default=PageNames.ERROR): Page to redirect to if the user's role does not match accepted_roles.
  • new_user_redirect_to_wait_page (bool, default=True): If True, new users are redirected to a wait page if their role is not accepted.

Output

PageSessionData: Holds the information for the session on the current page, such as:

  • authenticator (Authenticate): The streamlit-authenticator object
  • logged_in (Authenticate): Whether the user is logged-in or not
  • user_role (Authenticate): The role of the current user
  • user_name (Authenticate): The username of the current user
  • user_full_name (Authenticate): The full name of the current user
  • user_email (Authenticate): The email of the current user

This object can also obtain the User object automatically with its get_user() function.

Usage Example

import streamlit as st

from frontend.page_options import page_setup

psd = page_setup(
    # Options for the page
)

# Page code

Pages descriptions

Warning

The page names could change in the future. See this file to see the actual page names.

Who can access this page Description
ERROR All An error page
YOU_ARE_IN_WAITING_LIST New User A page that notifies that the user is in the waiting list
REGISTER Unregistered A page to register to the system
LOGIN Unregistered A page for the login
LOGOUT All except Unregistered A page for the logout
FORGOT_CREDENTIALS Unregistered A page to get forgotten credentials (WIP)
MAIN_DASHBOARD Admin, Manager, Regular, Sidekick The main page where the user can create, delete, select and view its own (and others, if it's an admin or manager) VMs and Bookmarks
USER_SETTINGS All except Unregistered A page to change password, email, username and full name
VM_CONNECTION Admin, Manager, Regular, Sidekick A page for the VM connection with the terminals and file explorers
MANAGE_USER_LIST Admin, Manager A page to see all the users in the system
MANAGE_WAITING_LIST Admin, Manager A page to see all the new users in the waiting list
DETAILS_VM Admin, Manager, Regular A page to see and edit the details of a VM
DETAILS_USER Admin, Manager A page to see the details of a user and change some authorizations for them

Clone this wiki locally