in preparation to moving userdata into app, we switched to arbitrary groups
All checks were successful
CI/CD Pipeline / test (push) Successful in 11m4s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped

This commit is contained in:
2023-12-23 21:27:52 +01:00
parent e4da952a62
commit c7d7d0ca83
29 changed files with 396 additions and 256 deletions

View File

@ -272,7 +272,7 @@ ORDER BY departure DESC
if let Ok(log_to_finalize) = TryInto::<LogToFinalize>::try_into(log.clone()) {
//TODO: fix clone() above
if !boat.shipmaster_allowed(created_by_user).await {
if !boat.shipmaster_allowed(db, created_by_user).await {
return Err(LogbookCreateError::UserNotAllowedToUseBoat);
}
@ -343,7 +343,7 @@ ORDER BY departure DESC
}
}
if !boat.shipmaster_allowed(created_by_user).await {
if !boat.shipmaster_allowed(db, created_by_user).await {
return Err(LogbookCreateError::UserNotAllowedToUseBoat);
}
@ -452,7 +452,7 @@ ORDER BY departure DESC
return Err(LogbookUpdateError::SteeringPersonNotInRowers);
}
if !boat.shipmaster_allowed(user).await && self.shipmaster != user.id {
if !boat.shipmaster_allowed_tx(db, user).await && self.shipmaster != user.id {
//second part: shipmaster has entered a different user, then the user should be able to
//`home` it
return Err(LogbookUpdateError::UserNotAllowedToUseBoat);
@ -471,7 +471,7 @@ ORDER BY departure DESC
return Err(LogbookUpdateError::ArrivalNotAfterDeparture);
}
let today = Utc::now().date_naive();
if arr.date() != today && !user.is_admin {
if arr.date() != today && !user.has_role_tx(db, "admin").await {
return Err(LogbookUpdateError::OnlyAllowedToEndTripsEndingToday);
}
@ -506,7 +506,7 @@ ORDER BY departure DESC
pub async fn delete(&self, db: &SqlitePool, user: &User) -> Result<(), LogbookDeleteError> {
Log::create(db, format!("{user:?} deleted trip: {self:?}")).await;
if user.is_admin || user.id == self.shipmaster {
if user.has_role(db, "admin").await || user.id == self.shipmaster {
sqlx::query!("DELETE FROM logbook WHERE id=?", self.id)
.execute(db)
.await