Switch DB layer to Diesel from SeaORM and Fjall #2
4 changed files with 13 additions and 17 deletions
|
@ -7,7 +7,7 @@ use axum_login::AuthSession;
|
|||
use crate::handler::internal_error;
|
||||
use crate::models::documents::{self, NewDocument};
|
||||
use crate::models::users::User;
|
||||
use crate::permissions::query::Permission;
|
||||
use crate::permissions::q::Permission;
|
||||
use crate::permissions::{self};
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -28,9 +28,9 @@ async fn render_documents_page(
|
|||
) -> Result<Response, (StatusCode, String)> {
|
||||
let mut db = provider.db_pool.get().map_err(internal_error)?;
|
||||
let documents =
|
||||
permissions::query::accessible_documents(&mut db, &user.id).map_err(internal_error)?;
|
||||
permissions::q::accessible_documents(&mut db, &user.id).map_err(internal_error)?;
|
||||
let projects =
|
||||
permissions::query::accessible_projects(&mut db, &user.id).map_err(internal_error)?;
|
||||
permissions::q::accessible_projects(&mut db, &user.id).map_err(internal_error)?;
|
||||
|
||||
let values = context! {
|
||||
user => user,
|
||||
|
@ -53,7 +53,7 @@ pub async fn create_document_page(
|
|||
let mut db = provider.db_pool.get().map_err(internal_error)?;
|
||||
|
||||
let projects =
|
||||
permissions::query::accessible_projects(&mut db, &user.id).map_err(internal_error)?;
|
||||
permissions::q::accessible_projects(&mut db, &user.id).map_err(internal_error)?;
|
||||
|
||||
let values = context! {
|
||||
user => user,
|
||||
|
@ -79,7 +79,7 @@ pub async fn create_document_submit(
|
|||
};
|
||||
let mut db = provider.db_pool.get().map_err(internal_error)?;
|
||||
|
||||
let project_allowed = permissions::query::check_user_project(
|
||||
let project_allowed = permissions::q::check_user_project(
|
||||
&mut db,
|
||||
&user.id,
|
||||
&form.project_id.to_string(),
|
||||
|
@ -116,13 +116,9 @@ pub async fn edit_document_page(
|
|||
|
||||
let mut db = provider.db_pool.get().map_err(internal_error)?;
|
||||
|
||||
let document_allowed = permissions::query::check_user_document(
|
||||
&mut db,
|
||||
&user.id,
|
||||
&id.to_string(),
|
||||
Permission::Write,
|
||||
)
|
||||
.map_err(internal_error)?;
|
||||
let document_allowed =
|
||||
permissions::q::check_user_document(&mut db, &user.id, &id.to_string(), Permission::Write)
|
||||
.map_err(internal_error)?;
|
||||
|
||||
if !document_allowed {
|
||||
return Err((StatusCode::FORBIDDEN, "permission denied".to_owned()));
|
||||
|
@ -130,7 +126,7 @@ pub async fn edit_document_page(
|
|||
|
||||
let document = documents::q::by_id(&mut db, &id.to_string()).map_err(internal_error)?;
|
||||
let projects =
|
||||
permissions::query::accessible_projects(&mut db, &user.id).map_err(internal_error)?;
|
||||
permissions::q::accessible_projects(&mut db, &user.id).map_err(internal_error)?;
|
||||
|
||||
let values = context! {
|
||||
user => user,
|
||||
|
@ -160,7 +156,7 @@ pub async fn edit_document_submit(
|
|||
|
||||
let mut db = provider.db_pool.get().map_err(internal_error)?;
|
||||
|
||||
let document_allowed = permissions::query::check_user_document(
|
||||
let document_allowed = permissions::q::check_user_document(
|
||||
&mut db,
|
||||
&user.id,
|
||||
&document_id.to_string(),
|
||||
|
|
|
@ -13,7 +13,7 @@ pub async fn home_page(
|
|||
if let Some(user) = auth_session.user {
|
||||
let mut db = provider.db_pool.get().unwrap();
|
||||
let projects: Vec<Project> =
|
||||
permissions::query::accessible_projects(&mut db, &user.id).unwrap();
|
||||
permissions::q::accessible_projects(&mut db, &user.id).unwrap();
|
||||
|
||||
let values = context! {
|
||||
user => user,
|
||||
|
|
|
@ -26,7 +26,7 @@ async fn render_projects_page(
|
|||
user: User,
|
||||
) -> Result<Response, (StatusCode, String)> {
|
||||
let mut db = provider.db_pool.get().map_err(internal_error)?;
|
||||
let projects = permissions::query::accessible_projects(&mut db, &user.id).unwrap_or_default();
|
||||
let projects = permissions::q::accessible_projects(&mut db, &user.id).unwrap_or_default();
|
||||
|
||||
let values = context! {
|
||||
user => user,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
pub mod query {
|
||||
pub mod q {
|
||||
use diesel::prelude::*;
|
||||
use diesel::SqliteConnection;
|
||||
|
||||
|
|
Loading…
Reference in a new issue