Add pages permission
This commit is contained in:
@@ -11,64 +11,18 @@ def build_sidebar():
|
||||
return
|
||||
|
||||
authenticator = st.session_state.get("authenticator")
|
||||
username = st.session_state.get("username")
|
||||
username = st.session_state.get("name")
|
||||
role_text = st.session_state.get("role_text")
|
||||
fullname = st.session_state.get("fullname")
|
||||
|
||||
if not authenticator or not username:
|
||||
return
|
||||
|
||||
role = get_role_for_user(username)
|
||||
fullname = get_fullname_for_user(username)
|
||||
|
||||
if role == "admin":
|
||||
sql = """
|
||||
select
|
||||
g.group_id,
|
||||
g.group_text,
|
||||
d.dash_id,
|
||||
d.dash_text,
|
||||
d.page_file,
|
||||
d.dash_type
|
||||
from
|
||||
groups g
|
||||
left join dashboards d
|
||||
on g.group_id = d.group_id
|
||||
where
|
||||
g.active = 1
|
||||
and d.active = 1
|
||||
"""
|
||||
else:
|
||||
sql = """
|
||||
SELECT
|
||||
d.group_id,
|
||||
g.group_text,
|
||||
p.dash_id,
|
||||
d.dash_text,
|
||||
d.page_file,
|
||||
d.dash_type
|
||||
FROM
|
||||
users u
|
||||
left join permissions p
|
||||
on u.role_id = p.role_id
|
||||
left join dashboards d
|
||||
on p.dash_id = d.dash_id
|
||||
left join groups g
|
||||
on d.group_id = g.group_id
|
||||
where
|
||||
u.active = 1
|
||||
and g.active = 1
|
||||
and d.active = 1
|
||||
and p.active = 1
|
||||
and u.username = ?
|
||||
order by
|
||||
g.order_no,
|
||||
d.order_no
|
||||
"""
|
||||
params = (username,) if "?" in sql else None
|
||||
df = get_list(sql, params)
|
||||
df = st.session_state.get("df_sidebar")
|
||||
|
||||
with st.sidebar:
|
||||
st.logo("app/images/GMN_Logo_neu_rgb.png", size="small")
|
||||
st.write(f"**{fullname}** ({role})")
|
||||
st.markdown(f"**{fullname}** ({role_text})")
|
||||
|
||||
col1, col2 = st.columns(2)
|
||||
with col1:
|
||||
@@ -81,32 +35,6 @@ def build_sidebar():
|
||||
st.divider()
|
||||
st.markdown("## Menü")
|
||||
|
||||
# for group_text, df_group in df.groupby("group_text"):
|
||||
# with st.expander(group_text, expanded=False):
|
||||
# for _, row in df_group.iterrows():
|
||||
# dash_type = row.get("dash_type")
|
||||
# page_file = row.get("page_file")
|
||||
# label = row.get("dash_text", "")
|
||||
# print(dash_type, page_file, label)
|
||||
# # 1) echte Streamlit-Page
|
||||
# if dash_type == "page" and isinstance(page_file, str) and page_file.strip():
|
||||
# st.page_link(
|
||||
# page_file, # z.B. "pages/umsatz.py"
|
||||
# label=label,
|
||||
# )
|
||||
|
||||
# # 2) externer Link (oder interner HTTP-Link)
|
||||
# elif dash_type == "url" and isinstance(page_file, str) and page_file.strip():
|
||||
# st.markdown(
|
||||
# f"[{label}]({page_file})",
|
||||
# unsafe_allow_html=False,
|
||||
# )
|
||||
|
||||
# # 3) Platzhalter / noch nicht implementiert
|
||||
# else:
|
||||
# st.write(f"▫️ {label} (in Vorbereitung)")
|
||||
|
||||
|
||||
# --- Suchfeld ---
|
||||
query = st.text_input("Menü-Suche", "", placeholder="z.B. Umsatz, Kosten, User ...")
|
||||
query = query.strip()
|
||||
@@ -145,7 +73,7 @@ def build_sidebar():
|
||||
|
||||
# Streamlit-Page
|
||||
if dash_type == "page" and isinstance(page_file, str) and page_file.strip():
|
||||
st.page_link(page_file, label=label)
|
||||
st.page_link(f"pages/{page_file}.py", label=label)
|
||||
|
||||
# Externer Link
|
||||
elif dash_type == "url" and isinstance(page_file, str) and page_file.strip():
|
||||
|
||||
Reference in New Issue
Block a user