Skip to content

ファイルアップロードの上限に関する検証を修正:上限値0を防ぎ、適切なエラーメッセージを追加するようにしました #693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 16, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 15, 2025

Problem

Users could create file upload fields with a limit of 0, which doesn't make functional sense and causes confusion. The form editor allowed this invalid configuration both through the default value and lack of validation.

Solution

This PR implements a two-part fix:

1. Added Minimum Value Validation

// In FormFieldEditor.tsx
{...register(`items.${index}.limit`, {
  required: { value: true, message: "ファイル数上限を入力してください" },
  min: { value: 1, message: "この設定では何も提出できません" }, // ← Added this line
  valueAsNumber: true,
})}

2. Fixed Default Value

// In FormEditor.tsx - when creating new file fields
append({
  name: "",
  type: "file", 
  required: false,
  extensions: "",
  limit: 1, // ← Changed from 0 to 1
});

Impact

  • Before: File upload fields could be created with limit 0, making them unusable
  • After:
    • New file fields default to limit 1
    • If user tries to set limit to 0, they see the error: "この設定では何も提出できません"
    • Form validation prevents submission with invalid limits

Technical Details

  • Follows existing validation patterns used elsewhere in the codebase
  • Minimal changes (only 2 lines of logic modified)
  • Added test coverage for the validation rule
  • No impact on existing functionality

Fixes #677.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • downloads.sentry-cdn.com
    • Triggering command: node ./scripts/install.js (dns block)
    • Triggering command: node /home/REDACTED/work/sos24-client/sos24-client/node_modules/.bin/next build --no-lint (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] ファイル数上限0の申請を作成できる Fix file upload limit validation: prevent limit 0 and add proper error message Jul 15, 2025
@Copilot Copilot AI requested a review from naohanpen July 15, 2025 17:29
Copilot finished work on behalf of naohanpen July 15, 2025 17:29
Copy link
Contributor

@naohanpen naohanpen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot 修正してください

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

方針がまとまっていないので、テストは消して大丈夫です

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the test file as requested. Commit 80b4be9

@@ -276,6 +276,7 @@ export const FormFieldEditor: FC<{
type="number"
{...register(`items.${index}.limit`, {
required: { value: true, message: "ファイル数上限を入力してください" },
min: { value: 1, message: "この設定では何も提出できません" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

エラーではなく、警告を表示するだけで送信(保存)はできるようにしてください。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed from error to warning. Now shows orange warning message "この設定では何も提出できません" when limit is 0, but allows form submission. Commit 80b4be9

Copy link
Contributor Author

Copilot AI commented Jul 15, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • downloads.sentry-cdn.com
    • Triggering command: node ./scripts/install.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of naohanpen July 15, 2025 17:47
@Copilot Copilot AI requested a review from naohanpen July 15, 2025 17:47
@naohanpen naohanpen requested a review from Nitoryu008 July 15, 2025 17:51
@naohanpen naohanpen changed the title Fix file upload limit validation: prevent limit 0 and add proper error message ファイルアップロードの上限に関する検証を修正:上限値0を防ぎ、適切なエラーメッセージを追加するようにしました Jul 15, 2025
Copy link

github-actions bot commented Jul 15, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 3.58% 511 / 14259
🔵 Statements 3.58% 511 / 14259
🔵 Functions 38.87% 131 / 337
🔵 Branches 59.81% 189 / 316
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/common_components/formFields/styles.ts 0% 0% 0% 0% 1-113
src/common_components/form_editor/FormEditor.tsx 0% 100% 100% 0% 3-551
src/common_components/form_editor/FormFieldEditor.tsx 0% 100% 100% 0% 3-336
Generated in workflow #1442 for commit 1d8a293 by the Vitest Coverage Report Action

Copy link

cloudflare-workers-and-pages bot commented Jul 15, 2025

Deploying sos25-client with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1d8a293
Status: ✅  Deploy successful!
Preview URL: https://90ba1a98.sos25-client.pages.dev
Branch Preview URL: https://copilot-fix-677.sos25-client.pages.dev

View logs

@naohanpen naohanpen marked this pull request as ready for review July 15, 2025 17:53
@naohanpen naohanpen marked this pull request as draft July 15, 2025 18:00
Copy link
Contributor

@Nitoryu008 Nitoryu008 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow

@Nitoryu008 Nitoryu008 merged commit c22071b into develop Jul 16, 2025
5 checks passed
@Nitoryu008 Nitoryu008 deleted the copilot/fix-677 branch July 16, 2025 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ファイル数上限0の申請を作成できる
3 participants