♻️ (user): Usa el panel y el acceso del núcleo
pagetop-user deja de depender de pagetop-admin: declara sus páginas en el panel del núcleo y monta sus rutas con su acceso. Quita las comprobaciones que repetían el permiso de la ruta y, con la acción AnonymousDenied, ofrece el inicio de sesión a un usuario anónimo sin acceso, también en las peticiones HTMX.
This commit is contained in:
parent
824dc4a3ab
commit
9ba493c2c4
19 changed files with 343 additions and 501 deletions
|
|
@ -1,7 +1,6 @@
|
|||
//! Menú de cuenta (iniciar y cerrar sesión).
|
||||
|
||||
use pagetop::prelude::*;
|
||||
use pagetop_admin::registry::can_access_admin;
|
||||
use pagetop_htmx::prelude::*;
|
||||
|
||||
use crate::config::SETTINGS;
|
||||
|
|
@ -49,7 +48,7 @@ pub fn account_menu(cx: &Context) -> Nav {
|
|||
if can_access_admin(cx) {
|
||||
menu = menu.with_item(dropdown::Item::link(
|
||||
Lc::t("menu-admin", &LOCALES_USER),
|
||||
cx.route(pagetop_admin::ADMIN_BASE_PATH),
|
||||
cx.route(admin_path("")),
|
||||
));
|
||||
}
|
||||
nav.with_item(nav::Item::dropdown(
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ impl Component for RoleForm {
|
|||
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let action = match self.mode() {
|
||||
RoleFormMode::New => util::join!(ADMIN_ROLES_PATH, "/new"),
|
||||
RoleFormMode::New => util::join!(ADMIN_ROLES_PATH.as_str(), "/new"),
|
||||
RoleFormMode::Edit => role_path(self.role_id().copied().unwrap_or_default(), "edit"),
|
||||
};
|
||||
let action = self.waypoint().append_to(cx.route(action));
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ impl Component for RoleTable {
|
|||
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let pager = Pager::new()
|
||||
.with_base_path(ADMIN_ROLES_PATH)
|
||||
.with_base_path(ADMIN_ROLES_PATH.as_str())
|
||||
.with_extra_query("sort", self.sort().as_str())
|
||||
.with_extra_query("dir", *self.dir())
|
||||
.with_current_page(self.page())
|
||||
|
|
@ -117,7 +117,7 @@ impl Component for RoleTable {
|
|||
);
|
||||
}
|
||||
|
||||
let new_href = waypoint.append_to(cx.route(util::join!(ADMIN_ROLES_PATH, "/new")));
|
||||
let new_href = waypoint.append_to(cx.route(util::join!(ADMIN_ROLES_PATH.as_str(), "/new")));
|
||||
|
||||
Ok(html! {
|
||||
div (self.props().unpack(cx)) {
|
||||
|
|
@ -181,7 +181,7 @@ impl RoleTable {
|
|||
// en los enlaces de ver/editar/permisos, para poder volver exactamente a este mismo estado. Se
|
||||
// construye con `cx.route()` para que preserve el parámetro `lang` cuando corresponda.
|
||||
fn list_href(&self, cx: &Context) -> String {
|
||||
cx.route(ADMIN_ROLES_PATH)
|
||||
cx.route(ADMIN_ROLES_PATH.as_str())
|
||||
.alter_param("sort", self.sort().as_str())
|
||||
.alter_param("dir", *self.dir())
|
||||
.alter_param("page", self.page().to_string())
|
||||
|
|
@ -200,7 +200,7 @@ impl RoleTable {
|
|||
let is_active = *self.sort() == field;
|
||||
let active = is_active.then_some(*self.dir());
|
||||
let next_dir = SortDir::next_for(active);
|
||||
let mut route = cx.route(ADMIN_ROLES_PATH);
|
||||
let mut route = cx.route(ADMIN_ROLES_PATH.as_str());
|
||||
route
|
||||
.alter_param("sort", field.as_str())
|
||||
.alter_param("dir", next_dir);
|
||||
|
|
@ -229,8 +229,8 @@ fn label_cell(role: &RoleListItem, waypoint: &Waypoint) -> Html {
|
|||
}
|
||||
|
||||
// Construye la celda de acciones: gestionar permisos si se tiene `user:admin_permissions`, y
|
||||
// editar/borrar sólo si el rol no está bloqueado por el sistema. Devuelve un componente `Html` para que el marcado se genere cuando
|
||||
// `Table` renderice la celda, no al construir la fila.
|
||||
// editar/borrar sólo si el rol no está bloqueado por el sistema. Devuelve un componente `Html` para
|
||||
// que el marcado se genere cuando `Table` renderice la celda, no al construir la fila.
|
||||
async fn actions_cell(
|
||||
role: &RoleListItem,
|
||||
waypoint: &Waypoint,
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ impl Component for UserForm {
|
|||
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let action = match self.mode() {
|
||||
UserFormMode::New => util::join!(ADMIN_USERS_PATH, "/new"),
|
||||
UserFormMode::New => util::join!(ADMIN_USERS_PATH.as_str(), "/new"),
|
||||
UserFormMode::Edit => user_path(self.user_id().copied().unwrap_or_default(), "edit"),
|
||||
UserFormMode::Profile => PROFILE_EDIT_PATH.into(),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ impl Component for UserTable {
|
|||
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let pager = Pager::new()
|
||||
.with_base_path(ADMIN_USERS_PATH)
|
||||
.with_base_path(ADMIN_USERS_PATH.as_str())
|
||||
.with_extra_query("q", self.query().cloned().unwrap_or_default())
|
||||
.with_extra_query("sort", self.sort().as_str())
|
||||
.with_extra_query("dir", *self.dir())
|
||||
|
|
@ -83,7 +83,7 @@ impl Component for UserTable {
|
|||
);
|
||||
}
|
||||
|
||||
let new_href = waypoint.append_to(cx.route(util::join!(ADMIN_USERS_PATH, "/new")));
|
||||
let new_href = waypoint.append_to(cx.route(util::join!(ADMIN_USERS_PATH.as_str(), "/new")));
|
||||
|
||||
Ok(html! {
|
||||
div (self.props().unpack(cx)) {
|
||||
|
|
@ -143,7 +143,7 @@ impl UserTable {
|
|||
// `waypoint` en los enlaces de ver/editar, para poder volver exactamente a este mismo estado.
|
||||
// Se construye con `cx.route()` para que preserve el parámetro `lang` cuando corresponda.
|
||||
fn list_href(&self, cx: &Context) -> String {
|
||||
let mut route = cx.route(ADMIN_USERS_PATH);
|
||||
let mut route = cx.route(ADMIN_USERS_PATH.as_str());
|
||||
if let Some(q) = self.query().filter(|q| !q.is_empty()) {
|
||||
route.alter_param("q", q);
|
||||
}
|
||||
|
|
@ -167,7 +167,7 @@ impl UserTable {
|
|||
let active = is_active.then_some(*self.dir());
|
||||
let next_dir = SortDir::next_for(active);
|
||||
|
||||
let mut route = cx.route(ADMIN_USERS_PATH);
|
||||
let mut route = cx.route(ADMIN_USERS_PATH.as_str());
|
||||
if let Some(q) = self.query().filter(|q| !q.is_empty()) {
|
||||
route.alter_param("q", q);
|
||||
}
|
||||
|
|
@ -228,7 +228,7 @@ async fn actions_cell(
|
|||
// Construye la celda de roles: sólo la insignia de administrador si lo es (tiene acceso sin
|
||||
// restricciones, así que sus roles no añaden nada), o las insignias de cada rol asignado, o "-" si
|
||||
// no tiene ninguno. Los badges se renderizan aquí mismo (con el `cx` del ciclo de renderizado de
|
||||
// `Table`); el resto del marcado se difiere al `Html` que se devuelve, igual que el resto de celdas.
|
||||
// `Table`); el resto del marcado se difiere al `Html` que se devuelve, como en las demás celdas.
|
||||
async fn roles_cell(user: &UserListItem, cx: &mut Context) -> Html {
|
||||
let mut badges = Vec::with_capacity(user.roles.len().max(1));
|
||||
if user.is_admin {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue