diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2019-01-09 13:18:38 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2019-01-09 13:18:38 -0800 |
commit | 17fe81ea8d58f93f129492dc44a38df9ab8d528e (patch) | |
tree | 3d4cb71fb5d2b1c3d15c6cfcf348f09a51b13543 /rust/src/endpoints.rs | |
parent | 0624fce632da17b3f98f0d4ff98a736f05fa287b (diff) | |
download | fatcat-17fe81ea8d58f93f129492dc44a38df9ab8d528e.tar.gz fatcat-17fe81ea8d58f93f129492dc44a38df9ab8d528e.zip |
rust impl required editgroup_id
Diffstat (limited to 'rust/src/endpoints.rs')
-rw-r--r-- | rust/src/endpoints.rs | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/rust/src/endpoints.rs b/rust/src/endpoints.rs index 6e67eadc..ada13654 100644 --- a/rust/src/endpoints.rs +++ b/rust/src/endpoints.rs @@ -88,19 +88,16 @@ macro_rules! wrap_entity_handlers { fn $post_fn( &self, entity: models::$model, - editgroup_id: Option<String>, + editgroup_id: String, context: &Context, ) -> Box<Future<Item = $post_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 auth_context = self.auth_confectionary.require_auth(&conn, &context.auth_data, Some(stringify!($post_fn)))?; auth_context.require_role(FatcatRole::Editor)?; - let editgroup_id = if let Some(s) = editgroup_id { - let eg_id = FatCatId::from_str(&s)?; - auth_context.require_editgroup(&conn, eg_id)?; - Some(eg_id) - } else { None }; - let edit_context = make_edit_context(&conn, auth_context.editor_id, editgroup_id, false)?; + auth_context.require_editgroup(&conn, editgroup_id)?; + let edit_context = make_edit_context(&conn, auth_context.editor_id, Some(editgroup_id), false)?; edit_context.check(&conn)?; entity.db_create(&conn, &edit_context)?.into_model() }) { @@ -190,20 +187,17 @@ macro_rules! wrap_entity_handlers { &self, ident: String, entity: models::$model, - editgroup_id: Option<String>, + editgroup_id: String, context: &Context, ) -> Box<Future<Item = $update_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 auth_context = self.auth_confectionary.require_auth(&conn, &context.auth_data, Some(stringify!($update_fn)))?; auth_context.require_role(FatcatRole::Editor)?; let entity_id = FatCatId::from_str(&ident)?; - let editgroup_id = if let Some(s) = editgroup_id { - let eg_id = FatCatId::from_str(&s)?; - auth_context.require_editgroup(&conn, eg_id)?; - Some(eg_id) - } else { None }; - let edit_context = make_edit_context(&conn, auth_context.editor_id, editgroup_id, false)?; + auth_context.require_editgroup(&conn, editgroup_id)?; + let edit_context = make_edit_context(&conn, auth_context.editor_id, Some(editgroup_id), false)?; edit_context.check(&conn)?; entity.db_update(&conn, &edit_context, entity_id)?.into_model() }) { @@ -246,23 +240,17 @@ macro_rules! wrap_entity_handlers { fn $delete_fn( &self, ident: String, - editgroup_id: Option<String>, + editgroup_id: String, context: &Context, ) -> Box<Future<Item = $delete_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 auth_context = self.auth_confectionary.require_auth(&conn, &context.auth_data, Some(stringify!($delete_fn)))?; auth_context.require_role(FatcatRole::Editor)?; let entity_id = FatCatId::from_str(&ident)?; - let editgroup_id: Option<FatCatId> = match editgroup_id { - Some(s) => { - let editgroup_id = FatCatId::from_str(&s)?; - auth_context.require_editgroup(&conn, editgroup_id)?; - Some(editgroup_id) - }, - None => None, - }; - let edit_context = make_edit_context(&conn, auth_context.editor_id, editgroup_id, false)?; + auth_context.require_editgroup(&conn, editgroup_id)?; + let edit_context = make_edit_context(&conn, auth_context.editor_id, Some(editgroup_id), false)?; edit_context.check(&conn)?; $model::db_delete(&conn, &edit_context, entity_id)?.into_model() }) { |