Make model query modules consistent

This commit is contained in:
Nicole Tietz-Sokolskaya 2024-06-02 11:30:18 -04:00
parent f527e73328
commit ef732e49fd
4 changed files with 13 additions and 17 deletions

View file

@ -7,7 +7,7 @@ use axum_login::AuthSession;
use crate::handler::internal_error; use crate::handler::internal_error;
use crate::models::documents::{self, NewDocument}; use crate::models::documents::{self, NewDocument};
use crate::models::users::User; use crate::models::users::User;
use crate::permissions::query::Permission; use crate::permissions::q::Permission;
use crate::permissions::{self}; use crate::permissions::{self};
use crate::prelude::*; use crate::prelude::*;
@ -28,9 +28,9 @@ async fn render_documents_page(
) -> Result<Response, (StatusCode, String)> { ) -> Result<Response, (StatusCode, String)> {
let mut db = provider.db_pool.get().map_err(internal_error)?; let mut db = provider.db_pool.get().map_err(internal_error)?;
let documents = 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 = 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! { let values = context! {
user => user, user => user,
@ -53,7 +53,7 @@ pub async fn create_document_page(
let mut db = provider.db_pool.get().map_err(internal_error)?; let mut db = provider.db_pool.get().map_err(internal_error)?;
let projects = 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! { let values = context! {
user => user, user => user,
@ -79,7 +79,7 @@ pub async fn create_document_submit(
}; };
let mut db = provider.db_pool.get().map_err(internal_error)?; 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, &mut db,
&user.id, &user.id,
&form.project_id.to_string(), &form.project_id.to_string(),
@ -116,12 +116,8 @@ pub async fn edit_document_page(
let mut db = provider.db_pool.get().map_err(internal_error)?; let mut db = provider.db_pool.get().map_err(internal_error)?;
let document_allowed = permissions::query::check_user_document( let document_allowed =
&mut db, permissions::q::check_user_document(&mut db, &user.id, &id.to_string(), Permission::Write)
&user.id,
&id.to_string(),
Permission::Write,
)
.map_err(internal_error)?; .map_err(internal_error)?;
if !document_allowed { if !document_allowed {
@ -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 document = documents::q::by_id(&mut db, &id.to_string()).map_err(internal_error)?;
let projects = 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! { let values = context! {
user => user, user => user,
@ -160,7 +156,7 @@ pub async fn edit_document_submit(
let mut db = provider.db_pool.get().map_err(internal_error)?; 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, &mut db,
&user.id, &user.id,
&document_id.to_string(), &document_id.to_string(),

View file

@ -13,7 +13,7 @@ pub async fn home_page(
if let Some(user) = auth_session.user { if let Some(user) = auth_session.user {
let mut db = provider.db_pool.get().unwrap(); let mut db = provider.db_pool.get().unwrap();
let projects: Vec<Project> = 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! { let values = context! {
user => user, user => user,

View file

@ -26,7 +26,7 @@ async fn render_projects_page(
user: User, user: User,
) -> Result<Response, (StatusCode, String)> { ) -> Result<Response, (StatusCode, String)> {
let mut db = provider.db_pool.get().map_err(internal_error)?; 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! { let values = context! {
user => user, user => user,

View file

@ -1,4 +1,4 @@
pub mod query { pub mod q {
use diesel::prelude::*; use diesel::prelude::*;
use diesel::SqliteConnection; use diesel::SqliteConnection;