in preparation to moving userdata into app, we switched to arbitrary groups
This commit is contained in:
@ -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,
|
||||
"
|
||||
|
Reference in New Issue
Block a user