csv: Don't panic when needle is not found
This commit is contained in:
parent
96ef1d6a4c
commit
6d752cd050
1 changed files with 14 additions and 8 deletions
|
@ -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 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue