Test for user system and comments

This commit is contained in:
Alphonse Paix
2025-10-06 02:08:26 +02:00
parent d96a29ee73
commit 04c2d2b7f5
12 changed files with 501 additions and 29 deletions

View File

@@ -6,7 +6,7 @@ mod posts;
mod subscribers;
use crate::{
authentication::{AuthenticatedUser, Role},
authentication::AuthenticatedUser,
routes::{AppError, error_chain_fmt},
session_state::TypedSession,
templates::{HtmlTemplate, MessageTemplate},
@@ -81,11 +81,10 @@ pub async fn require_admin(
request: Request,
next: Next,
) -> Result<Response, AppError> {
if let Role::Admin = session
.get_role()
if session
.has_admin_permissions()
.await
.context("Error retrieving user role in session.")?
.ok_or(anyhow::anyhow!("Could not find user role in session."))?
{
Ok(next.run(request).await)
} else {

View File

@@ -62,7 +62,10 @@ impl TryFrom<CreateUserForm> for NewUser {
anyhow::bail!("Password mismatch.");
}
let role = value.admin.map(|_| Role::Admin).unwrap_or(Role::Writer);
let role = match value.admin {
Some(true) => Role::Admin,
_ => Role::Writer,
};
let password_hash = crate::authentication::compute_pasword_hash(value.password)
.context("Failed to hash password.")?;
Ok(Self {