diff --git a/virtweb_backend/src/api_tokens.rs b/virtweb_backend/src/api_tokens.rs index 0e30eee..5cfa856 100644 --- a/virtweb_backend/src/api_tokens.rs +++ b/virtweb_backend/src/api_tokens.rs @@ -159,7 +159,7 @@ pub struct NewToken { pub description: String, pub rights: TokenRights, pub ip_restriction: Option, - pub delete_after_inactivity: Option, + pub max_inactivity: Option, } impl NewToken { @@ -185,7 +185,7 @@ impl NewToken { return Some(err); } - if let Some(t) = self.delete_after_inactivity { + if let Some(t) = self.max_inactivity { if t < 3600 { return Some("API tokens shall be valid for at least 1 hour!"); } @@ -209,7 +209,7 @@ pub async fn create(t: &NewToken) -> anyhow::Result<(Token, TokenPrivKey)> { rights: t.rights.clone(), last_used: time(), ip_restriction: t.ip_restriction, - max_inactivity: t.delete_after_inactivity, + max_inactivity: t.max_inactivity, }; token.save()?; diff --git a/virtweb_frontend/src/widgets/tokens/APITokenDetails.tsx b/virtweb_frontend/src/widgets/tokens/APITokenDetails.tsx index 776c969..c725219 100644 --- a/virtweb_frontend/src/widgets/tokens/APITokenDetails.tsx +++ b/virtweb_frontend/src/widgets/tokens/APITokenDetails.tsx @@ -12,11 +12,11 @@ import { useSnackbar } from "../../hooks/providers/SnackbarProvider"; import { AsyncWidget } from "../AsyncWidget"; import { TabsWidget } from "../TabsWidget"; import { EditSection } from "../forms/EditSection"; -import { IPInput, IPInputWithMask } from "../forms/IPInput"; -import { ResAutostartInput } from "../forms/ResAutostartInput"; -import { SelectInput } from "../forms/SelectInput"; -import { TextInput } from "../forms/TextInput"; +import { IPInputWithMask } from "../forms/IPInput"; import { RadioGroupInput } from "../forms/RadioGroupInput"; +import { TextInput } from "../forms/TextInput"; + +const SECS_PER_DAY = 3600 * 24; export enum TokenWidgetStatus { Create, @@ -149,7 +149,7 @@ function NetworkDetailsTabGeneral(p: DetailsInnerProps): React.ReactElement { - {(p.status === TokenWidgetStatus.Create || p.token.ip_restriction) && ( + {p.status === TokenWidgetStatus.Create && ( { setIpVersion(Number(v) as any); }} + label="Token IP restriction version" /> )} - {/* TODO : remaining */} + { + const secs = Number(v ?? "0") * SECS_PER_DAY; + p.token.max_inactivity = secs === 0 ? undefined : secs; + p.onChange?.(); + }} + /> );