refactor(housekeeping): return result from bulkImport, remove dead server calls, sync i18n
Local Build and Deploy / deploy (push) Successful in 1m15s
Local Build and Deploy / deploy (push) Successful in 1m15s
- bulkImportPermissions now returns {count, errors} instead of void
- ImportSection shows per-entry error details in toast
- Remove testRankPermission server action (test is 100% client-side)
- Clean up unused testing state in TestSection
- Sync pages.admin.{import,translations} keys to all 20 languages
- Add importedWithErrors translation key to all locales
This commit is contained in:
1 parent
702ab9fc67
commit
d693d169dd
24 files changed
+722
-61
No files matched your search
@@ -127,24 +127,28 @@ export async function deletePermission(formData: FormData): Promise<void> {
|
||||
revalidatePath("/admin/housekeeping");
|
||||
}
|
||||
|
||||
export async function bulkImportPermissions(formData: FormData): Promise<void> {
|
||||
export async function bulkImportPermissions(
|
||||
formData: FormData,
|
||||
): Promise<{ count: number; errors: string[] }> {
|
||||
await requirePermission(PERMS.SETTINGS_EDIT);
|
||||
|
||||
const raw = sanitize(String(formData.get("json") ?? ""));
|
||||
if (!raw) return;
|
||||
if (!raw) return { count: 0, errors: ["Empty input"] };
|
||||
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(raw);
|
||||
} catch {
|
||||
return;
|
||||
return { count: 0, errors: ["Invalid JSON"] };
|
||||
}
|
||||
|
||||
if (!Array.isArray(parsed)) {
|
||||
return;
|
||||
return { count: 0, errors: ["Expected an array"] };
|
||||
}
|
||||
|
||||
const userId = await currentUserId();
|
||||
const errors: string[] = [];
|
||||
let count = 0;
|
||||
|
||||
for (const item of parsed) {
|
||||
const permission = sanitize(String(item.permission ?? ""));
|
||||
@@ -154,6 +158,7 @@ export async function bulkImportPermissions(formData: FormData): Promise<void> {
|
||||
const dependsOn = sanitize(String(item.dependsOn ?? "")) || null;
|
||||
|
||||
if (!permission || !Number.isFinite(minRank) || minRank < 0) {
|
||||
errors.push("Invalid entry: " + JSON.stringify(item));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -176,12 +181,14 @@ export async function bulkImportPermissions(formData: FormData): Promise<void> {
|
||||
updatedBy: userId ?? undefined,
|
||||
},
|
||||
});
|
||||
count++;
|
||||
} catch {
|
||||
// Failed to upsert
|
||||
errors.push("Failed to upsert: " + permission);
|
||||
}
|
||||
}
|
||||
|
||||
revalidatePath("/admin/housekeeping");
|
||||
return { count, errors };
|
||||
}
|
||||
|
||||
export async function exportPermissions(): Promise<string> {
|
||||
@@ -863,20 +870,4 @@ export async function clearAllPermissions(): Promise<void> {
|
||||
revalidatePath("/admin/housekeeping");
|
||||
}
|
||||
|
||||
export async function testRankPermission(formData: FormData): Promise<void> {
|
||||
await requirePermission(PERMS.SETTINGS_VIEW);
|
||||
|
||||
const rank = Number(formData.get("testRank"));
|
||||
if (!Number.isFinite(rank) || rank < 0) return;
|
||||
|
||||
const perms = await prisma.websiteHousekeepingPermissions.findMany({
|
||||
where: { minRank: { lte: rank } },
|
||||
orderBy: [{ groupName: "asc" }, { permission: "asc" }],
|
||||
select: { permission: true },
|
||||
});
|
||||
|
||||
const granted = perms.map((p) => p.permission);
|
||||
revalidatePath("/admin/housekeeping");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user