feat: implementacao inicial do sistema LeadRadar
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import pandas as pd
|
||||
import streamlit as st
|
||||
from api_client import APIClient
|
||||
|
||||
def render_admin_users_view(api_client: APIClient):
|
||||
st.title("🛡️ Gestão de Usuários & Segurança (Admin)")
|
||||
|
||||
user_info = st.session_state.get('user', {})
|
||||
if user_info.get('role') != 'admin':
|
||||
st.error("🚫 Acesso restrito! Esta página é exclusiva para administradores.")
|
||||
return
|
||||
|
||||
c1, c2 = st.columns([2, 1])
|
||||
|
||||
with c1:
|
||||
st.subheader("👥 Operadores e Administradores")
|
||||
users = api_client.get_users()
|
||||
|
||||
if users:
|
||||
df_users = pd.DataFrame([
|
||||
{
|
||||
'ID': u['id'],
|
||||
'Nome': u['nome'],
|
||||
'E-mail': u['email'],
|
||||
'Perfil': u['role'].upper(),
|
||||
'Ativo': 'Sim' if u['ativo'] else 'Não',
|
||||
'Criado em': u['criado_em'][:10] if u.get('criado_em') else ''
|
||||
}
|
||||
for u in users
|
||||
])
|
||||
st.dataframe(df_users, use_container_width=True, hide_index=True)
|
||||
|
||||
st.markdown("### ❌ Excluir Operador")
|
||||
user_to_delete = st.selectbox(
|
||||
"Selecione um usuário para remover:",
|
||||
options=[u for u in users if u['id'] != user_info.get('id')],
|
||||
format_func=lambda u: f"{u['nome']} ({u['email']}) - {u['role'].upper()}"
|
||||
)
|
||||
if user_to_delete:
|
||||
if st.button(f"🗑️ Confirmar Exclusão de {user_to_delete['nome']}", type="secondary"):
|
||||
success, msg = api_client.delete_user(user_to_delete['id'])
|
||||
if success:
|
||||
st.success(msg)
|
||||
st.rerun()
|
||||
else:
|
||||
st.error(msg)
|
||||
else:
|
||||
st.warning("Não foi possível carregar a lista de usuários.")
|
||||
|
||||
with c2:
|
||||
with st.container(border=True):
|
||||
st.subheader("➕ Novo Usuário")
|
||||
nome = st.text_input("Nome Completo", key="add_nome")
|
||||
email = st.text_input("E-mail", key="add_email")
|
||||
password = st.text_input("Senha", type="password", key="add_pass")
|
||||
role = st.selectbox("Perfil de Acesso", ["user", "admin"], format_func=lambda r: "Operador (User)" if r == "user" else "Administrador (Admin)")
|
||||
|
||||
if st.button("✨ Criar Usuário", type="primary", use_container_width=True):
|
||||
if not nome or not email or not password:
|
||||
st.error("Preencha todos os campos obrigatórios.")
|
||||
else:
|
||||
success, msg = api_client.create_user(nome, email, password, role)
|
||||
if success:
|
||||
st.success(msg)
|
||||
st.rerun()
|
||||
else:
|
||||
st.error(msg)
|
||||
Reference in New Issue
Block a user