first commit

master
alex 2024-04-02 07:18:56 +02:00
commit 012bcb91a9
18 changed files with 445 additions and 0 deletions

3
.gitignore vendored 100644
View File

@ -0,0 +1,3 @@
/.venv
/.idea
.gitignore

View File

@ -0,0 +1,16 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="3">
<item index="0" class="java.lang.String" itemvalue="flask-swagger-ui" />
<item index="1" class="java.lang.String" itemvalue="PyMuPDF" />
<item index="2" class="java.lang.String" itemvalue="typing_extensions" />
</list>
</value>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml 100644
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12 (streamlit userverwaltung)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (streamlit userverwaltung)" project-jdk-type="Python SDK" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/streamlit userverwaltung.iml" filepath="$PROJECT_DIR$/.idea/streamlit userverwaltung.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml 100644
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="80a06ef6-1b55-49c1-bdfc-3ffc4e1e4b86" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/streamlit userverwaltung.iml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/users.json" afterDir="false" />
<change afterPath="$PROJECT_DIR$/users.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Script" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProblemsViewState">
<option name="selectedTabId" value="CurrentFile" />
</component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 8
}</component>
<component name="ProjectId" id="2eHbI5IPJFwhv90ARKGD9KXe4JJ" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;
}
}</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="80a06ef6-1b55-49c1-bdfc-3ffc4e1e4b86" name="Changes" comment="" />
<created>1711564367379</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1711564367379</updated>
</task>
<servers />
</component>
</project>

View File

@ -0,0 +1,2 @@
[client]
showSidebarNavigation = false

50
config/users.yml 100644
View File

@ -0,0 +1,50 @@
credentials:
usernames:
jsmith:
email: jsmith@gmail.com
failed_login_attempts: 0 # Will be managed automatically
logged_in: False # Will be managed automatically
name: John Smith
password: abc # Will be hashed automatically
groups:
- admin
- it
rbriggs:
email: rbriggs@gmail.com
failed_login_attempts: 0 # Will be managed automatically
logged_in: False # Will be managed automatically
name: Rebecca Briggs
password: def # Will be hashed automatically
cookie:
expiry_days: 30
key: some_signature_key # Must be string
name: some_cookie_name
pre-authorized:
emails:
- melsby@gmail.com
groups:
- admin
- it
- dispo
- fuhrpark
- buchhaltung
- service
dashboards:
users:
groups:
- admin
path: pages/users.py
test:
groups:
- admin
- it
path: pages/test.py
test2:
groups:
- it
path: pages/user.py
Dashboard:
groups:
- dispo
- it
path: pages/dashboard.py

51
main.py 100644
View File

@ -0,0 +1,51 @@
import os
import streamlit as st
import streamlit_authenticator as sauth
import numpy as np
import pandas as pd
import yaml
from yaml.loader import SafeLoader
st.set_page_config(layout='wide')
config = dict()
with open(os.getcwd()+'/config/users.yml') as file:
config = yaml.load(file, Loader=SafeLoader)
authenticator = sauth.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['pre-authorized']
)
authenticator.login()
if st.session_state["authentication_status"]:
authenticator.logout()
st.session_state['authenticator'] = authenticator
elif st.session_state["authentication_status"] is False:
st.error('Username/password is incorrect')
st.stop()
elif st.session_state["authentication_status"] is None:
st.warning('Please enter your username and password')
st.stop()
st.write('Hello')
st.button('World', use_container_width=True)
with st.sidebar:
st.button('Hallo')
st.page_link('pages/user.py')
st.page_link('pages/dashboards.py')
st.page_link('pages/dashboard.py')
st.page_link('pages/test.py')

13
pages/dashboard.py 100644
View File

@ -0,0 +1,13 @@
import streamlit as st
import template
template.authenticate()
template.make_logout_section()
with st.sidebar:
st.write('Hello Daschboard')
template.make_dashboard_section()

View File

@ -0,0 +1,7 @@
import os
import streamlit as st
dash_list = [f for f in os.listdir('./pages') if os.path.isfile(os.getcwd()+'/pages/'+f)]
data = st.data_editor(dash_list)

22
pages/test.py 100644
View File

@ -0,0 +1,22 @@
import os
import yaml
from yaml import SafeLoader
import streamlit as st
import template
template.authenticate()
template.make_logout_section()
template.make_dashboard_section()
config = dict()
with open(os.getcwd()+'/config/users.yml') as file:
config = yaml.load(file, Loader=SafeLoader)
st.write(config)
st.write(st.session_state)
with st.sidebar:
for i in range(20):
st.button('Test'+str(i))

36
pages/user.py 100644
View File

@ -0,0 +1,36 @@
import os
import streamlit as st
import pandas as pd
import template
template.authenticate()
template.make_logout_section()
st.title('Benutzer')
st.header(st.session_state['username'])
st.divider()
st.subheader('Info')
st.text_input('Benutzername', value=st.session_state['username'])
st.text_input('Name', value=st.session_state['name'])
st.text_input('Passwort', type='password', value='Sitch')
st.text_input('Passwort bestätigen:', type='password')
st.divider()
st.subheader('Gruppen')
st.multiselect('Gruppen', template.get_config_groups(), default=template.get_groups())
st.divider()
st.button('Speichern', type='primary')
st.page_link('pages/users.py', label='Abbrechen')

34
pages/users.py 100644
View File

@ -0,0 +1,34 @@
import os
import json
import streamlit as st
import pandas as pd
import template
template.authenticate()
template.make_logout_section()
def read_config():
with open(os.getcwd()+"/config/users.json") as file:
return json.load(file)
config = read_config()
st.write(config['users'])
df_users = pd.DataFrame(config['users'])
st.header('Benutzerverwaltung')
col1, col2, col3 = st.columns(3)
with col1:
pass
with col2:
st.metric('Benutzer Gesamt', 10, 20)
edited_df = st.data_editor(df_users, hide_index=True, use_container_width=True, num_rows="dynamic")
st.write(edited_df)

46
requirements.txt 100644
View File

@ -0,0 +1,46 @@
altair==5.2.0
attrs==23.2.0
bcrypt==4.1.2
blinker==1.7.0
cachetools==5.3.3
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.1.7
extra-streamlit-components==0.1.71
gitdb==4.0.11
GitPython==3.1.42
idna==3.6
Jinja2==3.1.3
jsonschema==4.21.1
jsonschema-specifications==2023.12.1
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mdurl==0.1.2
numpy==1.26.4
packaging==23.2
pandas==2.2.1
pillow==10.2.0
protobuf==4.25.3
pyarrow==15.0.2
pydeck==0.8.1b0
Pygments==2.17.2
PyJWT==2.8.0
python-dateutil==2.9.0.post0
pytz==2024.1
PyYAML==6.0.1
referencing==0.34.0
requests==2.31.0
rich==13.7.1
rpds-py==0.18.0
six==1.16.0
smmap==5.0.1
streamlit==1.32.2
streamlit-authenticator==0.3.2
tenacity==8.2.3
toml==0.10.2
toolz==0.12.1
tornado==6.4
typing_extensions==4.10.0
tzdata==2024.1
urllib3==2.2.1
watchdog==4.0.0

65
template.py 100644
View File

@ -0,0 +1,65 @@
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)