Skip to content

Conversation

@atomisu0312
Copy link
Contributor

@atomisu0312 atomisu0312 commented Aug 18, 2025

ユーザグループを入力しなくてもイベントが作れてしまい、かつ、リダイレクト時に404と出てしまうエラーが確認されました。

状況を分析すると以下のことが確認できました。

  1. フォーム上のフィールド(user_group)が空欄の状態で渡される
  2. バリデーション時にエラーとならず0として解釈
  3. userGroupIdが0となり、そんなグループは存在しないので誰もアクセスできない。

よって、以下の対策を実施します。

  • 新規グループ作成画面において、デフォルト値としてユーザグループを設定しておく
  • バリデーションで弾かれるようにする

手動ではまず起こらないですが、万が一select要素から値が消えてもバリデーションエラーとして処理されます。

Image

ユーザグループを入力しなくてもイベントが作れてしまい、かつ、リダイレクト時に404と出てしまうエラーが確認されました。

流れは以下の通りです。

1. フォーム上のフィールド(user_group)が空欄の状態で渡される
2. バリデーション時にエラーとならず0として解釈
3. userGroupIdが0となり、そんなグループは存在しないので誰もアクセスできない。

以下の対策の両方を実施します。

- 新規グループ作成画面において、デフォルト値としてユーザグループを入れる
- バリデーションで弾かれるようにする

ご迷惑をおかけいたしました。
@atomisu0312 atomisu0312 self-assigned this Aug 18, 2025

This comment was marked as outdated.

@atomisu0312 atomisu0312 requested a review from Copilot August 20, 2025 23:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug where events could be created with empty user groups, resulting in inaccessible events and 404 errors. The fix involves setting a default user group value and improving validation to prevent empty user group submissions.

  • Added default value selection for user group field in the event registration form
  • Enhanced validation to properly handle empty user group values with custom error messages
  • Added explicit type conversion from string to number after validation

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
EventRegisterTemplate.tsx Sets default user group selection to first available group
viewmodel.ts Improves user group validation with string-based validation and explicit number conversion

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

field?.name === 'userGroupId'
? {
...field,
defaultValue: userGroups[0].id.toString(),
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

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

Accessing userGroups[0] without checking if the array is empty will cause a runtime error when no user groups exist. Add a check to ensure userGroups.length > 0 before accessing the first element.

Suggested change
defaultValue: userGroups[0].id.toString(),
defaultValue: userGroups.length > 0 ? userGroups[0].id.toString() : '',

Copilot uses AI. Check for mistakes.
@YasunariIguchi YasunariIguchi merged commit 4e573bd into develop Oct 22, 2025
2 checks passed
@YasunariIguchi YasunariIguchi deleted the feature/#272 branch October 22, 2025 09:14
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.

3 participants