Skip loading owner of character for API.

This commit is contained in:
projectmoon 2020-12-31 20:19:45 +00:00
parent 2e2cf30755
commit 6156bba34d
2 changed files with 2 additions and 5 deletions

View File

@ -42,9 +42,6 @@ pub(crate) trait Dao {
async fn update_character_sheet<'a>(&self, character: &'a Character) -> sqlx::Result<()>; async fn update_character_sheet<'a>(&self, character: &'a Character) -> sqlx::Result<()>;
} }
//TODO is:
// - use compile time queries
// - find replacement for diesel migrations
#[rocket::async_trait] #[rocket::async_trait]
impl Dao for SqlitePool { impl Dao for SqlitePool {
async fn load_user_by_id(&self, user_id: i32) -> sqlx::Result<Option<User>> { async fn load_user_by_id(&self, user_id: i32) -> sqlx::Result<Option<User>> {

View File

@ -30,13 +30,13 @@ async fn load_character(
character_id: i32, character_id: i32,
) -> Result<Character, Error> { ) -> Result<Character, Error> {
let logged_in_user = logged_in_user.ok_or(Error::NotLoggedIn)?; let logged_in_user = logged_in_user.ok_or(Error::NotLoggedIn)?;
let owner = conn.load_user(&owner).await?.ok_or(Error::NotFound)?;
let character: Character = conn let character: Character = conn
.load_character(character_id) .load_character(character_id)
.await? .await?
.ok_or(Error::NotFound)?; .ok_or(Error::NotFound)?;
if logged_in_user != &owner { if logged_in_user.username != owner {
return Err(Error::NoPermission); return Err(Error::NoPermission);
} }