aboutsummaryrefslogtreecommitdiffstats
path: root/rust
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-05-14 17:09:50 -0700
committerBryan Newbold <bnewbold@robocracy.org>2019-05-14 17:09:50 -0700
commit822df2600ed7463ad23640559bcc51ecf9908456 (patch)
tree499ff34e5c50de9733cc1a9d488350328ab288e2 /rust
parent43ebd22582c33e95479572c213657a781e1eca3f (diff)
downloadfatcat-822df2600ed7463ad23640559bcc51ecf9908456.tar.gz
fatcat-822df2600ed7463ad23640559bcc51ecf9908456.zip
rust impl endpoint changes
Diffstat (limited to 'rust')
-rw-r--r--rust/src/editing.rs30
-rw-r--r--rust/src/endpoint_handlers.rs44
-rw-r--r--rust/src/endpoints.rs250
-rw-r--r--rust/src/entity_crud.rs12
-rw-r--r--rust/tests/test_api_server_http.rs154
-rw-r--r--rust/tests/test_refs.rs6
6 files changed, 211 insertions, 285 deletions
diff --git a/rust/src/editing.rs b/rust/src/editing.rs
index c17e5964..65cd5bb8 100644
--- a/rust/src/editing.rs
+++ b/rust/src/editing.rs
@@ -5,7 +5,6 @@
use crate::database_models::*;
use crate::database_schema::*;
-use crate::editing_crud::EditgroupCrud;
use crate::entity_crud::EntityCrud;
use crate::errors::{FatcatError, Result};
use crate::identifiers::FatcatId;
@@ -37,37 +36,12 @@ impl EditContext {
}
}
+// This function used to be more complex, and take a database response.
pub fn make_edit_context(
- conn: &DbConn,
editor_id: FatcatId,
- editgroup_id: Option<FatcatId>,
+ editgroup_id: FatcatId,
autoaccept: bool,
- description: Option<String>,
- extra: Option<serde_json::Value>,
) -> Result<EditContext> {
- // *either* autoaccept is false and editgroup_id is Some, *or* autoaccept is true and
- // editgroup_id is None
- let editgroup_id: FatcatId = match (editgroup_id, autoaccept) {
- (Some(eg), false) => eg,
- (None, true) => {
- let eg = Editgroup {
- editgroup_id: None,
- editor_id: Some(editor_id.to_string()),
- editor: None,
- changelog_index: None,
- submitted: None,
- description: description,
- extra: extra,
- annotations: None,
- edits: None,
- };
- let row = eg.db_create(conn, autoaccept)?;
- FatcatId::from_uuid(&row.id)
- }
- _ => Err(FatcatError::BadRequest(
- "unsupported batch editgroup/accept combination".to_string(),
- ))?,
- };
Ok(EditContext {
editor_id,
editgroup_id,
diff --git a/rust/src/endpoint_handlers.rs b/rust/src/endpoint_handlers.rs
index a19d33f9..dcc647ea 100644
--- a/rust/src/endpoint_handlers.rs
+++ b/rust/src/endpoint_handlers.rs
@@ -17,30 +17,28 @@ use diesel::prelude::*;
use fatcat_api_spec::models;
use fatcat_api_spec::models::*;
-macro_rules! entity_batch_handler {
- ($post_batch_handler:ident, $model:ident) => {
- pub fn $post_batch_handler(
+macro_rules! entity_auto_batch_handler {
+ ($post_auto_batch_handler:ident, $model:ident) => {
+ pub fn $post_auto_batch_handler(
&self,
conn: &DbConn,
+ editgroup: Editgroup,
entity_list: &[models::$model],
- autoaccept: bool,
editor_id: FatcatId,
- editgroup_id: Option<FatcatId>,
- description: Option<String>,
- extra: Option<serde_json::Value>,
- ) -> Result<Vec<EntityEdit>> {
+ ) -> Result<Editgroup> {
- let edit_context = make_edit_context(conn, editor_id, editgroup_id, autoaccept, description, extra)?;
+ let editgroup_row = editgroup.db_create(conn, true)?;
+ let editgroup_id = FatcatId::from_uuid(&editgroup_row.id);
+ let edit_context = make_edit_context(editor_id, editgroup_id, true)?;
edit_context.check(&conn)?;
let model_list: Vec<&models::$model> = entity_list.iter().map(|e| e).collect();
- let edits = $model::db_create_batch(conn, &edit_context, model_list.as_slice())?;
+ let _edits = $model::db_create_batch(conn, &edit_context, model_list.as_slice())?;
- if autoaccept {
- let _clr: ChangelogRow = diesel::insert_into(changelog::table)
- .values((changelog::editgroup_id.eq(edit_context.editgroup_id.to_uuid()),))
- .get_result(conn)?;
- }
- edits.into_iter().map(|e| e.into_model()).collect()
+ let _clr: ChangelogRow = diesel::insert_into(changelog::table)
+ .values((changelog::editgroup_id.eq(edit_context.editgroup_id.to_uuid()),))
+ .get_result(conn)?;
+ // XXX: edits.into_iter().map(|e| e.into_model()).collect()
+ self.get_editgroup_handler(conn, editgroup_id)
}
}
}
@@ -620,11 +618,11 @@ impl Server {
Ok((editor_row.into_model(), created))
}
- entity_batch_handler!(create_container_batch_handler, ContainerEntity);
- entity_batch_handler!(create_creator_batch_handler, CreatorEntity);
- entity_batch_handler!(create_file_batch_handler, FileEntity);
- entity_batch_handler!(create_fileset_batch_handler, FilesetEntity);
- entity_batch_handler!(create_webcapture_batch_handler, WebcaptureEntity);
- entity_batch_handler!(create_release_batch_handler, ReleaseEntity);
- entity_batch_handler!(create_work_batch_handler, WorkEntity);
+ entity_auto_batch_handler!(create_container_auto_batch_handler, ContainerEntity);
+ entity_auto_batch_handler!(create_creator_auto_batch_handler, CreatorEntity);
+ entity_auto_batch_handler!(create_file_auto_batch_handler, FileEntity);
+ entity_auto_batch_handler!(create_fileset_auto_batch_handler, FilesetEntity);
+ entity_auto_batch_handler!(create_webcapture_auto_batch_handler, WebcaptureEntity);
+ entity_auto_batch_handler!(create_release_auto_batch_handler, ReleaseEntity);
+ entity_auto_batch_handler!(create_work_auto_batch_handler, WorkEntity);
}
diff --git a/rust/src/endpoints.rs b/rust/src/endpoints.rs
index 4817184f..7d6db908 100644
--- a/rust/src/endpoints.rs
+++ b/rust/src/endpoints.rs
@@ -69,11 +69,12 @@ macro_rules! wrap_entity_handlers {
// stable doesn't have a mechanism to "concat" or generate new identifiers in macros, at least
// in the context of defining new functions.
// The only stable approach I know of would be: https://github.com/dtolnay/mashup
- ($get_fn:ident, $get_resp:ident, $post_fn:ident, $post_resp:ident, $post_batch_fn:ident,
- $post_batch_handler:ident, $post_batch_resp:ident, $update_fn:ident, $update_resp:ident,
- $delete_fn:ident, $delete_resp:ident, $get_history_fn:ident, $get_history_resp:ident,
- $get_edit_fn:ident, $get_edit_resp:ident, $delete_edit_fn:ident, $delete_edit_resp:ident,
- $get_rev_fn:ident, $get_rev_resp:ident, $get_redirects_fn:ident, $get_redirects_resp:ident,
+ ($get_fn:ident, $get_resp:ident, $post_fn:ident, $post_resp:ident, $auto_batch_type:ident,
+ $post_auto_batch_fn:ident, $post_auto_batch_handler:ident, $post_auto_batch_resp:ident,
+ $update_fn:ident, $update_resp:ident, $delete_fn:ident, $delete_resp:ident,
+ $get_history_fn:ident, $get_history_resp:ident, $get_edit_fn:ident, $get_edit_resp:ident,
+ $delete_edit_fn:ident, $delete_edit_resp:ident, $get_rev_fn:ident, $get_rev_resp:ident,
+ $get_redirects_fn:ident, $get_redirects_resp:ident,
$model:ident) => {
fn $get_fn(
@@ -110,8 +111,8 @@ macro_rules! wrap_entity_handlers {
fn $post_fn(
&self,
- entity: models::$model,
editgroup_id: String,
+ entity: models::$model,
context: &Context,
) -> Box<Future<Item = $post_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
@@ -120,7 +121,7 @@ macro_rules! wrap_entity_handlers {
let auth_context = self.auth_confectionary.require_auth(&conn, &context.auth_data, Some(stringify!($post_fn)))?;
auth_context.require_role(FatcatRole::Editor)?;
auth_context.require_editgroup(&conn, editgroup_id)?;
- let edit_context = make_edit_context(&conn, auth_context.editor_id, Some(editgroup_id), false, None, None)?;
+ let edit_context = make_edit_context(auth_context.editor_id, editgroup_id, false)?;
edit_context.check(&conn)?;
entity.db_create(&conn, &edit_context)?.into_model()
}).map_err(|e| FatcatError::from(e)) {
@@ -133,54 +134,51 @@ macro_rules! wrap_entity_handlers {
Box::new(futures::done(Ok(ret)))
}
- fn $post_batch_fn(
+ fn $post_auto_batch_fn(
&self,
- entity_list: &Vec<models::$model>,
- autoaccept: Option<bool>,
- editgroup_id: Option<String>,
- description: Option<String>,
- extra: Option<String>,
+ auto_batch: $auto_batch_type,
context: &Context,
- ) -> Box<Future<Item = $post_batch_resp, Error = ApiError> + Send> {
+ ) -> Box<Future<Item = $post_auto_batch_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
let ret = match conn.transaction(|| {
- let auth_context = self.auth_confectionary.require_auth(&conn, &context.auth_data, Some(stringify!($post_batch_fn)))?;
- let autoaccept = autoaccept.unwrap_or(false);
- if autoaccept {
- auth_context.require_role(FatcatRole::Admin)?;
- } else {
- auth_context.require_role(FatcatRole::Editor)?;
- };
- let editgroup_id = if let Some(s) = editgroup_id {
- // make_edit_context() checks for "both editgroup_id and autosubmit" error case
- let eg_id = FatcatId::from_str(&s)?;
- auth_context.require_editgroup(&conn, eg_id)?;
- Some(eg_id)
- } else { None };
- let extra: Option<serde_json::Value> = match extra {
- Some(v) => serde_json::from_str(&v)?,
- None => None,
+ let auth_context = self.auth_confectionary.require_auth(&conn, &context.auth_data, Some(stringify!($post_auto_batch_fn)))?;
+ auth_context.require_role(FatcatRole::Admin)?;
+ let mut editgroup = auto_batch.editgroup.clone();
+ // TODO: this is duplicated code with create_editgroup()
+ match editgroup.editor_id.clone() {
+ Some(editor_id) => {
+ if editor_id != auth_context.editor_id.to_string()
+ && !auth_context.has_role(FatcatRole::Admin)
+ {
+ return Err(FatcatError::InsufficientPrivileges(
+ "not authorized to create editgroups in others' names".to_string()
+ ))
+ }
+ }
+ None => {
+ editgroup.editor_id = Some(auth_context.editor_id.to_string());
+ }
};
- self.$post_batch_handler(&conn, entity_list, autoaccept, auth_context.editor_id, editgroup_id, description, extra)
- }).map_err(|e| FatcatError::from(e)) {
- Ok(edits) => {
- self.metrics.count("entities.created", edits.len() as i64).ok();
- if let Some(true) = autoaccept {
- self.metrics.incr("editgroup.created").ok();
- self.metrics.incr("editgroup.accepted").ok();
- };
- $post_batch_resp::CreatedEntities(edits)
+ self.$post_auto_batch_handler(&conn, editgroup, &auto_batch.entity_list, auth_context.editor_id)
+ .map_err(|e| FatcatError::from(e))
+ }) {
+ Ok(editgroup) => {
+ // TODO: need a count helper on editgroup
+ //self.metrics.count("entities.created", count as i64).ok();
+ self.metrics.incr("editgroup.created").ok();
+ self.metrics.incr("editgroup.accepted").ok();
+ $post_auto_batch_resp::CreatedEditgroup(editgroup)
},
- Err(fe) => generic_auth_err_responses!(fe, $post_batch_resp),
+ Err(fe) => generic_auth_err_responses!(fe, $post_auto_batch_resp),
};
Box::new(futures::done(Ok(ret)))
}
fn $update_fn(
&self,
+ editgroup_id: String,
ident: String,
entity: models::$model,
- editgroup_id: String,
context: &Context,
) -> Box<Future<Item = $update_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
@@ -190,7 +188,7 @@ macro_rules! wrap_entity_handlers {
auth_context.require_role(FatcatRole::Editor)?;
let entity_id = FatcatId::from_str(&ident)?;
auth_context.require_editgroup(&conn, editgroup_id)?;
- let edit_context = make_edit_context(&conn, auth_context.editor_id, Some(editgroup_id), false, None, None)?;
+ let edit_context = make_edit_context(auth_context.editor_id, editgroup_id, false)?;
edit_context.check(&conn)?;
entity.db_update(&conn, &edit_context, entity_id)?.into_model()
}).map_err(|e| FatcatError::from(e)) {
@@ -205,8 +203,8 @@ macro_rules! wrap_entity_handlers {
fn $delete_fn(
&self,
- ident: String,
editgroup_id: String,
+ ident: String,
context: &Context,
) -> Box<Future<Item = $delete_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
@@ -216,7 +214,7 @@ macro_rules! wrap_entity_handlers {
auth_context.require_role(FatcatRole::Editor)?;
let entity_id = FatcatId::from_str(&ident)?;
auth_context.require_editgroup(&conn, editgroup_id)?;
- let edit_context = make_edit_context(&conn, auth_context.editor_id, Some(editgroup_id), false, None, None)?;
+ let edit_context = make_edit_context(auth_context.editor_id, editgroup_id, false)?;
edit_context.check(&conn)?;
$model::db_delete(&conn, &edit_context, entity_id)?.into_model()
}).map_err(|e| FatcatError::from(e)) {
@@ -300,18 +298,27 @@ macro_rules! wrap_entity_handlers {
fn $delete_edit_fn(
&self,
+ editgroup_id: String,
edit_id: String,
context: &Context,
) -> Box<Future<Item = $delete_edit_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
let ret = match conn.transaction(|| {
+ let editgroup_id = FatcatId::from_str(&editgroup_id)?;
let edit_id = Uuid::from_str(&edit_id)?;
let auth_context = self.auth_confectionary.require_auth(&conn, &context.auth_data, Some(stringify!($delete_edit_fn)))?;
auth_context.require_role(FatcatRole::Editor)?;
let edit = $model::db_get_edit(&conn, edit_id)?;
- auth_context.require_editgroup(&conn, FatcatId::from_uuid(&edit.editgroup_id))?;
+ if !(edit.editgroup_id == editgroup_id.to_uuid()) {
+ return Err(FatcatError::BadRequest(
+ "editgroup_id parameter didn't match that of the edit".to_string()
+ ))
+ }
+ auth_context.require_editgroup(&conn, editgroup_id)?;
+ // check for editgroup being deleted happens in db_delete_edit()
$model::db_delete_edit(&conn, edit_id)
- }).map_err(|e| FatcatError::from(e)) {
+ .map_err(|e| FatcatError::from(e))
+ }) {
Ok(()) =>
$delete_edit_resp::DeletedEdit(Success {
success: true,
@@ -429,9 +436,10 @@ impl Api for Server {
GetContainerResponse,
create_container,
CreateContainerResponse,
- create_container_batch,
- create_container_batch_handler,
- CreateContainerBatchResponse,
+ ContainerAutoBatch,
+ create_container_auto_batch,
+ create_container_auto_batch_handler,
+ CreateContainerAutoBatchResponse,
update_container,
UpdateContainerResponse,
delete_container,
@@ -454,9 +462,10 @@ impl Api for Server {
GetCreatorResponse,
create_creator,
CreateCreatorResponse,
- create_creator_batch,
- create_creator_batch_handler,
- CreateCreatorBatchResponse,
+ CreatorAutoBatch,
+ create_creator_auto_batch,
+ create_creator_auto_batch_handler,
+ CreateCreatorAutoBatchResponse,
update_creator,
UpdateCreatorResponse,
delete_creator,
@@ -478,9 +487,10 @@ impl Api for Server {
GetFileResponse,
create_file,
CreateFileResponse,
- create_file_batch,
- create_file_batch_handler,
- CreateFileBatchResponse,
+ FileAutoBatch,
+ create_file_auto_batch,
+ create_file_auto_batch_handler,
+ CreateFileAutoBatchResponse,
update_file,
UpdateFileResponse,
delete_file,
@@ -502,9 +512,10 @@ impl Api for Server {
GetFilesetResponse,
create_fileset,
CreateFilesetResponse,
- create_fileset_batch,
- create_fileset_batch_handler,
- CreateFilesetBatchResponse,
+ FilesetAutoBatch,
+ create_fileset_auto_batch,
+ create_fileset_auto_batch_handler,
+ CreateFilesetAutoBatchResponse,
update_fileset,
UpdateFilesetResponse,
delete_fileset,
@@ -526,9 +537,10 @@ impl Api for Server {
GetWebcaptureResponse,
create_webcapture,
CreateWebcaptureResponse,
- create_webcapture_batch,
- create_webcapture_batch_handler,
- CreateWebcaptureBatchResponse,
+ WebcaptureAutoBatch,
+ create_webcapture_auto_batch,
+ create_webcapture_auto_batch_handler,
+ CreateWebcaptureAutoBatchResponse,
update_webcapture,
UpdateWebcaptureResponse,
delete_webcapture,
@@ -550,9 +562,10 @@ impl Api for Server {
GetReleaseResponse,
create_release,
CreateReleaseResponse,
- create_release_batch,
- create_release_batch_handler,
- CreateReleaseBatchResponse,
+ ReleaseAutoBatch,
+ create_release_auto_batch,
+ create_release_auto_batch_handler,
+ CreateReleaseAutoBatchResponse,
update_release,
UpdateReleaseResponse,
delete_release,
@@ -574,9 +587,10 @@ impl Api for Server {
GetWorkResponse,
create_work,
CreateWorkResponse,
- create_work_batch,
- create_work_batch_handler,
- CreateWorkBatchResponse,
+ WorkAutoBatch,
+ create_work_auto_batch,
+ create_work_auto_batch_handler,
+ CreateWorkAutoBatchResponse,
update_work,
UpdateWorkResponse,
delete_work,
@@ -941,31 +955,31 @@ impl Api for Server {
context: &Context,
) -> Box<Future<Item = CreateEditgroupResponse, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
- let ret = match conn
- .transaction(|| {
- let auth_context = self.auth_confectionary.require_auth(
- &conn,
- &context.auth_data,
- Some("create_editgroup"),
- )?;
- auth_context.require_role(FatcatRole::Editor)?;
- let mut entity = entity.clone();
- match entity.editor_id.clone() {
- Some(editor_id) => {
- if editor_id != auth_context.editor_id.to_string()
- && !auth_context.has_role(FatcatRole::Admin)
- {
- bail!("not authorized to create editgroups in others' names");
- }
- }
- None => {
- entity.editor_id = Some(auth_context.editor_id.to_string());
+ let ret = match conn.transaction(|| {
+ let auth_context = self.auth_confectionary.require_auth(
+ &conn,
+ &context.auth_data,
+ Some("create_editgroup"),
+ )?;
+ auth_context.require_role(FatcatRole::Editor)?;
+ let mut entity = entity.clone();
+ match entity.editor_id.clone() {
+ Some(editor_id) => {
+ if editor_id != auth_context.editor_id.to_string()
+ && !auth_context.has_role(FatcatRole::Admin)
+ {
+ return Err(FatcatError::InsufficientPrivileges(
+ "not authorized to create editgroups in others' names".to_string(),
+ ));
}
- };
- self.create_editgroup_handler(&conn, entity)
- })
- .map_err(|e| FatcatError::from(e))
- {
+ }
+ None => {
+ entity.editor_id = Some(auth_context.editor_id.to_string());
+ }
+ };
+ self.create_editgroup_handler(&conn, entity)
+ .map_err(|e| FatcatError::from(e))
+ }) {
Ok(eg) => {
self.metrics.incr("editgroup.created").ok();
CreateEditgroupResponse::SuccessfullyCreated(eg)
@@ -1035,33 +1049,35 @@ impl Api for Server {
context: &Context,
) -> Box<Future<Item = CreateEditgroupAnnotationResponse, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
- let ret = match conn
- .transaction(|| {
- let auth_context = self.auth_confectionary.require_auth(
- &conn,
- &context.auth_data,
- Some("create_editgroup_annotation"),
- )?;
- auth_context.require_role(FatcatRole::Editor)?;
- let editgroup_id = FatcatId::from_str(&editgroup_id)?;
- let mut annotation = annotation.clone();
- annotation.editgroup_id = Some(editgroup_id.to_string());
- match annotation.editor_id.clone() {
- Some(editor_id) => {
- if editor_id != auth_context.editor_id.to_string()
- && !auth_context.has_role(FatcatRole::Superuser)
- {
- bail!("not authorized to annotate in others' names");
- }
- }
- None => {
- annotation.editor_id = Some(auth_context.editor_id.to_string());
+ let ret = match conn.transaction(|| {
+ let auth_context = self.auth_confectionary.require_auth(
+ &conn,
+ &context.auth_data,
+ Some("create_editgroup_annotation"),
+ )?;
+ auth_context.require_role(FatcatRole::Editor)?;
+ let editgroup_id = FatcatId::from_str(&editgroup_id)?;
+ let mut annotation = annotation.clone();
+ annotation.editgroup_id = Some(editgroup_id.to_string());
+ match annotation.editor_id.clone() {
+ Some(editor_id) => {
+ if editor_id != auth_context.editor_id.to_string()
+ && !auth_context.has_role(FatcatRole::Superuser)
+ {
+ return Err(FatcatError::BadRequest(
+ "not authorized to annotate in others' names".to_string(),
+ ));
}
- };
- annotation.db_create(&conn).map(|a| a.into_model())
- })
- .map_err(|e: Error| FatcatError::from(e))
- {
+ }
+ None => {
+ annotation.editor_id = Some(auth_context.editor_id.to_string());
+ }
+ };
+ annotation
+ .db_create(&conn)
+ .map(|a| a.into_model())
+ .map_err(|e: Error| FatcatError::from(e))
+ }) {
Ok(annotation) => CreateEditgroupAnnotationResponse::Created(annotation),
Err(fe) => generic_auth_err_responses!(fe, CreateEditgroupAnnotationResponse),
};
diff --git a/rust/src/entity_crud.rs b/rust/src/entity_crud.rs
index 8f4c33a8..bdb83560 100644
--- a/rust/src/entity_crud.rs
+++ b/rust/src/entity_crud.rs
@@ -385,13 +385,14 @@ macro_rules! generic_db_create_batch {
rev_ids
.into_iter()
.zip(ident_ids.into_iter())
- .map(|(rev_id, ident_id)| Self::EditNewRow {
+ .zip(models.into_iter().map(|m| m.edit_extra.clone()))
+ .map(|((rev_id, ident_id), edit_extra)| Self::EditNewRow {
editgroup_id: edit_context.editgroup_id.to_uuid(),
rev_id: Some(rev_id),
ident_id,
redirect_id: None,
prev_rev: None,
- extra_json: edit_context.extra_json.clone(),
+ extra_json: edit_extra,
})
.collect::<Vec<Self::EditNewRow>>(),
)
@@ -519,7 +520,7 @@ macro_rules! generic_db_delete {
$edit_table::rev_id.eq(None::<Uuid>),
$edit_table::redirect_id.eq(None::<Uuid>),
$edit_table::prev_rev.eq(current.rev_id),
- $edit_table::extra_json.eq(&edit_context.extra_json),
+ //$edit_table::extra_json.eq(None::<?>),
))
.get_result(conn)?;
@@ -1816,13 +1817,14 @@ impl EntityCrud for ReleaseEntity {
rev_ids
.into_iter()
.zip(ident_ids.into_iter())
- .map(|(rev_id, ident_id)| Self::EditNewRow {
+ .zip(models.into_iter().map(|m| m.edit_extra.clone()))
+ .map(|((rev_id, ident_id), edit_extra)| Self::EditNewRow {
editgroup_id: edit_context.editgroup_id.to_uuid(),
rev_id: Some(rev_id),
ident_id,
redirect_id: None,
prev_rev: None,
- extra_json: edit_context.extra_json.clone(),
+ extra_json: edit_extra,
})
.collect::<Vec<Self::EditNewRow>>(),
)
diff --git a/rust/tests/test_api_server_http.rs b/rust/tests/test_api_server_http.rs
index aa8f4e01..d88af31c 100644
--- a/rust/tests/test_api_server_http.rs
+++ b/rust/tests/test_api_server_http.rs
@@ -528,7 +528,7 @@ fn test_post_container() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/container?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/container",
editgroup_id
),
headers,
@@ -546,9 +546,10 @@ fn test_post_batch_container() {
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/container/batch?autoaccept=true",
+ "http://localhost:9411/v0/editgroup/auto/container/batch",
headers,
- r#"[{"name": "test journal"}, {"name": "another test journal"}]"#,
+ r#"{"editgroup": {},
+ "entity_list": [{"name": "test journal"}, {"name": "another test journal"}]}"#,
&router,
),
status::Created,
@@ -564,7 +565,7 @@ fn test_post_creator() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/creator?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/creator",
editgroup_id
),
headers,
@@ -583,10 +584,7 @@ fn test_post_file() {
helpers::check_http_response(
request::post(
- &format!(
- "http://localhost:9411/v0/file?editgroup_id={}",
- editgroup_id
- ),
+ &format!("http://localhost:9411/v0/editgroup/{}/file", editgroup_id),
headers.clone(),
r#"{ }"#,
&router,
@@ -597,7 +595,7 @@ fn test_post_file() {
helpers::check_http_response(
request::post(
- &format!("http://localhost:9411/v0/file?editgroup_id={}", editgroup_id),
+ &format!("http://localhost:9411/v0/editgroup/{}/file", editgroup_id),
headers.clone(),
r#"{"size": 76543,
"sha1": "f0000000000000008b7eb2a93e6d0440c1f3e7f8",
@@ -653,7 +651,7 @@ fn test_post_fileset() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/fileset?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/fileset",
editgroup_id
),
headers.clone(),
@@ -666,7 +664,7 @@ fn test_post_fileset() {
helpers::check_http_response(
request::post(
- &format!("http://localhost:9411/v0/fileset?editgroup_id={}", editgroup_id),
+ &format!("http://localhost:9411/v0/editgroup/{}/fileset", editgroup_id),
headers.clone(),
r#"{"manifest": [
{"path": "new_file.txt", "size": 12345, "sha1": "e9dd75237c94b209dc3ccd52722de6931a310ba3" },
@@ -712,7 +710,7 @@ fn test_post_webcapture() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/webcapture?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/webcapture",
editgroup_id
),
headers.clone(),
@@ -727,7 +725,7 @@ fn test_post_webcapture() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/webcapture?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/webcapture",
editgroup_id
),
headers.clone(),
@@ -781,7 +779,7 @@ fn test_post_release() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -801,7 +799,7 @@ fn test_post_release() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -819,7 +817,7 @@ fn test_post_release() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -868,7 +866,7 @@ fn test_post_release() {
/* XXX: doesn't fail
helpers::check_http_response(
request::post(
- &format!("http://localhost:9411/v0/release?editgroup_id={}", editgroup_id),
+ &format!("http://localhost:9411/v0/editgroup/{}/release", editgroup_id),
headers.clone(),
r#"{"title": "secret minimal paper the second",
"asdf123": "lalala"
@@ -888,10 +886,7 @@ fn test_post_work() {
helpers::check_http_response(
request::post(
- &format!(
- "http://localhost:9411/v0/work?editgroup_id={}",
- editgroup_id
- ),
+ &format!("http://localhost:9411/v0/editgroup/{}/work", editgroup_id),
headers.clone(),
// TODO: target_work_id
r#"{
@@ -911,10 +906,7 @@ fn test_update_work() {
helpers::check_http_response(
request::post(
- &format!(
- "http://localhost:9411/v0/work?editgroup_id={}",
- editgroup_id
- ),
+ &format!("http://localhost:9411/v0/editgroup/{}/work", editgroup_id),
headers.clone(),
r#"{
"extra": { "source": "other speculation" }
@@ -945,7 +937,7 @@ fn test_delete_work() {
helpers::check_http_response(
request::delete(
&format!(
- "http://localhost:9411/v0/work/aaaaaaaaaaaaavkvaaaaaaaaai?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/work/aaaaaaaaaaaaavkvaaaaaaaaai",
editgroup_id
),
headers.clone(),
@@ -988,7 +980,7 @@ fn test_accept_editgroup() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/container?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/container",
editgroup_id
),
headers.clone(),
@@ -1004,7 +996,7 @@ fn test_accept_editgroup() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/container?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/container",
editgroup_id
),
headers.clone(),
@@ -1104,7 +1096,7 @@ fn test_400() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers,
@@ -1183,7 +1175,7 @@ fn test_bad_external_idents() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1200,7 +1192,7 @@ fn test_bad_external_idents() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1217,7 +1209,7 @@ fn test_bad_external_idents() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1236,7 +1228,7 @@ fn test_bad_external_idents() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1255,7 +1247,7 @@ fn test_bad_external_idents() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1274,7 +1266,7 @@ fn test_bad_external_idents() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1293,7 +1285,7 @@ fn test_bad_external_idents() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1320,7 +1312,7 @@ fn test_abstracts() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1347,7 +1339,7 @@ fn test_abstracts() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1420,7 +1412,7 @@ fn test_contribs() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1460,51 +1452,6 @@ fn test_contribs() {
}
#[test]
-fn test_post_batch_autoaccept() {
- let (headers, router, conn) = helpers::setup_http();
-
- // "true"
- helpers::check_http_response(
- request::post(
- "http://localhost:9411/v0/container/batch?autoaccept=true",
- headers.clone(),
- r#"[{"name": "test journal"}, {"name": "another test journal"}]"#,
- &router,
- ),
- status::Created,
- None,
- );
-
- // "n" (TODO)
- let editgroup_id = helpers::quick_editgroup(&conn);
- helpers::check_http_response(
- request::post(
- &format!(
- "http://localhost:9411/v0/container/batch?autoaccept=n&editgroup_id={}",
- editgroup_id
- ),
- headers.clone(),
- r#"[{"name": "test journal"}, {"name": "another test journal"}]"#,
- &router,
- ),
- status::BadRequest, // TODO
- None,
- );
-
- // editgroup
- helpers::check_http_response(
- request::post(
- "http://localhost:9411/v0/container/batch?autoaccept=yes&editgroup_id=asdf",
- headers.clone(),
- r#"[{"name": "test journal"}, {"name": "another test journal"}]"#,
- &router,
- ),
- status::BadRequest,
- None,
- );
-}
-
-#[test]
fn test_release_dates() {
let (headers, router, conn) = helpers::setup_http();
let editgroup_id = helpers::quick_editgroup(&conn);
@@ -1513,7 +1460,7 @@ fn test_release_dates() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1532,7 +1479,7 @@ fn test_release_dates() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1551,7 +1498,7 @@ fn test_release_dates() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1568,7 +1515,7 @@ fn test_release_dates() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1587,7 +1534,7 @@ fn test_release_dates() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1607,7 +1554,7 @@ fn test_release_dates() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1627,7 +1574,7 @@ fn test_release_dates() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1646,7 +1593,7 @@ fn test_release_dates() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1665,7 +1612,7 @@ fn test_release_dates() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1690,7 +1637,7 @@ fn test_release_types() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1708,7 +1655,7 @@ fn test_release_types() {
helpers::check_http_response(
request::post(
&format!(
- "http://localhost:9411/v0/release?editgroup_id={}",
+ "http://localhost:9411/v0/editgroup/{}/release",
editgroup_id
),
headers.clone(),
@@ -1953,20 +1900,11 @@ fn test_query_params() {
helpers::check_http_response(
request::post(
- "http://localhost:9411/v0/container/batch?autoaccept=asdf",
+ "http://localhost:9411/v0/editgroup/auto/container/batch",
headers.clone(),
- r#"[{"name": "test journal"}, {"name": "another test journal"}]"#,
- &router,
- ),
- status::BadRequest,
- Some("boolean"),
- );
-
- helpers::check_http_response(
- request::post(
- "http://localhost:9411/v0/container/batch?autoaccept=True",
- headers.clone(),
- r#"[{"name": "test journal"}, {"name": "another test journal"}]"#,
+ r#"{"editgroup": {},
+ "entity_list": [{"name": "test journal"}, {"name": "another test journal"}]
+ }"#,
&router,
),
status::Created,
diff --git a/rust/tests/test_refs.rs b/rust/tests/test_refs.rs
index 20dafe04..28dfd6b8 100644
--- a/rust/tests/test_refs.rs
+++ b/rust/tests/test_refs.rs
@@ -17,8 +17,7 @@ fn test_refs_blob() {
let conn = server.db_pool.get().expect("db_pool error");
let editor_id = FatcatId::from_str(helpers::TEST_ADMIN_EDITOR_ID).unwrap();
let editgroup_id = helpers::quick_editgroup(&conn);
- let edit_context =
- make_edit_context(&conn, editor_id, Some(editgroup_id), false, None, None).unwrap();
+ let edit_context = make_edit_context(editor_id, editgroup_id, false).unwrap();
// this release entity should be unchanged after being inserted/fetched
let mut r1 = ReleaseEntity::new(ReleaseExtIds::new());
@@ -154,8 +153,7 @@ fn test_refs_blob() {
// update r1 with new target_idents (r3); SHA1 row still shouldn't change
accept_editgroup(&conn, editgroup_id).unwrap();
let editgroup_id = helpers::quick_editgroup(&conn);
- let edit_context =
- make_edit_context(&conn, editor_id, Some(editgroup_id), false, None, None).unwrap();
+ let edit_context = make_edit_context(editor_id, editgroup_id, false).unwrap();
let _edit4 = r3b
.db_update(&conn, &edit_context, edit1.ident_id.into())