refactor(drive): match DriveKind directly instead of Drive::is_personal()
Drops the boolean is_personal() wrapper in favor of matching DriveKind::Personal/Shared at the two call sites, matching the exhaustive-match convention already used for DriveKind elsewhere (as_str, parse, DriveKindDto::from).
This commit is contained in:
@@ -556,7 +556,10 @@ impl DriveManagementService {
|
|||||||
let drive = self.drive_repo.get_by_id(drive_id).await.map_err(|e| {
|
let drive = self.drive_repo.get_by_id(drive_id).await.map_err(|e| {
|
||||||
DomainError::internal_error("Drive", format!("Failed to fetch drive: {e:?}"))
|
DomainError::internal_error("Drive", format!("Failed to fetch drive: {e:?}"))
|
||||||
})?;
|
})?;
|
||||||
if drive.drive.is_personal() {
|
if matches!(
|
||||||
|
drive.drive.kind,
|
||||||
|
crate::domain::entities::drive::DriveKind::Personal
|
||||||
|
) {
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
target: "audit",
|
target: "audit",
|
||||||
event = "drive_membership.rejected",
|
event = "drive_membership.rejected",
|
||||||
|
|||||||
+5
-2
@@ -2169,14 +2169,17 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let drive = self.drive_repo.get_by_id(drive_id).await.ok()?.drive;
|
let drive = self.drive_repo.get_by_id(drive_id).await.ok()?.drive;
|
||||||
if drive.is_personal() {
|
match drive.kind {
|
||||||
|
crate::domain::entities::drive::DriveKind::Personal => {
|
||||||
let (used, quota) = storage_svc.get_user_storage_info(user_id).await.ok()?;
|
let (used, quota) = storage_svc.get_user_storage_info(user_id).await.ok()?;
|
||||||
Some((used, (quota > 0).then(|| (quota - used).max(0))))
|
Some((used, (quota > 0).then(|| (quota - used).max(0))))
|
||||||
} else {
|
}
|
||||||
|
crate::domain::entities::drive::DriveKind::Shared => {
|
||||||
let used = drive.used_bytes;
|
let used = drive.used_bytes;
|
||||||
Some((used, drive.quota_bytes.map(|q| (q - used).max(0))))
|
Some((used, drive.quota_bytes.map(|q| (q - used).max(0))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds the authorization engine. Today this only constructs `PgAclEngine`;
|
/// Builds the authorization engine. Today this only constructs `PgAclEngine`;
|
||||||
|
|||||||
@@ -131,12 +131,6 @@ impl Drive {
|
|||||||
self.default_for_user == Some(user_id)
|
self.default_for_user == Some(user_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `true` if this drive is a personal drive of any kind (default or
|
|
||||||
/// secondary). Encapsulates the kind check at the call site.
|
|
||||||
pub fn is_personal(&self) -> bool {
|
|
||||||
matches!(self.kind, DriveKind::Personal)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Typed view of `policies` for enforcement code. Lenient deserialise:
|
/// Typed view of `policies` for enforcement code. Lenient deserialise:
|
||||||
/// unknown keys are preserved on disk (the column stays the canonical
|
/// unknown keys are preserved on disk (the column stays the canonical
|
||||||
/// JSONB bag) but ignored here, missing keys default to `false`.
|
/// JSONB bag) but ignored here, missing keys default to `false`.
|
||||||
|
|||||||
Reference in New Issue
Block a user