From 468752f69194b8a4ab6213ff5f5421afc76834ad Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Fri, 30 Jun 2023 16:49:35 +0530 Subject: [PATCH] feat: advance siteey create now allows setting publication status --- src/api/v1/mcaptcha/create.rs | 6 ++++++ src/api/v1/mcaptcha/test.rs | 1 + src/api/v1/pow/get_config.rs | 1 + src/tests/mod.rs | 1 + templates/panel/sitekey/add/advance/form.html | 11 +++++++++++ templates/panel/sitekey/add/advance/ts/form/index.ts | 8 ++++++++ 6 files changed, 28 insertions(+) diff --git a/src/api/v1/mcaptcha/create.rs b/src/api/v1/mcaptcha/create.rs index 2e882500..743fb831 100644 --- a/src/api/v1/mcaptcha/create.rs +++ b/src/api/v1/mcaptcha/create.rs @@ -31,6 +31,7 @@ pub struct CreateCaptcha { pub levels: Vec, pub duration: u32, pub description: String, + pub publish_benchmarks: bool, } #[derive(Clone, Debug, Deserialize, Serialize)] @@ -52,6 +53,11 @@ pub async fn create( ) -> ServiceResult { let username = id.identity().unwrap(); let mcaptcha_config = runner::create(&payload, &data, &username).await?; + if payload.publish_benchmarks { + data.db + .analytics_create_psuedo_id_if_not_exists(&mcaptcha_config.key) + .await?; + } Ok(HttpResponse::Ok().json(mcaptcha_config)) } diff --git a/src/api/v1/mcaptcha/test.rs b/src/api/v1/mcaptcha/test.rs index 9019a042..2b1d43ff 100644 --- a/src/api/v1/mcaptcha/test.rs +++ b/src/api/v1/mcaptcha/test.rs @@ -82,6 +82,7 @@ pub async fn level_routes_work(data: ArcData) { levels: levels.clone(), description: add_level.description, duration: add_level.duration, + publish_benchmarks: true, }; let add_token_resp = test::call_service( diff --git a/src/api/v1/pow/get_config.rs b/src/api/v1/pow/get_config.rs index 13c381d5..063003de 100644 --- a/src/api/v1/pow/get_config.rs +++ b/src/api/v1/pow/get_config.rs @@ -250,6 +250,7 @@ pub mod tests { levels: levels.into(), duration: 30, description: "dummy".into(), + publish_benchmarks: true, }; // 1. add level diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 9de70cf9..b51a7f59 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -262,5 +262,6 @@ pub fn get_level_data() -> CreateCaptcha { levels, duration: 30, description: "dummy".into(), + publish_benchmarks: false, } } diff --git a/templates/panel/sitekey/add/advance/form.html b/templates/panel/sitekey/add/advance/form.html index 69f18085..060867ff 100644 --- a/templates/panel/sitekey/add/advance/form.html +++ b/templates/panel/sitekey/add/advance/form.html @@ -45,5 +45,16 @@ <. } .> <. } .> + + + diff --git a/templates/panel/sitekey/add/advance/ts/form/index.ts b/templates/panel/sitekey/add/advance/ts/form/index.ts index 2140e421..0bb34c49 100644 --- a/templates/panel/sitekey/add/advance/ts/form/index.ts +++ b/templates/panel/sitekey/add/advance/ts/form/index.ts @@ -38,6 +38,13 @@ export const addSubmitEventListener = (): void => const submit = async (e: Event) => { e.preventDefault(); + + const PUBLISH_BENCHMARKS = ( + FORM.querySelector("#publish_benchmarks") + ); + + + const description = validateDescription(e); const duration = validateDuration(); @@ -50,6 +57,7 @@ const submit = async (e: Event) => { levels: levels, duration, description, + publish_benchmarks: PUBLISH_BENCHMARKS.checked, }; console.debug(`[form submition] json payload: ${JSON.stringify(payload)}`);