Skip to content

fix: service以下の状態名変更#1052

Open
Hueter57 wants to merge 1 commit into
v2from
904_change_status_name
Open

fix: service以下の状態名変更#1052
Hueter57 wants to merge 1 commit into
v2from
904_change_status_name

Conversation

@Hueter57

@Hueter57 Hueter57 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

#904

servise内の状態名のみ変更
現状行ったのは状態名の変更のみ

状態遷移の修正に関して、現状の遷移図がわからない・現状のプログラムの意図が読むだけではわかりにくかったためまだ行っていないが、状態遷移を行っている場所は見つけた

Summary by CodeRabbit

リリースノート

  • New Features

    • アカウントマネージャーが承認済みのアプリケーションを再確認待ちの状態に戻す機能を追加しました。
  • Refactor

    • アプリケーションステータスの管理ロジックとバリデーション条件を最適化しました。

@Hueter57 Hueter57 requested a review from H1rono June 10, 2026 12:25
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

このプルリクエストは、アプリケーション申請のステータス体系を刷新し、ステータス遷移の権限制御ロジックを再定義する変更と、ファイル処理で使用される MIME タイプ許可リストを公開化する変更を含みます。

Changes

ステータス体系と遷移制御の更新

Layer / File(s) Summary
ステータス定義とシリアライズ対応
internal/service/application_status.go
Status 列挙定数が PendingReviewChangeRequestedApprovedPaymentFinished に更新され、String()、MarshalJSON()、UnmarshalJSON() メソッドが新しい状態値と JSON 文字列形式の対応に修正されました。
ステータス遷移権限と許可条件
internal/service/application.go
UpdateApplicationStatus で Approved から PendingReview への戻し分岐が追加され、isAbleNoCommentUpdateStatus、isAbleAccountManagerUpdateStatus、isAbleCreatorChangeStatus の許可ルールが新しいステータス値を対象に再定義されました。

MIME タイプ許可リストの公開化

Layer / File(s) Summary
ApprovedMimeTypes の公開化と参照更新
internal/service/file.go
MIME タイプ検証用の acceptedMimeTypes 非公開変数が ApprovedMimeTypes 公開変数に変更され、WriteFile 内の参照も更新されました。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトルは「service以下の状態名変更」であり、実際の変更内容(Status列挙値の置き換え、ステータス遷移制御の変更、MIME型マップの公開化)を適切に要約しています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 904_change_status_name

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Hueter57

Copy link
Copy Markdown
Contributor Author

func (s *Service) isAbleNoCommentUpdateStatus(currentStatus, newStatus Status) bool {
switch currentStatus {
case PendingReview:
return newStatus != ChangeRequested && newStatus != Rejected
case Approved:
return newStatus != PendingReview
case ChangeRequested, PaymentFinished, Rejected:
return true
default:
return false
}
}
func (s *Service) isAbleAccountManagerUpdateStatus(currentStatus, newStatus Status) bool {
return newStatus == Rejected && currentStatus == PendingReview ||
newStatus == PendingReview && currentStatus == ChangeRequested ||
newStatus == Approved && currentStatus == PendingReview ||
newStatus == PendingReview && currentStatus == Approved ||
newStatus == ChangeRequested && currentStatus == PendingReview
}
func (s *Service) isAbleCreatorChangeStatus(currentStatus, newStatus Status) bool {
return currentStatus == ChangeRequested && newStatus == PendingReview
}
func (s *Service) isAccountManagerRevertingApprovedApplication(
user *User, currentStatus, newStatus Status,
) bool {
return user.AccountManager && currentStatus == Approved && newStatus == PendingReview
}

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/service/application.go (1)

276-282: 💤 Low value

可読性向上のため括弧の追加を検討してください。

Goの演算子優先順位(&& > ||)により論理的には正しいですが、複数の条件が連なっているため一目で理解しにくいです。

♻️ 括弧を追加した例
 func (s *Service) isAbleAccountManagerUpdateStatus(currentStatus, newStatus Status) bool {
-	return newStatus == Rejected && currentStatus == PendingReview ||
-		newStatus == PendingReview && currentStatus == ChangeRequested ||
-		newStatus == Approved && currentStatus == PendingReview ||
-		newStatus == PendingReview && currentStatus == Approved ||
-		newStatus == ChangeRequested && currentStatus == PendingReview
+	return (newStatus == Rejected && currentStatus == PendingReview) ||
+		(newStatus == PendingReview && currentStatus == ChangeRequested) ||
+		(newStatus == Approved && currentStatus == PendingReview) ||
+		(newStatus == PendingReview && currentStatus == Approved) ||
+		(newStatus == ChangeRequested && currentStatus == PendingReview)
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/service/application.go` around lines 276 - 282, The boolean
expression in isAbleAccountManagerUpdateStatus is correct but hard to read due
to mixed && and ||; wrap each binary comparison pair in parentheses to clarify
grouping (e.g., (newStatus == Rejected && currentStatus == PendingReview),
(newStatus == PendingReview && currentStatus == ChangeRequested), etc.), keeping
the same logic and using the existing Status constants Rejected, PendingReview,
ChangeRequested, Approved so the intent is explicit and easier to maintain.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/service/file.go`:
- Around line 101-102: The WriteFile flow is doing a strict equals check against
ApprovedMimeTypes using the raw Content-Type header, which fails when parameters
(e.g. "image/jpeg; charset=binary") are present; modify WriteFile to call
mime.ParseMediaType on the incoming mimetype (from echo.HeaderContentType),
extract the mediaType, normalize it to lowercase, and then check
ApprovedMimeTypes[mediaType]; ensure you handle ParseMediaType errors (treat as
unsupported) and keep the ApprovedMimeTypes lookup using the normalized media
type.

---

Nitpick comments:
In `@internal/service/application.go`:
- Around line 276-282: The boolean expression in
isAbleAccountManagerUpdateStatus is correct but hard to read due to mixed && and
||; wrap each binary comparison pair in parentheses to clarify grouping (e.g.,
(newStatus == Rejected && currentStatus == PendingReview), (newStatus ==
PendingReview && currentStatus == ChangeRequested), etc.), keeping the same
logic and using the existing Status constants Rejected, PendingReview,
ChangeRequested, Approved so the intent is explicit and easier to maintain.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4dec30a9-c637-4c91-a912-8472f0c45243

📥 Commits

Reviewing files that changed from the base of the PR and between 76c53b0 and 94756a0.

📒 Files selected for processing (3)
  • internal/service/application.go
  • internal/service/application_status.go
  • internal/service/file.go

Comment thread internal/service/file.go
Comment on lines +101 to 102
if !ApprovedMimeTypes[mimetype] {
return nil, NewBadInputError("unsupported mime type")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 生ヘッダー受け渡しと ParseMediaType 未使用の確認
rg -n -C2 'Header\.Get\(echo\.HeaderContentType\)'
rg -n -C2 '\bWriteFile\s*\(.*mimetype' --type=go
rg -n -C2 '\bParseMediaType\s*\(' --type=go

Repository: traPtitech/Jomon

Length of output: 608


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== internal/service/file.go (around 80-130) ==="
nl -ba internal/service/file.go | sed -n '70,140p'

echo
echo "=== Find ApprovedMimeTypes / IsApprovedMimeType ==="
rg -n "ApprovedMimeTypes|IsApprovedMimeType" --type=go .

echo
echo "=== internal/router/file.go (around 40-100) ==="
nl -ba internal/router/file.go | sed -n '40,110p'

echo
echo "=== Ensure ParseMediaType usage absence (more broad) ==="
rg -n "ParseMediaType" --type=go .

echo
echo "=== Any existing mime parsing/normalization helpers ==="
rg -n "Parse.*MediaType|ToLower\\(mediaType\\)|strings\\.ToLower\\(.*mim" --type=go internal || true

Repository: traPtitech/Jomon

Length of output: 170


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== internal/service/file.go (lines ~80-130) ==="
sed -n '70,140p' internal/service/file.go | cat -n

echo
echo "=== Find ApprovedMimeTypes / IsApprovedMimeType ==="
rg -n "ApprovedMimeTypes|IsApprovedMimeType" --type=go .

echo
echo
echo "=== internal/router/file.go (lines ~40-100) ==="
sed -n '40,110p' internal/router/file.go | cat -n

echo
echo
echo "=== ParseMediaType usage (anywhere) ==="
rg -n "ParseMediaType" --type=go .

Repository: traPtitech/Jomon

Length of output: 5033


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== internal/service/file.go (lines ~1-70) ==="
sed -n '1,80p' internal/service/file.go | cat -n

Repository: traPtitech/Jomon

Length of output: 2855


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== internal/service/file.go (lines ~1-80) ==="
sed -n '1,80p' internal/service/file.go | cat -n

Repository: traPtitech/Jomon

Length of output: 2855


Content-Typeを生値で完全一致判定しており、パラメータ付きで誤拒否する可能性があります。

internal/router/file.go:60 で echo.HeaderContentType をそのまま WriteFile に渡し、internal/service/file.go(WriteFile)で ApprovedMimeTypes[mimetype] の完全一致で判定しているため、image/jpeg; charset=binary のような値が来ると一致せず unsupported mime type になります。mime.ParseMediaType でパラメータを除いたメディアタイプ部分に正規化(小文字化)してから ApprovedMimeTypes[mediaType] を判定してください。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/service/file.go` around lines 101 - 102, The WriteFile flow is doing
a strict equals check against ApprovedMimeTypes using the raw Content-Type
header, which fails when parameters (e.g. "image/jpeg; charset=binary") are
present; modify WriteFile to call mime.ParseMediaType on the incoming mimetype
(from echo.HeaderContentType), extract the mediaType, normalize it to lowercase,
and then check ApprovedMimeTypes[mediaType]; ensure you handle ParseMediaType
errors (treat as unsupported) and keep the ApprovedMimeTypes lookup using the
normalized media type.

@H1rono

H1rono commented Jun 12, 2026

Copy link
Copy Markdown
Member

ありがとうございます

実はrouter以下にも同様のstatusがあって、こいつといい感じに同期をとる必要があります

type Status string
const (
Submitted Status = "submitted"
FixRequired Status = "fix_required"
Accepted Status = "accepted"
Completed Status = "completed"
Rejected Status = "rejected"
)

とりあえず、ここもservice以下の変更と同様にrenameしてあげてください。

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.

2 participants