re-enabled autoseeding of attachment groups
All checks were successful
CI/CD Pipeline / test (push) Successful in 7s
CI/CD Pipeline / deploy (push) Successful in 19s

This commit is contained in:
2026-01-28 20:01:02 +01:00
parent c33cde6f04
commit 7fbc566129
2 changed files with 63 additions and 12 deletions

View File

@@ -1140,34 +1140,63 @@ export default function Acp({ isAdmin }) {
setAttachmentGroupsError('')
setAttachmentExtensionsError('')
try {
const groupsByName = new Map(attachmentGroups.map((group) => [group.name, group]))
const extensionsByGroup = new Map()
attachmentExtensions.forEach((ext) => {
const groupId = ext.attachment_group_id ? String(ext.attachment_group_id) : 'none'
if (!extensionsByGroup.has(groupId)) {
extensionsByGroup.set(groupId, new Set())
}
extensionsByGroup
.get(groupId)
.add(String(ext.extension || '').toLowerCase())
})
const createdGroups = []
const createdExtensions = []
for (const group of attachmentDefaultSeed) {
const parent = await createAttachmentGroup({
name: group.name,
max_size_kb: group.max_size_kb,
is_active: true,
})
let parent = groupsByName.get(group.name)
if (!parent) {
parent = await createAttachmentGroup({
name: group.name,
max_size_kb: group.max_size_kb,
is_active: true,
})
groupsByName.set(group.name, parent)
createdGroups.push(parent)
}
createdGroups.push(parent)
for (const child of group.children || []) {
const createdChild = await createAttachmentGroup({
name: child.name,
parent_id: parent.id,
max_size_kb: child.max_size_kb,
is_active: true,
})
createdGroups.push(createdChild)
let createdChild = groupsByName.get(child.name)
if (!createdChild) {
createdChild = await createAttachmentGroup({
name: child.name,
parent_id: parent.id,
max_size_kb: child.max_size_kb,
is_active: true,
})
groupsByName.set(child.name, createdChild)
createdGroups.push(createdChild)
}
const groupKey = String(createdChild.id)
const existingSet = extensionsByGroup.get(groupKey) || new Set()
for (const ext of child.extensions || []) {
const key = String(ext.ext || '').toLowerCase()
if (existingSet.has(key)) {
continue
}
const createdExt = await createAttachmentExtension({
extension: ext.ext,
attachment_group_id: createdChild.id,
allowed_mimes: ext.mimes,
})
createdExtensions.push(createdExt)
existingSet.add(key)
}
extensionsByGroup.set(groupKey, existingSet)
}
}
@@ -2677,6 +2706,16 @@ export default function Acp({ isAdmin }) {
<div className="d-flex justify-content-between align-items-center mb-3">
<h5 className="mb-0">{t('attachment.groups_title')}</h5>
<div className="d-flex align-items-center gap-2">
<Button
type="button"
className="bb-accent-button"
onClick={handleSeedAttachmentDefaults}
disabled={attachmentSeedSaving}
>
{attachmentSeedSaving
? t('attachment.seed_in_progress')
: t('attachment.seed_defaults')}
</Button>
<Button
type="button"
variant="outline-secondary"
@@ -2722,6 +2761,16 @@ export default function Acp({ isAdmin }) {
{!attachmentGroupsLoading && attachmentGroups.length > 0
&& attachmentGroups.every((group) => !group.parent_id) && (
<div className="bb-muted mb-3">
<Button
type="button"
className="bb-accent-button me-2"
onClick={handleSeedAttachmentDefaults}
disabled={attachmentSeedSaving}
>
{attachmentSeedSaving
? t('attachment.seed_in_progress')
: t('attachment.seed_defaults')}
</Button>
<Button
type="button"
variant="outline-secondary"