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

@ -89,7 +89,7 @@ impl Boat {
.ok()
}
pub async fn shipmaster_allowed(&self, user: &User) -> bool {
pub async fn shipmaster_allowed(&self, db: &SqlitePool, user: &User) -> bool {
if let Some(owner_id) = self.owner {
return owner_id == user.id;
}
@ -98,7 +98,23 @@ impl Boat {
return true;
}
user.is_cox
user.has_role(db, "cox").await
}
pub async fn shipmaster_allowed_tx(
&self,
db: &mut Transaction<'_, Sqlite>,
user: &User,
) -> bool {
if let Some(owner_id) = self.owner {
return owner_id == user.id;
}
if self.amount_seats == 1 {
return true;
}
user.has_role_tx(db, "cox").await
}
pub async fn is_locked(&self, db: &SqlitePool) -> bool {
@ -156,10 +172,10 @@ ORDER BY amount_seats DESC
}
pub async fn for_user(db: &SqlitePool, user: &User) -> Vec<BoatWithDetails> {
if user.is_admin {
if user.has_role(db, "admin").await {
return Self::all(db).await;
}
let boats = if user.is_cox {
let boats = if user.has_role(db, "cox").await {
sqlx::query_as!(
Boat,
"