fix: Fix policy document format to send as object instead of double-stringified JSON

- Change generatePolicyFromTemplate to return object instead of string
- Update CreatePolicyRequest interface to accept string | object for policy
- Update CreatePolicyDialog to stringify policy object only when needed
- Fix QuickStartWizard to send policy object directly to API

This fixes the 'Proxy error' when creating policies as the backend was
receiving double-stringified JSON which failed validation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-07-23 17:50:41 +02:00
parent f02d1c8890
commit c2469ba5e9
2 changed files with 5 additions and 6 deletions
@@ -74,7 +74,7 @@ const CreatePolicyDialog: React.FC<CreatePolicyDialogProps> = ({
const generatePreview = () => { const generatePreview = () => {
if (bucketName && selectedTemplate) { if (bucketName && selectedTemplate) {
const generatedPolicy = policyService.generatePolicyFromTemplate(selectedTemplate, bucketName); const generatedPolicy = policyService.generatePolicyFromTemplate(selectedTemplate, bucketName);
setCustomPolicy(generatedPolicy); setCustomPolicy(JSON.stringify(generatedPolicy, null, 2));
} }
}; };
@@ -111,7 +111,7 @@ const CreatePolicyDialog: React.FC<CreatePolicyDialogProps> = ({
setError('Bucket name is required'); setError('Bucket name is required');
return; return;
} }
policyToCreate = policyService.generatePolicyFromTemplate(selectedTemplate, bucketName); policyToCreate = JSON.stringify(policyService.generatePolicyFromTemplate(selectedTemplate, bucketName), null, 2);
} }
if (!validatePolicy()) { if (!validatePolicy()) {
+3 -4
View File
@@ -12,7 +12,7 @@ export interface Policy {
export interface CreatePolicyRequest { export interface CreatePolicyRequest {
name: string; name: string;
policy: string; policy: string | object;
} }
export interface AttachPolicyRequest { export interface AttachPolicyRequest {
@@ -220,13 +220,12 @@ class PolicyService {
} }
// Generate policy from template // Generate policy from template
generatePolicyFromTemplate(templateKey: string, bucketName: string): string { generatePolicyFromTemplate(templateKey: string, bucketName: string): object {
const template = policyTemplates[templateKey]; const template = policyTemplates[templateKey];
if (!template) { if (!template) {
throw new Error('Invalid template'); throw new Error('Invalid template');
} }
const policy = template.generatePolicy(bucketName); return template.generatePolicy(bucketName);
return JSON.stringify(policy, null, 2);
} }
} }