code: creation function now takes all fields
This commit is contained in:
parent
bce450f744
commit
e77fc115b6
2
TODOS.md
2
TODOS.md
@ -64,3 +64,5 @@ These errors should encompass:
|
|||||||
- Not Found Error: for 404s
|
- Not Found Error: for 404s
|
||||||
- Internal Errors: for 500s
|
- Internal Errors: for 500s
|
||||||
|
|
||||||
|
Repository functions also need to be redesigned to be Results.
|
||||||
|
|
||||||
|
@ -34,7 +34,16 @@ impl AdminRepository for UserRepository {
|
|||||||
name: "User",
|
name: "User",
|
||||||
lookup_key: "id",
|
lookup_key: "id",
|
||||||
display_list: &["id", "username"],
|
display_list: &["id", "username"],
|
||||||
fields: &["username", "description"],
|
fields: &[
|
||||||
|
"username",
|
||||||
|
"first_name",
|
||||||
|
"last_name",
|
||||||
|
"email",
|
||||||
|
"is_staff",
|
||||||
|
"is_active",
|
||||||
|
"is_superuser",
|
||||||
|
],
|
||||||
|
// fields_readonly: &["last_login", "date_joined"]
|
||||||
}
|
}
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
@ -93,6 +102,30 @@ impl AdminRepository for UserRepository {
|
|||||||
user.password = Set(value.as_str().unwrap().to_owned());
|
user.password = Set(value.as_str().unwrap().to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(value) = data.get("first_name") {
|
||||||
|
user.first_name = Set(value.as_str().map(|s| s.to_owned()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(value) = data.get("last_name") {
|
||||||
|
user.last_name = Set(value.as_str().map(|s| s.to_owned()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(value) = data.get("email") {
|
||||||
|
user.email = Set(value.as_str().map(|s| s.to_owned()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(value) = data.get("is_staff") {
|
||||||
|
user.is_staff = Set(value.as_bool().unwrap_or(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(value) = data.get("is_active") {
|
||||||
|
user.is_active = Set(value.as_bool().unwrap_or(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(value) = data.get("is_superuser") {
|
||||||
|
user.is_superuser = Set(value.as_bool().unwrap_or(false));
|
||||||
|
}
|
||||||
|
|
||||||
if let Ok(user) = user.insert(&self.connection).await {
|
if let Ok(user) = user.insert(&self.connection).await {
|
||||||
let id = user.id.to_string();
|
let id = user.id.to_string();
|
||||||
return Some(model.build_item(&*id, serde_json::to_value(&user).unwrap()));
|
return Some(model.build_item(&*id, serde_json::to_value(&user).unwrap()));
|
||||||
|
Loading…
Reference in New Issue
Block a user