csv: Don't panic when needle is not found

This commit is contained in:
George Kaklamanos 2023-11-20 21:26:08 +02:00
parent 96ef1d6a4c
commit 6d752cd050
No known key found for this signature in database
GPG key ID: C0CAB8A6BDC9399D

View file

@ -57,8 +57,12 @@ impl ACL for CSV {
identifier: identifier, identifier: identifier,
username: "".to_string(), username: "".to_string(),
}; };
let res = self.find::<AuthMethod>(needle, "auth_methods.csv").unwrap(); let res = self.find::<AuthMethod>(needle, "auth_methods.csv");
Some(res.username) return if let Some(r) = res {
Some(r.username)
} else {
None
};
} }
fn get_resource(&self, username: String, id: i8) -> Option<String> { fn get_resource(&self, username: String, id: i8) -> Option<String> {
let needle = ResourceShortcuts { let needle = ResourceShortcuts {
@ -66,14 +70,16 @@ impl ACL for CSV {
id: id, id: id,
resource: "".to_string(), resource: "".to_string(),
}; };
let res = self let res = self.find::<ResourceShortcuts>(needle, "resource_shortcuts.csv");
.find::<ResourceShortcuts>(needle, "resource_shortcuts.csv") return if let Some(r) = res {
.unwrap(); Some(r.resource)
Some(res.resource) } else {
None
};
} }
fn is_allowed(&self, username: String, resource: String) -> Option<()> { fn is_allowed(&self, username: String, resource: String) -> Option<()> {
let needle = ACLEntry { username, resource }; let needle = ACLEntry { username, resource };
self.find::<ACLEntry>(needle, "acl_entries.csv").unwrap(); let res = self.find::<ACLEntry>(needle, "acl_entries.csv");
Some(()) return if let Some(r) = res { Some(()) } else { None };
} }
} }