66 lines
1.7 KiB
Python
66 lines
1.7 KiB
Python
import os
|
|
import streamlit as st
|
|
import yaml
|
|
from yaml.loader import SafeLoader
|
|
|
|
config = None
|
|
def get_config():
|
|
global config
|
|
if config is None:
|
|
with open(os.getcwd()+'/config/users.yml') as file:
|
|
config = yaml.load(file, Loader=SafeLoader)
|
|
return config
|
|
|
|
def authenticate():
|
|
try:
|
|
if st.session_state["authentication_status"]:
|
|
pass
|
|
else:
|
|
print('Not authenticated')
|
|
st.switch_page('main.py')
|
|
except KeyError:
|
|
print('No Key found')
|
|
st.switch_page('main.py')
|
|
|
|
def make_logout_section():
|
|
with st.sidebar:
|
|
st.write("Hallo " + st.session_state['name'])
|
|
st.page_link('pages/user.py', label='Benutzer')
|
|
st.page_link('main.py', label='Hauptseite')
|
|
st.session_state['authenticator'].logout()
|
|
st.divider()
|
|
|
|
|
|
def get_config_groups():
|
|
config = get_config()
|
|
groups = config['groups']
|
|
return groups
|
|
|
|
def get_config_dashboards():
|
|
config = get_config()
|
|
dashboards = config['dashboards']
|
|
return dashboards
|
|
|
|
def get_groups():
|
|
config = get_config()
|
|
user = config['credentials']['usernames'][st.session_state['username']]
|
|
groups = user['groups']
|
|
return groups
|
|
|
|
def get_dashboards():
|
|
config = get_config()
|
|
groups = get_groups()
|
|
dashboards = set()
|
|
dash = config['dashboards']
|
|
for d in dash:
|
|
for dg in dash[d]['groups']:
|
|
if dg in groups:
|
|
dashboards.add(d)
|
|
return dashboards
|
|
|
|
def make_dashboard_section():
|
|
with st.sidebar:
|
|
dashboards = get_config_dashboards()
|
|
for d in get_dashboards():
|
|
st.page_link(dashboards[d]['path'], label=d)
|