fix(api): malformed entries aren't parsed as invariants during PUT
parent
d5f6a615ba
commit
89bca64d23
|
@ -324,12 +324,18 @@ pub async fn get_object(
|
|||
})))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct InEntry {
|
||||
pub entity: Option<Address>,
|
||||
pub attribute: String,
|
||||
pub value: EntryValue,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum InEntry {
|
||||
Entry(Entry),
|
||||
pub enum PutInput {
|
||||
Entry(InEntry),
|
||||
EntryList(Vec<Entry>),
|
||||
Invariant(InvariantEntry),
|
||||
Address { entity: InAddress },
|
||||
}
|
||||
|
||||
|
@ -367,7 +373,7 @@ impl TryInto<Address> for InAddress {
|
|||
pub async fn put_object(
|
||||
req: HttpRequest,
|
||||
state: web::Data<State>,
|
||||
payload: Either<web::Json<InEntry>, Multipart>,
|
||||
payload: Either<web::Json<PutInput>, Multipart>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
check_auth(&req, &state)?;
|
||||
|
||||
|
@ -379,28 +385,23 @@ pub async fn put_object(
|
|||
debug!("PUTting {in_entry:?}");
|
||||
|
||||
match in_entry {
|
||||
InEntry::Entry(entry) => Ok(web::block::<_, _, anyhow::Error>(move || {
|
||||
PutInput::Entry(in_entry) => {
|
||||
if let Some(entity) = in_entry.entity {
|
||||
let entry = Entry {
|
||||
entity,
|
||||
attribute: in_entry.attribute,
|
||||
value: in_entry.value,
|
||||
};
|
||||
|
||||
Ok(web::block::<_, _, anyhow::Error>(move || {
|
||||
Ok((
|
||||
Some(connection.insert_entry(entry.clone())?),
|
||||
Some(entry.entity),
|
||||
))
|
||||
})
|
||||
.await
|
||||
.map_err(ErrorInternalServerError)?),
|
||||
InEntry::EntryList(entries) => {
|
||||
web::block(move || {
|
||||
connection.transaction::<_, anyhow::Error, _>(|| {
|
||||
for entry in entries {
|
||||
connection.insert_entry(entry)?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
.await
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
Ok((None, None))
|
||||
}
|
||||
InEntry::Invariant(in_entry) => {
|
||||
.map_err(ErrorInternalServerError)?)
|
||||
} else {
|
||||
let invariant = Entry::try_from(&InvariantEntry {
|
||||
attribute: in_entry.attribute,
|
||||
value: in_entry.value,
|
||||
|
@ -416,7 +417,21 @@ pub async fn put_object(
|
|||
.await
|
||||
.map_err(ErrorInternalServerError)?)
|
||||
}
|
||||
InEntry::Address { entity: in_address } => {
|
||||
}
|
||||
PutInput::EntryList(entries) => {
|
||||
web::block(move || {
|
||||
connection.transaction::<_, anyhow::Error, _>(|| {
|
||||
for entry in entries {
|
||||
connection.insert_entry(entry)?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
.await
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
Ok((None, None))
|
||||
}
|
||||
PutInput::Address { entity: in_address } => {
|
||||
let address = in_address.try_into().map_err(ErrorBadRequest)?;
|
||||
|
||||
let label_entry = match &address {
|
||||
|
|
Loading…
Reference in New Issue