summaryrefslogtreecommitdiffstats
path: root/rust/src
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/api_helpers.rs17
-rw-r--r--rust/src/api_server.rs1
-rw-r--r--rust/src/api_wrappers.rs5
3 files changed, 22 insertions, 1 deletions
diff --git a/rust/src/api_helpers.rs b/rust/src/api_helpers.rs
index 77377531..b6525546 100644
--- a/rust/src/api_helpers.rs
+++ b/rust/src/api_helpers.rs
@@ -21,6 +21,22 @@ pub struct EditContext {
pub autoaccept: bool,
}
+impl EditContext {
+
+ /// This function should always be run within a transaction
+ pub fn check(&self, conn: &DbConn) -> Result<()> {
+ let count: i64 = changelog::table
+ .filter(changelog::editgroup_id.eq(&self.editgroup_id.to_uuid()))
+ .count()
+ .get_result(conn)?;
+ if count > 0 {
+ return Err(ErrorKind::EditgroupAlreadyAccepted(self.editgroup_id.to_string()).into());
+ }
+ return Ok(());
+ }
+}
+
+
#[derive(Clone, Copy, PartialEq)]
pub struct ExpandFlags {
pub files: bool,
@@ -202,6 +218,7 @@ pub fn get_or_create_editgroup(editor_id: Uuid, conn: &DbConn) -> Result<Uuid> {
pub fn accept_editgroup(editgroup_id: FatCatId, conn: &DbConn) -> Result<ChangelogRow> {
// check that we haven't accepted already (in changelog)
// NB: could leave this to a UNIQUE constraint
+ // TODO: redundant with check_edit_context
let count: i64 = changelog::table
.filter(changelog::editgroup_id.eq(editgroup_id.to_uuid()))
.count()
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index 0961194b..d03fce07 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -24,6 +24,7 @@ macro_rules! entity_batch_handler {
) -> Result<Vec<EntityEdit>> {
let edit_context = make_edit_context(conn, editgroup_id, autoaccept)?;
+ 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())?;
diff --git a/rust/src/api_wrappers.rs b/rust/src/api_wrappers.rs
index aa7f9ec3..fe9cd793 100644
--- a/rust/src/api_wrappers.rs
+++ b/rust/src/api_wrappers.rs
@@ -36,7 +36,7 @@ macro_rules! wrap_entity_handlers {
_context: &Context,
) -> Box<Future<Item = $get_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
- // No transaction for GET?
+ // No transaction for GET
let ret = match (|| {
let entity_id = FatCatId::from_str(&id)?;
let hide_flags = match hide {
@@ -88,6 +88,7 @@ macro_rules! wrap_entity_handlers {
Some(FatCatId::from_str(&s)?)
} else { None };
let edit_context = make_edit_context(&conn, editgroup_id, false)?;
+ edit_context.check(&conn)?;
entity.db_create(&conn, &edit_context)?.into_model()
}) {
Ok(edit) =>
@@ -168,6 +169,7 @@ macro_rules! wrap_entity_handlers {
Some(FatCatId::from_str(&s)?)
} else { None };
let edit_context = make_edit_context(&conn, editgroup_id, false)?;
+ edit_context.check(&conn)?;
entity.db_update(&conn, &edit_context, entity_id)?.into_model()
}) {
Ok(edit) =>
@@ -213,6 +215,7 @@ macro_rules! wrap_entity_handlers {
None => None,
};
let edit_context = make_edit_context(&conn, editgroup_id, false)?;
+ edit_context.check(&conn)?;
$model::db_delete(&conn, &edit_context, entity_id)?.into_model()
}) {
Ok(edit) =>