Upload 3 files
Browse files- README.md +21 -4
- auth.py +26 -3
- persistent_data_gate.py +58 -0
README.md
CHANGED
|
@@ -10,9 +10,26 @@ short_description: veureu demo space
|
|
| 10 |
---
|
| 11 |
|
| 12 |
|
| 13 |
-
#
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
|
| 18 |
-
forums](https://discuss.streamlit.io).
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
|
| 13 |
+
# AVISO LEGAL Y RESPONSABILIDAD DE CUMPLIMIENTO NORMATIVO
|
| 14 |
|
| 15 |
+
## 1. Responsabilidad del usuario del software
|
| 16 |
+
|
| 17 |
+
El presente software se distribuye tal cual ("as is"). Cualquier persona que descargue, instale, despliegue o utilice este software asume la plena responsabilidad sobre su uso y las consecuencias derivadas del mismo.
|
| 18 |
+
|
| 19 |
+
## 2. Cumplimiento normativo
|
| 20 |
+
|
| 21 |
+
Es responsabilidad exclusiva del usuario que descargue, ejecute, despliegue y/o haga uso de este software asegurar el cumplimiento de toda la normativa aplicable en su jurisdicci贸n, incluyendo, sin car谩cter limitativo:
|
| 22 |
+
|
| 23 |
+
- El Reglamento (UE) 2016/679 (RGPD) y la Ley Org谩nica 3/2018, de Protecci贸n de Datos Personales y garant铆a de los derechos digitales, en caso de tratamiento de datos personales.
|
| 24 |
+
- El Real Decreto Legislativo 1/1996, de 12 de abril, por el que se aprueba el texto refundido de la Ley de Propiedad Intelectual, regularizando, aclarando y armonizando las disposiciones legales vigentes sobre la materia.
|
| 25 |
+
- La Ley 17/2001, de 7 de diciembre, de Marcas.
|
| 26 |
+
- Cualquier otra normativa, general o sectorial, aplicable seg煤n el uso espec铆fico que se d茅 al software.
|
| 27 |
+
|
| 28 |
+
## 3. Exenci贸n de responsabilidad
|
| 29 |
+
|
| 30 |
+
Los desarrolladores y distribuidores de este software no asumen responsabilidad alguna por el uso indebido, ilegal o contrario a la normativa vigente que terceros puedan hacer del mismo. El usuario es el 煤nico responsable de implementar las medidas t茅cnicas y organizativas necesarias para garantizar el cumplimiento legal en su implementaci贸n.
|
| 31 |
+
|
| 32 |
+
## 4. Prohibici贸n de tratamiento de datos personales sin garant铆as
|
| 33 |
+
|
| 34 |
+
Si el usuario pretende utilizar este software para tratar datos personales, deber谩 implementar previamente todas las salvaguardas legales y t茅cnicas exigidas por la normativa de protecci贸n de datos, incluyendo la realizaci贸n de an谩lisis de riesgos, la implementaci贸n de medidas de seguridad apropiadas y la obtenci贸n de las bases de legitimaci贸n necesarias.
|
| 35 |
|
|
|
|
|
|
auth.py
CHANGED
|
@@ -15,7 +15,7 @@ from mobile_verification import (
|
|
| 15 |
get_user_permissions,
|
| 16 |
show_verification_status_in_sidebar
|
| 17 |
)
|
| 18 |
-
from persistent_data_gate import confirm_changes_and_logout
|
| 19 |
from compliance_client import compliance_client
|
| 20 |
import yaml
|
| 21 |
|
|
@@ -80,8 +80,31 @@ def require_login(login_form_func):
|
|
| 80 |
def render_login_form():
|
| 81 |
"""Renderiza el formulario de login con logs de depuraci贸n."""
|
| 82 |
st.subheader("Inici de sessi贸")
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
if st.button("Entrar", type="primary"):
|
| 87 |
row = get_user(username) if username else None
|
|
|
|
| 15 |
get_user_permissions,
|
| 16 |
show_verification_status_in_sidebar
|
| 17 |
)
|
| 18 |
+
from persistent_data_gate import confirm_changes_and_logout, set_data_origin_and_reload
|
| 19 |
from compliance_client import compliance_client
|
| 20 |
import yaml
|
| 21 |
|
|
|
|
| 80 |
def render_login_form():
|
| 81 |
"""Renderiza el formulario de login con logs de depuraci贸n."""
|
| 82 |
st.subheader("Inici de sessi贸")
|
| 83 |
+
# Valors per defecte de demo: usuari vermell (visitant)
|
| 84 |
+
username = st.text_input("Usuari", value="vermell")
|
| 85 |
+
password = st.text_input("Contrasenya", value="vermell123", type="password")
|
| 86 |
+
|
| 87 |
+
# Checkbox per canviar l'origen de dades (capacitat d'edici贸)
|
| 88 |
+
base_dir = Path(__file__).parent
|
| 89 |
+
try:
|
| 90 |
+
import yaml
|
| 91 |
+
|
| 92 |
+
cfg_path = base_dir / "config.yaml"
|
| 93 |
+
with cfg_path.open("r", encoding="utf-8") as f:
|
| 94 |
+
cfg = yaml.safe_load(f) or {}
|
| 95 |
+
app_cfg = cfg.get("app", {}) or {}
|
| 96 |
+
data_origin = str(app_cfg.get("data_origin", "internal")).lower()
|
| 97 |
+
except Exception:
|
| 98 |
+
data_origin = "internal"
|
| 99 |
+
|
| 100 |
+
is_external = data_origin == "external"
|
| 101 |
+
edit_mode = st.checkbox("Capacitat d'edici贸 de dades", value=is_external)
|
| 102 |
+
|
| 103 |
+
# Si el checkbox canvia respecte a l'estat actual, actualitzar config.yaml i recarregar dades
|
| 104 |
+
new_origin = "external" if edit_mode else "internal"
|
| 105 |
+
if new_origin != data_origin:
|
| 106 |
+
api_client = st.session_state.get("api_client")
|
| 107 |
+
set_data_origin_and_reload(base_dir, api_client, new_origin)
|
| 108 |
|
| 109 |
if st.button("Entrar", type="primary"):
|
| 110 |
row = get_user(username) if username else None
|
persistent_data_gate.py
CHANGED
|
@@ -26,6 +26,64 @@ def _load_data_origin(base_dir: Path) -> str:
|
|
| 26 |
return origin
|
| 27 |
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def _load_compliance_flags(base_dir: Path) -> dict:
|
| 30 |
"""Llegeix flags de la secci贸 'compliance' de demo/config.yaml.
|
| 31 |
|
|
|
|
| 26 |
return origin
|
| 27 |
|
| 28 |
|
| 29 |
+
def set_data_origin_and_reload(base_dir: Path, api_client, new_origin: str) -> None:
|
| 30 |
+
"""Actualiza app.data_origin en config.yaml y recarga BDs y media en temp/.
|
| 31 |
+
|
| 32 |
+
- new_origin: "internal" o "external" (cualquier otro valor se ignora).
|
| 33 |
+
- Elimina demo/temp/db, demo/temp/media y demo/temp/pending_videos para
|
| 34 |
+
forzar una nueva importaci贸n acorde al origen seleccionado.
|
| 35 |
+
- Vuelve a llamar a ensure_temp_databases para poblar temp/db.
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
new_origin = str(new_origin).lower()
|
| 39 |
+
if new_origin not in {"internal", "external"}:
|
| 40 |
+
return
|
| 41 |
+
|
| 42 |
+
cfg_path = base_dir / "config.yaml"
|
| 43 |
+
try:
|
| 44 |
+
import yaml
|
| 45 |
+
|
| 46 |
+
cfg = {}
|
| 47 |
+
if cfg_path.exists():
|
| 48 |
+
with cfg_path.open("r", encoding="utf-8") as f:
|
| 49 |
+
cfg = yaml.safe_load(f) or {}
|
| 50 |
+
|
| 51 |
+
app_cfg = cfg.get("app", {}) or {}
|
| 52 |
+
current_origin = str(app_cfg.get("data_origin", "internal")).lower()
|
| 53 |
+
if current_origin == new_origin:
|
| 54 |
+
# Nada que hacer
|
| 55 |
+
return
|
| 56 |
+
|
| 57 |
+
app_cfg["data_origin"] = new_origin
|
| 58 |
+
cfg["app"] = app_cfg
|
| 59 |
+
|
| 60 |
+
with cfg_path.open("w", encoding="utf-8") as f:
|
| 61 |
+
yaml.safe_dump(cfg, f, sort_keys=False, allow_unicode=True)
|
| 62 |
+
except Exception:
|
| 63 |
+
# Si no podemos actualizar config.yaml, no seguimos con el reset
|
| 64 |
+
return
|
| 65 |
+
|
| 66 |
+
# Reinicializar carpetas temporales seg煤n el nuevo origen de datos
|
| 67 |
+
temp_root = base_dir / "temp"
|
| 68 |
+
db_temp_dir = temp_root / "db"
|
| 69 |
+
media_temp_dir = temp_root / "media"
|
| 70 |
+
pending_temp_dir = temp_root / "pending_videos"
|
| 71 |
+
|
| 72 |
+
for d in (db_temp_dir, media_temp_dir, pending_temp_dir):
|
| 73 |
+
try:
|
| 74 |
+
if d.exists():
|
| 75 |
+
shutil.rmtree(d, ignore_errors=True)
|
| 76 |
+
except Exception:
|
| 77 |
+
continue
|
| 78 |
+
|
| 79 |
+
# Volver a importar BDs a demo/temp/db segun new_origin
|
| 80 |
+
try:
|
| 81 |
+
ensure_temp_databases(base_dir, api_client)
|
| 82 |
+
except Exception:
|
| 83 |
+
# No bloquear la app si la recarga falla; se intentar谩 de nou en properes crides
|
| 84 |
+
return
|
| 85 |
+
|
| 86 |
+
|
| 87 |
def _load_compliance_flags(base_dir: Path) -> dict:
|
| 88 |
"""Llegeix flags de la secci贸 'compliance' de demo/config.yaml.
|
| 89 |
|