feat: advance siteey create now allows setting publication status

This commit is contained in:
Aravinth Manivannan
2023-06-30 16:49:35 +05:30
parent 22edb04ce2
commit 468752f691
6 changed files with 28 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ pub struct CreateCaptcha {
pub levels: Vec<Level>, pub levels: Vec<Level>,
pub duration: u32, pub duration: u32,
pub description: String, pub description: String,
pub publish_benchmarks: bool,
} }
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
@@ -52,6 +53,11 @@ pub async fn create(
) -> ServiceResult<impl Responder> { ) -> ServiceResult<impl Responder> {
let username = id.identity().unwrap(); let username = id.identity().unwrap();
let mcaptcha_config = runner::create(&payload, &data, &username).await?; 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)) Ok(HttpResponse::Ok().json(mcaptcha_config))
} }

View File

@@ -82,6 +82,7 @@ pub async fn level_routes_work(data: ArcData) {
levels: levels.clone(), levels: levels.clone(),
description: add_level.description, description: add_level.description,
duration: add_level.duration, duration: add_level.duration,
publish_benchmarks: true,
}; };
let add_token_resp = test::call_service( let add_token_resp = test::call_service(

View File

@@ -250,6 +250,7 @@ pub mod tests {
levels: levels.into(), levels: levels.into(),
duration: 30, duration: 30,
description: "dummy".into(), description: "dummy".into(),
publish_benchmarks: true,
}; };
// 1. add level // 1. add level

View File

@@ -262,5 +262,6 @@ pub fn get_level_data() -> CreateCaptcha {
levels, levels,
duration: 30, duration: 30,
description: "dummy".into(), description: "dummy".into(),
publish_benchmarks: false,
} }
} }

View File

@@ -45,5 +45,16 @@
<. } .> <. } .>
<. } .> <. } .>
<label class="sitekey-form__label" for="publish_benchmarks">
Anonymously publish CAPTCHA performance statistics to help other webmasters
<input
class="sitekey-form__input"
type="checkbox"
name="publish_benchmarks"
id="publish_benchmarks"
/>
</label>
<button class="sitekey-form__submit" type="submit">Submit</button> <button class="sitekey-form__submit" type="submit">Submit</button>
</form> </form>

View File

@@ -38,6 +38,13 @@ export const addSubmitEventListener = (): void =>
const submit = async (e: Event) => { const submit = async (e: Event) => {
e.preventDefault(); e.preventDefault();
const PUBLISH_BENCHMARKS = <HTMLInputElement>(
FORM.querySelector("#publish_benchmarks")
);
const description = validateDescription(e); const description = validateDescription(e);
const duration = validateDuration(); const duration = validateDuration();
@@ -50,6 +57,7 @@ const submit = async (e: Event) => {
levels: levels, levels: levels,
duration, duration,
description, description,
publish_benchmarks: PUBLISH_BENCHMARKS.checked,
}; };
console.debug(`[form submition] json payload: ${JSON.stringify(payload)}`); console.debug(`[form submition] json payload: ${JSON.stringify(payload)}`);