Can configure maximum inactivity of token
This commit is contained in:
parent
89b9f7c292
commit
ec25b6e4f1
@ -159,7 +159,7 @@ pub struct NewToken {
|
||||
pub description: String,
|
||||
pub rights: TokenRights,
|
||||
pub ip_restriction: Option<ipnetwork::IpNetwork>,
|
||||
pub delete_after_inactivity: Option<u64>,
|
||||
pub max_inactivity: Option<u64>,
|
||||
}
|
||||
|
||||
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()?;
|
||||
|
@ -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 {
|
||||
</EditSection>
|
||||
|
||||
<EditSection title="General settings">
|
||||
{(p.status === TokenWidgetStatus.Create || p.token.ip_restriction) && (
|
||||
{p.status === TokenWidgetStatus.Create && (
|
||||
<RadioGroupInput
|
||||
{...p}
|
||||
editable={p.status === TokenWidgetStatus.Create}
|
||||
@ -161,6 +161,7 @@ function NetworkDetailsTabGeneral(p: DetailsInnerProps): React.ReactElement {
|
||||
onValueChange={(v) => {
|
||||
setIpVersion(Number(v) as any);
|
||||
}}
|
||||
label="Token IP restriction version"
|
||||
/>
|
||||
)}
|
||||
<IPInputWithMask
|
||||
@ -175,7 +176,21 @@ function NetworkDetailsTabGeneral(p: DetailsInnerProps): React.ReactElement {
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* TODO : remaining */}
|
||||
<TextInput
|
||||
editable={p.status === TokenWidgetStatus.Create}
|
||||
label="Max inactivity of tokens (days)"
|
||||
type="number"
|
||||
value={
|
||||
p.token.max_inactivity
|
||||
? Math.floor(p.token.max_inactivity / SECS_PER_DAY).toString()
|
||||
: ""
|
||||
}
|
||||
onValueChange={(v) => {
|
||||
const secs = Number(v ?? "0") * SECS_PER_DAY;
|
||||
p.token.max_inactivity = secs === 0 ? undefined : secs;
|
||||
p.onChange?.();
|
||||
}}
|
||||
/>
|
||||
</EditSection>
|
||||
</Grid>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user