use proper role instead of manully validating role
Some checks failed
CI/CD Pipeline / deploy-staging (push) Has been cancelled
CI/CD Pipeline / test (push) Has been cancelled
CI/CD Pipeline / deploy-main (push) Has been cancelled

This commit is contained in:
2025-05-29 12:10:35 +02:00
parent 782d68cd03
commit 7027145a9a
2 changed files with 19 additions and 43 deletions

View File

@ -12,11 +12,11 @@ use super::{
notification::Notification,
role::Role,
rower::Rower,
user::User,
user::{User, VorstandUser},
};
use crate::model::user::VecUser;
#[derive(FromRow, Serialize, Deserialize, Clone, Debug)]
#[derive(FromRow, Serialize, Deserialize, Clone, Debug, Difference)]
pub struct Logbook {
pub id: i64,
pub boat_id: i64,
@ -193,11 +193,6 @@ impl LogbookWithBoatAndRowers {
}
}
#[derive(Debug, PartialEq)]
pub enum LogbookAdminUpdateError {
NotAllowed,
}
#[derive(Debug, PartialEq)]
pub enum LogbookUpdateError {
NotYourEntry,
@ -634,16 +629,7 @@ ORDER BY departure DESC
Ok(ret)
}
pub async fn update(
&self,
db: &SqlitePool,
data: LogToUpdate,
user: &User,
) -> Result<(), LogbookAdminUpdateError> {
if !user.has_role(db, "Vorstand").await {
return Err(LogbookAdminUpdateError::NotAllowed);
}
pub async fn update(&self, db: &SqlitePool, data: LogToUpdate, changed_by: &VorstandUser) {
sqlx::query!(
"UPDATE logbook SET boat_id=?, shipmaster=?, steering_person=?, shipmaster_only_steering=?, departure=?, arrival=?, destination=?, distance_in_km=?, comments=?, logtype=? WHERE id=?",
data.boat_id,
@ -660,7 +646,12 @@ ORDER BY departure DESC
)
.execute(db)
.await.unwrap();
Ok(())
Log::create(
db,
format!("{changed_by} updated log entry={:?} to {:?}", self, data),
)
.await;
}
async fn remove_rowers(&self, db: &mut Transaction<'_, Sqlite>) {