remove all that .map_err nonsense at once
This commit is contained in:
@@ -4,8 +4,8 @@ use maud::{Markup, PreEscaped, html};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
persons::{Name, Person},
|
||||
quotes::{Quote, QuoteLine},
|
||||
tags::Tag,
|
||||
@@ -25,7 +25,7 @@ const LINKS: &[(&str, &str, &str)] = &[
|
||||
pub async fn page(req: Request) -> Result<Markup, CompositeError> {
|
||||
let u = User::authenticate(req.headers()).ok().flatten();
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
Ok(base(
|
||||
"Dashboard | Mnemosyne",
|
||||
|
||||
@@ -5,8 +5,8 @@ use axum::{
|
||||
use maud::{PreEscaped, html};
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::LogEntry,
|
||||
users::{User, auth::UserAuthenticate, permissions::Permission},
|
||||
web::{RedirectViaError, components::nav::nav, icons, pages::base},
|
||||
@@ -16,7 +16,7 @@ pub async fn page(req: Request) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(req.headers())?
|
||||
.ok_or(RedirectViaError(Redirect::to("/login?re=/logs")))?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
let logs = LogEntry::get_all(&tx)?;
|
||||
|
||||
Ok(base(
|
||||
|
||||
@@ -8,8 +8,8 @@ use maud::{PreEscaped, html};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::{LogAction, LogEntry},
|
||||
persons::Person,
|
||||
users::{
|
||||
@@ -100,7 +100,7 @@ pub async fn create(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let p = Person::create(&tx, form.primary_name, u.id)?;
|
||||
LogEntry::new(
|
||||
@@ -111,6 +111,6 @@ pub async fn create(
|
||||
pname: p.primary_name,
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok(Redirect::to("/persons").into_response())
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ use maud::{PreEscaped, html};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::{LogAction, LogEntry},
|
||||
tags::{Tag, TagName},
|
||||
users::{
|
||||
@@ -99,7 +99,7 @@ pub async fn create(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let t = Tag::create(&tx, form.tagname)?;
|
||||
LogEntry::new(
|
||||
@@ -110,6 +110,6 @@ pub async fn create(
|
||||
name: t.name.to_string(),
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok(Redirect::to("/tags").into_response())
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ use maud::{PreEscaped, html};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::{LogAction, LogEntry},
|
||||
users::{
|
||||
User,
|
||||
@@ -73,8 +73,8 @@ pub async fn create_user(
|
||||
Form(form): Form<CreateUserWithPasswordForm>,
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
if !u.has_permission(&tx, Permission::ManuallyCreateUsers)? {
|
||||
return Ok((StatusCode::FORBIDDEN).into_response());
|
||||
@@ -89,6 +89,6 @@ pub async fn create_user(
|
||||
handle: nu.handle.as_str().to_string(),
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok(Redirect::to("/users").into_response())
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ use maud::{PreEscaped, html};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
persons::Name,
|
||||
quotes::{Quote, QuoteLine},
|
||||
users::{User, UserError, auth::UserAuthenticate},
|
||||
@@ -24,8 +24,8 @@ pub async fn page(Path(id): Path<Uuid>, req: Request) -> Result<Response, Compos
|
||||
Some(u) => u,
|
||||
None => return Ok(Redirect::to("/users").into_response()),
|
||||
};
|
||||
let mut conn = database::conn().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let user = match User::get_by_id(&tx, id) {
|
||||
Ok(u) => u,
|
||||
|
||||
@@ -8,8 +8,8 @@ use maud::{PreEscaped, html};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::{LogAction, LogEntry},
|
||||
users::{
|
||||
User,
|
||||
@@ -83,7 +83,7 @@ pub async fn change_handle(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let mut u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let oldhandle = u.handle.as_str().to_string();
|
||||
u.set_handle(&tx, form.handle)?;
|
||||
@@ -96,7 +96,7 @@ pub async fn change_handle(
|
||||
new: u.handle.as_str().to_string(),
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok(Redirect::to("/user-settings").into_response())
|
||||
}
|
||||
|
||||
@@ -110,8 +110,8 @@ pub async fn change_password(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let mut u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
u.set_password(&tx, Some(&form.password))?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok(Redirect::to("/user-settings").into_response())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user