feat: Add maxAliasesPerUser to SettingsForm.tsx

This commit is contained in:
Myzel394 2023-02-20 15:49:52 +01:00
parent 2ab9665afd
commit 438ec51e17
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
3 changed files with 66 additions and 20 deletions

View File

@ -395,6 +395,10 @@
"allowAliasDeletion": { "allowAliasDeletion": {
"label": "Allow alias deletion", "label": "Allow alias deletion",
"description": "If enabled, users will be able to delete their aliases." "description": "If enabled, users will be able to delete their aliases."
},
"maxAliasesPerUser": {
"label": "Maximum aliases per user",
"description": "The maximum number of aliases a user can create. 0 means unlimited. Existing aliases will not be affected."
} }
} }
}, },

View File

@ -6,6 +6,9 @@ import {MdCheck, MdClear, MdOutlineChangeCircle, MdTextFormat} from "react-icons
import {BsImage} from "react-icons/bs" import {BsImage} from "react-icons/bs"
import {AxiosError} from "axios" import {AxiosError} from "axios"
import {FaMask} from "react-icons/fa"
import AliasesPercentageAmount from "./AliasPercentageAmount"
import { import {
Checkbox, Checkbox,
FormControlLabel, FormControlLabel,
@ -28,8 +31,6 @@ import {parseFastAPIError} from "~/utils"
import {DEFAULT_ADMIN_SETTINGS} from "~/constants/admin-settings" import {DEFAULT_ADMIN_SETTINGS} from "~/constants/admin-settings"
import RandomAliasGenerator from "~/route-widgets/GlobalSettingsRoute/RandomAliasGenerator" import RandomAliasGenerator from "~/route-widgets/GlobalSettingsRoute/RandomAliasGenerator"
import AliasesPercentageAmount from "./AliasPercentageAmount"
export interface SettingsFormProps { export interface SettingsFormProps {
settings: AdminSettings settings: AdminSettings
queryKey: readonly string[] queryKey: readonly string[]
@ -84,7 +85,14 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) {
allowStatistics: yup allowStatistics: yup
.boolean() .boolean()
.label(t("routes.AdminRoute.forms.settings.allowStatistics.label")), .label(t("routes.AdminRoute.forms.settings.allowStatistics.label")),
}) allowAliasDeletion: yup
.boolean()
.label(t("routes.AdminRoute.forms.settings.allowAliasDeletion.label")),
maxAliasesPerUser: yup
.number()
.label(t("routes.AdminRoute.forms.settings.maxAliasesPerUser.label"))
.min(0),
} as Record<keyof AdminSettings, any>)
const {mutateAsync} = useMutation< const {mutateAsync} = useMutation<
UpdateAdminSettingsResponse, UpdateAdminSettingsResponse,
@ -144,7 +152,40 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) {
</Grid> </Grid>
<Grid item> <Grid item>
<Grid container spacing={3} direction="row" alignItems="start"> <Grid container spacing={3} direction="row" alignItems="start">
<Grid item md={6}> <Grid item xs={12}>
<TextField
key="max_aliases_per_user"
fullWidth
label={t(
"routes.AdminRoute.forms.settings.maxAliasesPerUser.label",
)}
name="maxAliasesPerUser"
value={formik.values.maxAliasesPerUser}
onChange={formik.handleChange}
error={
formik.touched.maxAliasesPerUser &&
Boolean(formik.errors.maxAliasesPerUser)
}
helperText={
(formik.touched.maxAliasesPerUser &&
formik.errors.maxAliasesPerUser) ||
t(
"routes.AdminRoute.forms.settings.maxAliasesPerUser.description",
)
}
type="number"
disabled={formik.isSubmitting}
inputMode="numeric"
InputProps={{
startAdornment: (
<InputAdornment position="start">
<FaMask />
</InputAdornment>
),
}}
/>
</Grid>
<Grid item xs={12} md={6}>
<TextField <TextField
key="random_email_id_min_length" key="random_email_id_min_length"
fullWidth fullWidth
@ -177,7 +218,7 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) {
}} }}
/> />
</Grid> </Grid>
<Grid item md={6}> <Grid item xs={12} md={6}>
<StringPoolField <StringPoolField
fullWidth fullWidth
allowCustom allowCustom
@ -209,13 +250,13 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) {
} }
/> />
</Grid> </Grid>
<Grid item marginX="auto"> <Grid item xs={12} marginX="auto">
<RandomAliasGenerator <RandomAliasGenerator
characters={formik.values.randomEmailIdChars!} characters={formik.values.randomEmailIdChars!}
length={formik.values.randomEmailIdMinLength!} length={formik.values.randomEmailIdMinLength!}
/> />
</Grid> </Grid>
<Grid item> <Grid item xs={12}>
<TextField <TextField
key="random_email_length_increase_on_percentage" key="random_email_length_increase_on_percentage"
fullWidth fullWidth
@ -248,14 +289,14 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) {
}} }}
/> />
</Grid> </Grid>
<Grid item> <Grid item xs={12}>
<AliasesPercentageAmount <AliasesPercentageAmount
percentage={formik.values.randomEmailLengthIncreaseOnPercentage!} percentage={formik.values.randomEmailLengthIncreaseOnPercentage!}
length={formik.values.randomEmailIdMinLength!} length={formik.values.randomEmailIdMinLength!}
characters={formik.values.randomEmailIdChars!} characters={formik.values.randomEmailIdChars!}
/> />
</Grid> </Grid>
<Grid item md={6}> <Grid item xs={12} md={6}>
<TextField <TextField
key="custom_email_suffix_length" key="custom_email_suffix_length"
fullWidth fullWidth
@ -288,7 +329,7 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) {
}} }}
/> />
</Grid> </Grid>
<Grid item md={6}> <Grid item xs={12} md={6}>
<StringPoolField <StringPoolField
key="custom_email_suffix_chars" key="custom_email_suffix_chars"
allowCustom allowCustom
@ -320,7 +361,7 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) {
} }
/> />
</Grid> </Grid>
<Grid item> <Grid item xs={12}>
<TextField <TextField
key="image_proxy_storage_life_time_in_hours" key="image_proxy_storage_life_time_in_hours"
fullWidth fullWidth
@ -365,7 +406,7 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) {
}} }}
/> />
</Grid> </Grid>
<Grid item> <Grid item xs={12}>
<FormGroup key="user_email_enable_disposable_emails"> <FormGroup key="user_email_enable_disposable_emails">
<FormControlLabel <FormControlLabel
control={ control={
@ -394,12 +435,12 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) {
</FormHelperText> </FormHelperText>
</FormGroup> </FormGroup>
</Grid> </Grid>
<Grid item> <Grid item xs={12}>
<FormGroup key="user_email_enable_other_relays"> <FormGroup key="user_email_enable_other_relays">
<FormControlLabel <FormControlLabel
control={ control={
<Checkbox <Checkbox
checked={formik.values.userEmailEnableOtherRelays!} checked={formik.values.userEmailEnableOtherRelays}
onChange={formik.handleChange} onChange={formik.handleChange}
name="userEmailEnableOtherRelays" name="userEmailEnableOtherRelays"
/> />
@ -423,12 +464,12 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) {
</FormHelperText> </FormHelperText>
</FormGroup> </FormGroup>
</Grid> </Grid>
<Grid item> <Grid item xs={12}>
<FormGroup key="enable_image_proxy"> <FormGroup key="enable_image_proxy">
<FormControlLabel <FormControlLabel
control={ control={
<Checkbox <Checkbox
checked={formik.values.enableImageProxy!} checked={formik.values.enableImageProxy}
onChange={formik.handleChange} onChange={formik.handleChange}
name="enableImageProxy" name="enableImageProxy"
/> />
@ -452,12 +493,12 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) {
</FormHelperText> </FormHelperText>
</FormGroup> </FormGroup>
</Grid> </Grid>
<Grid item> <Grid item xs={12}>
<FormGroup key="allow_statistics"> <FormGroup key="allow_statistics">
<FormControlLabel <FormControlLabel
control={ control={
<Checkbox <Checkbox
checked={formik.values.allowStatistics!} checked={formik.values.allowStatistics}
onChange={formik.handleChange} onChange={formik.handleChange}
name="allowStatistics" name="allowStatistics"
/> />
@ -481,12 +522,12 @@ export default function SettingsForm({settings, queryKey}: SettingsFormProps) {
</FormHelperText> </FormHelperText>
</FormGroup> </FormGroup>
</Grid> </Grid>
<Grid item> <Grid item xs={12}>
<FormGroup key="allow_alias_deletion"> <FormGroup key="allow_alias_deletion">
<FormControlLabel <FormControlLabel
control={ control={
<Checkbox <Checkbox
checked={formik.values.allowAliasDeletion!} checked={formik.values.allowAliasDeletion}
onChange={formik.handleChange} onChange={formik.handleChange}
name="allowAliasDeletion" name="allowAliasDeletion"
/> />

View File

@ -212,6 +212,7 @@ export interface AdminSettings {
userEmailEnableOtherRelays: boolean userEmailEnableOtherRelays: boolean
allowStatistics: boolean allowStatistics: boolean
allowAliasDeletion: boolean allowAliasDeletion: boolean
maxAliasesPerUser: number
} }
export interface ServerCronReport { export interface ServerCronReport {