use proper role instead of manully validating role
This commit is contained in:
@ -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>) {
|
||||
|
Reference in New Issue
Block a user