mirror of
https://github.com/allankoechke/mantisbase-admin.git
synced 2026-12-01 01:15:36 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b17b556fa2 |
@@ -170,7 +170,8 @@ Connected to `GET/PATCH /api/v1/sys/settings/config`:
|
||||
- **General** — organization name, site domain, CORS origins
|
||||
- **File & Sessions** — max upload size (MB in UI, bytes in API), session timeouts
|
||||
- **Features** — registration, email verification, schema mutations, JWT issuer/audience flags
|
||||
- **SMTP** — outbound mail configuration
|
||||
- **SMTP** — outbound mail configuration, plus **Test SMTP** (`POST /api/v1/sys/settings/smtp/test`) using the saved server config
|
||||
- Server version from settings (`mantisVersion`) shown in the Settings header
|
||||
|
||||
Site domain is used for OAuth callback URL hints in the configure drawer.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { RefreshCw, Save } from "lucide-react"
|
||||
import { Mail, RefreshCw, Save } from "lucide-react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Input } from "@/components/ui/input"
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
type SmtpConfig,
|
||||
} from "@/lib/api"
|
||||
import { useToast } from "@/hooks/use-toast"
|
||||
import { SmtpTestDialog } from "./smtp-test-dialog"
|
||||
|
||||
interface SettingsSectionProps {
|
||||
apiClient: ApiClient
|
||||
@@ -52,6 +53,7 @@ export function SettingsSection({ apiClient }: SettingsSectionProps) {
|
||||
const [isLoading, setIsLoading] = React.useState<Record<string, boolean>>({})
|
||||
const [isRefreshing, setIsRefreshing] = React.useState(false)
|
||||
const [isBootstrapping, setIsBootstrapping] = React.useState(true)
|
||||
const [smtpTestOpen, setSmtpTestOpen] = React.useState(false)
|
||||
|
||||
const applySettings = React.useCallback((settings: AppSettings) => {
|
||||
const normalized: AppSettings = {
|
||||
@@ -290,7 +292,15 @@ export function SettingsSection({ apiClient }: SettingsSectionProps) {
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-1">
|
||||
<h1 className="text-3xl font-bold tracking-tight">Settings</h1>
|
||||
<p className="text-muted-foreground">Manage your application configuration and preferences</p>
|
||||
<p className="text-muted-foreground">
|
||||
Manage your application configuration and preferences
|
||||
{formData.mantisVersion ? (
|
||||
<>
|
||||
{" "}
|
||||
· Server <span className="font-mono text-foreground">{formData.mantisVersion}</span>
|
||||
</>
|
||||
) : null}
|
||||
</p>
|
||||
</div>
|
||||
<Button variant="outline" size="icon" onClick={handleRefresh} disabled={isRefreshing}>
|
||||
<RefreshCw className={`h-4 w-4 ${isRefreshing ? "animate-spin" : ""}`} />
|
||||
@@ -481,12 +491,24 @@ export function SettingsSection({ apiClient }: SettingsSectionProps) {
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<div>
|
||||
<CardTitle>SMTP</CardTitle>
|
||||
<CardDescription>Outbound email delivery configuration</CardDescription>
|
||||
</div>
|
||||
{renderSaveButton("smtp")}
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setSmtpTestOpen(true)}
|
||||
className="gap-2"
|
||||
>
|
||||
<Mail className="h-4 w-4" />
|
||||
Test SMTP
|
||||
</Button>
|
||||
{renderSaveButton("smtp")}
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
@@ -551,9 +573,15 @@ export function SettingsSection({ apiClient }: SettingsSectionProps) {
|
||||
onCheckedChange={(checked) => handleSmtpChange("tls", checked)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Test SMTP uses the configuration already saved on the server. Save any changes before testing.
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<SmtpTestDialog open={smtpTestOpen} apiClient={apiClient} onClose={() => setSmtpTestOpen(false)} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
133
components/settings/smtp-test-dialog.tsx
Normal file
133
components/settings/smtp-test-dialog.tsx
Normal file
@@ -0,0 +1,133 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Mail } from "lucide-react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog"
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert"
|
||||
import {
|
||||
SYS_SETTINGS_SMTP_TEST_API,
|
||||
getApiClientError,
|
||||
type ApiClient,
|
||||
type SmtpTestResult,
|
||||
} from "@/lib/api"
|
||||
import { useToast } from "@/hooks/use-toast"
|
||||
|
||||
interface SmtpTestDialogProps {
|
||||
open: boolean
|
||||
apiClient: ApiClient
|
||||
onClose: () => void
|
||||
}
|
||||
|
||||
function isValidEmail(value: string): boolean {
|
||||
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)
|
||||
}
|
||||
|
||||
export function SmtpTestDialog({ open, apiClient, onClose }: SmtpTestDialogProps) {
|
||||
const { toast } = useToast()
|
||||
const [email, setEmail] = React.useState("")
|
||||
const [isLoading, setIsLoading] = React.useState(false)
|
||||
const [error, setError] = React.useState("")
|
||||
|
||||
React.useEffect(() => {
|
||||
if (open) {
|
||||
setEmail("")
|
||||
setError("")
|
||||
}
|
||||
}, [open])
|
||||
|
||||
const handleSubmit = async (event: React.FormEvent) => {
|
||||
event.preventDefault()
|
||||
|
||||
const trimmed = email.trim()
|
||||
if (!trimmed || !isValidEmail(trimmed)) {
|
||||
setError("Enter a valid email address")
|
||||
return
|
||||
}
|
||||
|
||||
setIsLoading(true)
|
||||
setError("")
|
||||
|
||||
try {
|
||||
const result = await apiClient.call<SmtpTestResult>(SYS_SETTINGS_SMTP_TEST_API, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ email: trimmed }),
|
||||
})
|
||||
|
||||
const apiError = getApiClientError(result)
|
||||
if (apiError) {
|
||||
throw new Error(apiError)
|
||||
}
|
||||
|
||||
toast({
|
||||
title: "Test Email Sent",
|
||||
description: result?.message || `A test message was sent to ${trimmed}.`,
|
||||
duration: 5000,
|
||||
})
|
||||
onClose()
|
||||
} catch (submitError) {
|
||||
console.error("Failed to send SMTP test email:", submitError)
|
||||
setError(submitError instanceof Error ? submitError.message : "Failed to send test email")
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={(nextOpen) => !nextOpen && onClose()}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<Mail className="h-5 w-5" />
|
||||
Send Test Email
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
Sends a message using the SMTP settings already saved on the server. Unsaved form changes are not used.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
{error && (
|
||||
<Alert variant="destructive">
|
||||
<AlertDescription>{error}</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="smtp-test-email">Recipient email</Label>
|
||||
<Input
|
||||
id="smtp-test-email"
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(event) => setEmail(event.target.value)}
|
||||
placeholder="you@example.com"
|
||||
required
|
||||
autoFocus
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Limited to 3 test messages per recipient per hour.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={onClose} disabled={isLoading}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" disabled={isLoading}>
|
||||
{isLoading ? "Sending..." : "Send Test Email"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
15
lib/api.ts
15
lib/api.ts
@@ -71,6 +71,9 @@ export const SYS_ADMINS_API = "/api/v1/sys/admins" as const
|
||||
/** Application settings (GET/PATCH). */
|
||||
export const SYS_SETTINGS_CONFIG_API = "/api/v1/sys/settings/config" as const
|
||||
|
||||
/** Send a test email using the saved SMTP configuration. */
|
||||
export const SYS_SETTINGS_SMTP_TEST_API = "/api/v1/sys/settings/smtp/test" as const
|
||||
|
||||
/** Admin API keys (list, create, update, revoke). */
|
||||
export const SYS_API_KEYS_API = "/api/v1/sys/api-keys" as const
|
||||
|
||||
@@ -258,6 +261,18 @@ export interface AppSettings {
|
||||
jwtEnableSetIssuer: boolean
|
||||
jwtEnableSetAudience: boolean
|
||||
smtp: SmtpConfig
|
||||
/** Running MantisBase server version (read-only from GET settings). */
|
||||
mantisVersion?: string
|
||||
}
|
||||
|
||||
export interface SmtpTestRequest {
|
||||
email: string
|
||||
}
|
||||
|
||||
export interface SmtpTestResult {
|
||||
to: string
|
||||
subject: string
|
||||
message: string
|
||||
}
|
||||
|
||||
// API Response interface
|
||||
|
||||
61
openapi.yaml
61
openapi.yaml
@@ -1239,6 +1239,67 @@ paths:
|
||||
schema:
|
||||
$ref: "#/components/schemas/ApiEnvelope"
|
||||
|
||||
/sys/settings/smtp/test:
|
||||
post:
|
||||
tags: [System]
|
||||
summary: Send SMTP test message
|
||||
description: |
|
||||
Sends a test email using the SMTP settings already stored on the server.
|
||||
Does not modify settings. Not blocked by `MB_DISABLE_CONFIG_MUTATIONS`.
|
||||
Rate-limited to 3 messages per recipient per hour.
|
||||
security:
|
||||
- bearerAuth: []
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [email]
|
||||
properties:
|
||||
email:
|
||||
type: string
|
||||
format: email
|
||||
example: you@example.com
|
||||
responses:
|
||||
"200":
|
||||
description: Test email sent
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/ApiEnvelope"
|
||||
- type: object
|
||||
properties:
|
||||
data:
|
||||
type: object
|
||||
properties:
|
||||
to:
|
||||
type: string
|
||||
format: email
|
||||
subject:
|
||||
type: string
|
||||
example: "MantisBase: Hey, it works!"
|
||||
message:
|
||||
type: string
|
||||
example: If you are seeing this, the SMTP Settings are OK!
|
||||
"400":
|
||||
description: Invalid email or SMTP not configured (host and from required)
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/ApiEnvelope"
|
||||
"401":
|
||||
$ref: "#/components/responses/Unauthorized"
|
||||
"429":
|
||||
$ref: "#/components/responses/TooManyRequests"
|
||||
"502":
|
||||
description: SMTP server rejected the message or could not be reached
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/ApiEnvelope"
|
||||
|
||||
/sys/api-keys:
|
||||
get:
|
||||
tags: [System]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "mantisbase-admin",
|
||||
"version": "0.4.0",
|
||||
"version": "0.4.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"export": "next build && next export",
|
||||
|
||||
Reference in New Issue
Block a user