Build 2602260214: invites profiles and expiry admin controls
This commit is contained in:
@@ -14,9 +14,18 @@ type AdminUser = {
|
||||
lastLoginAt?: string | null
|
||||
isBlocked?: boolean
|
||||
autoSearchEnabled?: boolean
|
||||
profileId?: number | null
|
||||
expiresAt?: string | null
|
||||
isExpired?: boolean
|
||||
stats?: UserStats
|
||||
}
|
||||
|
||||
type UserProfileOption = {
|
||||
id: number
|
||||
name: string
|
||||
isActive?: boolean
|
||||
}
|
||||
|
||||
type UserStats = {
|
||||
total: number
|
||||
ready: number
|
||||
@@ -43,6 +52,13 @@ const formatLastRequest = (value?: string | null) => {
|
||||
return date.toLocaleString()
|
||||
}
|
||||
|
||||
const formatExpiry = (value?: string | null) => {
|
||||
if (!value) return 'Never'
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.valueOf())) return value
|
||||
return date.toLocaleString()
|
||||
}
|
||||
|
||||
const emptyStats: UserStats = {
|
||||
total: 0,
|
||||
ready: 0,
|
||||
@@ -76,6 +92,35 @@ export default function UsersPage() {
|
||||
const [jellyseerrSyncBusy, setJellyseerrSyncBusy] = useState(false)
|
||||
const [jellyseerrResyncBusy, setJellyseerrResyncBusy] = useState(false)
|
||||
const [bulkAutoSearchBusy, setBulkAutoSearchBusy] = useState(false)
|
||||
const [profiles, setProfiles] = useState<UserProfileOption[]>([])
|
||||
const [bulkProfileId, setBulkProfileId] = useState('')
|
||||
const [bulkProfileBusy, setBulkProfileBusy] = useState(false)
|
||||
const [bulkExpiryDays, setBulkExpiryDays] = useState('')
|
||||
const [bulkExpiryBusy, setBulkExpiryBusy] = useState(false)
|
||||
|
||||
const loadProfiles = async () => {
|
||||
try {
|
||||
const baseUrl = getApiBase()
|
||||
const response = await authFetch(`${baseUrl}/admin/profiles`)
|
||||
if (!response.ok) {
|
||||
return
|
||||
}
|
||||
const data = await response.json()
|
||||
if (!Array.isArray(data?.profiles)) {
|
||||
setProfiles([])
|
||||
return
|
||||
}
|
||||
setProfiles(
|
||||
data.profiles.map((profile: any) => ({
|
||||
id: Number(profile.id ?? 0),
|
||||
name: String(profile.name ?? 'Unnamed profile'),
|
||||
isActive: Boolean(profile.is_active ?? true),
|
||||
}))
|
||||
)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
const loadUsers = async () => {
|
||||
try {
|
||||
@@ -103,6 +148,12 @@ export default function UsersPage() {
|
||||
lastLoginAt: user.last_login_at ?? null,
|
||||
isBlocked: Boolean(user.is_blocked),
|
||||
autoSearchEnabled: Boolean(user.auto_search_enabled ?? true),
|
||||
profileId:
|
||||
user.profile_id == null || Number.isNaN(Number(user.profile_id))
|
||||
? null
|
||||
: Number(user.profile_id),
|
||||
expiresAt: user.expires_at ?? null,
|
||||
isExpired: Boolean(user.is_expired),
|
||||
id: Number(user.id ?? 0),
|
||||
stats: normalizeStats(user.stats ?? emptyStats),
|
||||
}))
|
||||
@@ -238,12 +289,110 @@ export default function UsersPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const bulkApplyProfile = async () => {
|
||||
setBulkProfileBusy(true)
|
||||
setJellyseerrSyncStatus(null)
|
||||
setError(null)
|
||||
try {
|
||||
const baseUrl = getApiBase()
|
||||
const response = await authFetch(`${baseUrl}/admin/users/profile/bulk`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
profile_id: bulkProfileId || null,
|
||||
scope: 'non-admin-users',
|
||||
}),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const text = await response.text()
|
||||
throw new Error(text || 'Bulk profile update failed')
|
||||
}
|
||||
const data = await response.json()
|
||||
setJellyseerrSyncStatus(
|
||||
bulkProfileId
|
||||
? `Applied profile ${bulkProfileId} to ${data?.updated ?? 0} non-admin users.`
|
||||
: `Cleared profile assignment for ${data?.updated ?? 0} non-admin users.`
|
||||
)
|
||||
await loadUsers()
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
setError('Could not apply profile to all users.')
|
||||
} finally {
|
||||
setBulkProfileBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
const bulkSetExpiryDays = async () => {
|
||||
if (!bulkExpiryDays.trim()) {
|
||||
setError('Enter expiry days before applying bulk expiry.')
|
||||
return
|
||||
}
|
||||
setBulkExpiryBusy(true)
|
||||
setJellyseerrSyncStatus(null)
|
||||
setError(null)
|
||||
try {
|
||||
const baseUrl = getApiBase()
|
||||
const response = await authFetch(`${baseUrl}/admin/users/expiry/bulk`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
days: bulkExpiryDays,
|
||||
scope: 'non-admin-users',
|
||||
}),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const text = await response.text()
|
||||
throw new Error(text || 'Bulk expiry update failed')
|
||||
}
|
||||
const data = await response.json()
|
||||
setJellyseerrSyncStatus(
|
||||
`Set expiry for ${data?.updated ?? 0} non-admin users (${bulkExpiryDays} days).`
|
||||
)
|
||||
await loadUsers()
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
setError('Could not set expiry for all users.')
|
||||
} finally {
|
||||
setBulkExpiryBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
const bulkClearExpiry = async () => {
|
||||
setBulkExpiryBusy(true)
|
||||
setJellyseerrSyncStatus(null)
|
||||
setError(null)
|
||||
try {
|
||||
const baseUrl = getApiBase()
|
||||
const response = await authFetch(`${baseUrl}/admin/users/expiry/bulk`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
clear: true,
|
||||
scope: 'non-admin-users',
|
||||
}),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const text = await response.text()
|
||||
throw new Error(text || 'Bulk expiry clear failed')
|
||||
}
|
||||
const data = await response.json()
|
||||
setJellyseerrSyncStatus(`Cleared expiry for ${data?.updated ?? 0} non-admin users.`)
|
||||
await loadUsers()
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
setError('Could not clear expiry for all users.')
|
||||
} finally {
|
||||
setBulkExpiryBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!getToken()) {
|
||||
router.push('/login')
|
||||
return
|
||||
}
|
||||
void loadUsers()
|
||||
void loadProfiles()
|
||||
}, [router])
|
||||
|
||||
if (loading) {
|
||||
@@ -274,11 +423,11 @@ export default function UsersPage() {
|
||||
<section className="admin-section">
|
||||
{error && <div className="error-banner">{error}</div>}
|
||||
{jellyseerrSyncStatus && <div className="status-banner">{jellyseerrSyncStatus}</div>}
|
||||
<div className="user-bulk-toolbar">
|
||||
<div className="user-bulk-summary">
|
||||
<strong>Auto search/download</strong>
|
||||
<span>
|
||||
{autoSearchEnabledCount} of {nonAdminUsers.length} non-admin users enabled
|
||||
<div className="user-bulk-toolbar">
|
||||
<div className="user-bulk-summary">
|
||||
<strong>Auto search/download</strong>
|
||||
<span>
|
||||
{autoSearchEnabledCount} of {nonAdminUsers.length} non-admin users enabled
|
||||
</span>
|
||||
</div>
|
||||
<div className="user-bulk-actions">
|
||||
@@ -299,6 +448,57 @@ export default function UsersPage() {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="user-bulk-toolbar user-bulk-toolbar--stacked">
|
||||
<div className="user-bulk-summary">
|
||||
<strong>Profiles and expiry</strong>
|
||||
<span>Apply invite profile defaults and account expiry to all non-admin users.</span>
|
||||
</div>
|
||||
<div className="user-bulk-groups">
|
||||
<div className="user-bulk-group">
|
||||
<label className="admin-select">
|
||||
<span>Profile</span>
|
||||
<select
|
||||
value={bulkProfileId}
|
||||
onChange={(e) => setBulkProfileId(e.target.value)}
|
||||
disabled={bulkProfileBusy}
|
||||
>
|
||||
<option value="">None / clear assignment</option>
|
||||
{profiles.map((profile) => (
|
||||
<option key={profile.id} value={profile.id}>
|
||||
{profile.name}{profile.isActive === false ? ' (disabled)' : ''}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<button type="button" onClick={bulkApplyProfile} disabled={bulkProfileBusy}>
|
||||
{bulkProfileBusy ? 'Applying...' : 'Apply profile to all users'}
|
||||
</button>
|
||||
</div>
|
||||
<div className="user-bulk-group">
|
||||
<label>
|
||||
<span className="user-bulk-label">Expiry days</span>
|
||||
<input
|
||||
value={bulkExpiryDays}
|
||||
onChange={(e) => setBulkExpiryDays(e.target.value)}
|
||||
inputMode="numeric"
|
||||
placeholder="e.g. 30"
|
||||
disabled={bulkExpiryBusy}
|
||||
/>
|
||||
</label>
|
||||
<button type="button" onClick={bulkSetExpiryDays} disabled={bulkExpiryBusy}>
|
||||
{bulkExpiryBusy ? 'Working...' : 'Set expiry for all users'}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="ghost-button"
|
||||
onClick={bulkClearExpiry}
|
||||
disabled={bulkExpiryBusy}
|
||||
>
|
||||
{bulkExpiryBusy ? 'Working...' : 'Clear expiry for all users'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{users.length === 0 ? (
|
||||
<div className="status-banner">No users found yet.</div>
|
||||
) : (
|
||||
@@ -322,6 +522,14 @@ export default function UsersPage() {
|
||||
<span className={`user-grid-pill ${user.autoSearchEnabled === false ? 'is-disabled' : ''}`}>
|
||||
Auto search {user.autoSearchEnabled === false ? 'Off' : 'On'}
|
||||
</span>
|
||||
<span className={`user-grid-pill ${user.isExpired ? 'is-blocked' : ''}`}>
|
||||
{user.expiresAt
|
||||
? `Expiry ${user.isExpired ? 'expired' : formatExpiry(user.expiresAt)}`
|
||||
: 'Expiry Never'}
|
||||
</span>
|
||||
<span className="user-grid-pill">
|
||||
Profile {user.profileId ?? 'None'}
|
||||
</span>
|
||||
</div>
|
||||
<div className="user-grid-stats">
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user