♻️ (user): Unifica la tabla de datos del perfil
«Mi cuenta» y la ficha de administración muestran los datos del usuario con la misma función, user_details(), en lugar de dos copias idénticas.
This commit is contained in:
parent
e238db1a1b
commit
31f4c516e4
3 changed files with 90 additions and 164 deletions
|
|
@ -7,9 +7,8 @@ use pagetop::prelude::*;
|
|||
|
||||
use crate::account::{Account, UserStatus};
|
||||
use crate::auth;
|
||||
use crate::component::admin::{UserForm, UserFormMode, status_key};
|
||||
use crate::component::{ChangePasswordForm, language_name, multiline_text, theme_name};
|
||||
use crate::config::{user_language_applies, user_timezone_applies};
|
||||
use crate::component::admin::{UserForm, UserFormMode};
|
||||
use crate::component::{ChangePasswordForm, multiline_text, user_details};
|
||||
use crate::entity::{role, user};
|
||||
use crate::error::AuthError;
|
||||
use crate::handlers::admin::map_auth_error;
|
||||
|
|
@ -50,12 +49,11 @@ pub(crate) async fn profile_get(request: HttpRequest) -> Response {
|
|||
Ok(roles) => roles,
|
||||
Err(_) => return ErrorPage::InternalError(Some(request)).into_response(),
|
||||
};
|
||||
let status = UserStatus::from_i16(user.status);
|
||||
let can_edit = has_permission(&request, &UserPermission::EditOwnProfile);
|
||||
let can_change_password = has_permission(&request, &UserPermission::ChangeOwnPassword);
|
||||
|
||||
let mut page = Page::new(request);
|
||||
let details_block = profile_details(&user, status, page.context()).await;
|
||||
let details_block = user_details(&user, page.context()).await;
|
||||
let roles_block = profile_roles(&roles, page.context()).await;
|
||||
let actions = profile_actions(can_edit, can_change_password, page.context());
|
||||
|
||||
|
|
@ -95,83 +93,6 @@ fn profile_actions(can_edit: bool, can_change_password: bool, cx: &Context) -> F
|
|||
actions
|
||||
}
|
||||
|
||||
// Bloque de sólo lectura con los datos de perfil del usuario autenticado.
|
||||
async fn profile_details(user: &user::Model, status: UserStatus, cx: &mut Context) -> Block {
|
||||
let mut table = Table::new()
|
||||
.with_prop(PropsOp::add_classes("user-admin-table"))
|
||||
.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-username-admin", &LOCALES_USER))
|
||||
.with_cell(user.username.as_str()),
|
||||
)
|
||||
.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-email", &LOCALES_USER))
|
||||
.with_cell(user.email.as_str()),
|
||||
)
|
||||
.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-display-name", &LOCALES_USER))
|
||||
.with_cell(user.display_name.as_deref().unwrap_or("-")),
|
||||
)
|
||||
.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-about", &LOCALES_USER))
|
||||
.with_cell(multiline_text(
|
||||
user.about.clone().unwrap_or_else(|| "-".into()),
|
||||
)),
|
||||
);
|
||||
// Sólo se muestran si se aplican, igual que en el formulario de edición.
|
||||
if user_language_applies() {
|
||||
table = table.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-language", &LOCALES_USER))
|
||||
.with_cell(language_name(user.language.as_deref())),
|
||||
);
|
||||
}
|
||||
if user_timezone_applies() {
|
||||
table = table.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-timezone", &LOCALES_USER))
|
||||
.with_cell(user.timezone.as_deref().unwrap_or("-")),
|
||||
);
|
||||
}
|
||||
table = table
|
||||
.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-theme", &LOCALES_USER))
|
||||
.with_cell(theme_name(user.theme.as_deref())),
|
||||
)
|
||||
.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("col-status", &LOCALES_USER))
|
||||
.with_cell(Lc::t(status_key(status), &LOCALES_USER)),
|
||||
)
|
||||
.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-member-since", &LOCALES_USER))
|
||||
.with_cell(cx.format_date(
|
||||
user.created_at.with_timezone(&cx.timezone()).date_naive(),
|
||||
DateFormat::Long,
|
||||
)),
|
||||
);
|
||||
|
||||
if user.is_admin {
|
||||
let badge = Badge::severe(Lc::t("badge-admin", &LOCALES_USER))
|
||||
.render(cx)
|
||||
.await;
|
||||
table = table.with_row(
|
||||
table::Row::new()
|
||||
.with_cell("")
|
||||
.with_cell(Html::with(move |_| badge.clone())),
|
||||
);
|
||||
}
|
||||
|
||||
Block::new()
|
||||
.with_title(Lc::t("title-user-details", &LOCALES_USER))
|
||||
.with_child(table)
|
||||
}
|
||||
|
||||
// Bloque de sólo lectura con los roles del usuario autenticado. A diferencia de la vista de
|
||||
// administración, no enlaza cada rol a su pantalla de detalle: un usuario sin permisos de
|
||||
// administración no puede acceder a ella.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue