♻️ PR#235レビュー対応: Discordロール種別ごとの分岐と退会者ロールを実装#248
Open
Tivo0921 wants to merge 11 commits into
Open
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- 付与対象を学年・学部ロールのみに変更(興味分野・メンバー種別は付与しない) - 既存の興味分野・種別ロールは管理対象として削除する - 同期結果の付与/削除カラムをロールIDではなく名前で表示 - ensureRolesInMap後に逆引きマップを構築し新規作成ロールも名前解決できるよう修正 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…o feature/discord-role-slim # Conflicts: # lib/admin/actions.ts
- 卒業生: 卒業生ロールのみ付与(年度・学部ロールなし) - その他: その他ロールのみ付与 - 退会者: opt-out確定時に退会者ロールを付与 - 再入会: 退会者ロールを削除し通常ロールを付与 - isProfileValueName に退会者を追加(管理対象に含める) - MemberRoleParams に memberType / optedOut を追加 - バルク同期でも種別ごとに正しいロールを ensureRolesInMap に渡すよう修正 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Deployed on https://dev-pr-248-birbz3fm6q-an.a.run.app |
Contributor
There was a problem hiding this comment.
Pull request overview
Discord ロール同期を「メンバー種別(学部生/院生/卒業生/その他)」「退会者(optedOut)」で分岐させ、退会・再入会・オンボーディング・管理者一括同期の各フローから同期できるようにするPRです。
Changes:
lib/discord-role.tsを追加し、Discord ロールの作成/付与/削除と同期ロジック(種別・退会者分岐)を実装- 退会確定/再入会/オンボーディング完了時にロール同期を呼ぶように API/ページ側を更新
- 管理者ページに「Discordロール一括同期」パネルを追加し、Firestore→Discord の一括同期を実装
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/discord-role.ts | ロール名マップ取得・不足ロール作成・メンバーへのロール差分同期(退会者/卒業生/その他/通常)を追加 |
| lib/admin/actions.ts | 管理者用の一括ロール同期サーバーアクションを追加(Firestoreから対象取得→同期) |
| components/admin/role-sync-panel.tsx | 管理画面から一括同期を実行し、付与/削除/エラーを表示するUIを追加 |
| app/internal/(protected)/admin/page.tsx | 管理者ページにロール同期パネルを追加 |
| app/optout/confirm/[discordId]/[exp]/[messageId]/[sig]/page.tsx | 退会確定時に退会者ロールへ同期する呼び出しを追加 |
| app/api/optout/rejoin/route.ts | 再入会時に退会者ロール削除+通常ロール付与の同期呼び出しを追加 |
| app/api/onboarding/route.ts | オンボーディング完了時にロール同期呼び出しを追加 |
| app/layout.tsx | テーマ初期化スクリプトを next/script から素の <script> に変更 |
| .env.example | MEMBER_ROLE_ID の説明を追加 |
| .gitignore | env.share を追加 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+173
to
+176
| // 退会者ロール付与 (fire-and-forget) | ||
| syncMemberDiscordRoles(discordId, { optedOut: true }).catch((e) => { | ||
| console.error("Failed to sync Discord roles (optout):", e); | ||
| }); |
Comment on lines
+106
to
+112
| syncMemberDiscordRoles(session.user.id, { | ||
| year: updatedMember.yearByFiscal?.[String(new Date().getFullYear())], | ||
| faculty: updatedMember.enrollments?.find((e) => e.isCurrent)?.faculty, | ||
| memberType: updatedMember.memberType, | ||
| }).catch((e) => { | ||
| console.error("Failed to sync Discord roles (onboarding):", e); | ||
| }); |
Comment on lines
+42
to
+51
| // 退会者ロール削除 + 通常ロール付与 (fire-and-forget) | ||
| if (member) { | ||
| syncMemberDiscordRoles(discordId, { | ||
| year: member.yearByFiscal?.[String(new Date().getFullYear())], | ||
| faculty: member.enrollments?.find((e) => e.isCurrent)?.faculty, | ||
| memberType: member.memberType, | ||
| }).catch((e) => { | ||
| console.error("Failed to sync Discord roles (rejoin):", e); | ||
| }); | ||
| } |
Comment on lines
+239
to
+246
| const targets = snap.docs.filter((doc) => doc.data().optedOut !== true); | ||
| result.total = targets.length; | ||
|
|
||
| const roleNameMap = await getGuildRoleNameMap(); | ||
| console.log( | ||
| `[role-sync] ギルドロール ${roleNameMap.size}件を取得: [${[...roleNameMap.keys()].join(", ")}]`, | ||
| ); | ||
| console.log(`[role-sync] 対象メンバー: ${result.total}件`); |
Comment on lines
+125
to
+127
| メンバー種別・学年・学部・興味分野は Discord | ||
| サーバーのロール名と自動マッチングし、不要になったロールは削除します。 | ||
| 年度メンバーロール(全員共通)は環境変数 |
| <section className="mt-10"> | ||
| <h2 className="text-lg font-semibold mb-4">Discordロール付与</h2> | ||
| <p className="text-sm text-muted-foreground mb-4"> | ||
| 登録済みメンバー全員に年度メンバーロールおよびメンバー種別ロールを一括付与します。 |
Comment on lines
+31
to
+33
| # メンバー種別・学年・学部・興味分野のロールは Discord ギルドのロール名で自動マッチング。 | ||
| # Discord サーバーのロール名をプロフィール値(例: "理工学部", "Python", "学部3年", "学部生")と | ||
| # 一致させれば env var の設定なしに自動で付与される。 |
Comment on lines
+131
to
+135
| // ロール名 → ID のマップを返す。バッチ処理では一度だけ呼び出して使い回す。 | ||
| export async function getGuildRoleNameMap(): Promise<Map<string, string>> { | ||
| const roles = await fetchGuildRoles(); | ||
| return new Map(roles.map((r) => [r.name, r.id])); | ||
| } |
Comment on lines
+156
to
+164
| // params から付与すべきロール ID 一覧を返す。 | ||
| // 退会者: 退会者ロールのみ | ||
| // 卒業生: 卒業生ロールのみ | ||
| // その他: その他ロールのみ | ||
| // 学部生・院生: MEMBER_ROLE_ID + 学年 + 学部/学府 | ||
| function getTargetRoleIds( | ||
| params: MemberRoleParams, | ||
| roleNameMap: Map<string, string>, | ||
| ): { roleIds: string[]; matched: string[]; notFound: string[] } { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
対応した指摘 (PR #235 コメント)
Shion1305 さんのレビューコメントに基づき、ロール付与ロジックを種別ごとに分岐させ、退会者ロールのフローを追加しました。
変更内容
ロール付与の分岐(
lib/discord-role.ts)MEMBER_ROLE_ID+学部X年/修士X年/博士X年+ 学部/学府ロール卒業生のみその他のみ退会者のみMemberRoleParamsにmemberType/optedOutを追加isProfileValueNameに退会者を追加(管理対象ロールとして削除候補に含める)YEAR_ROLE_PATTERNからその他X年パターンを除外(その他は年号なしのロール)退会者ロールのフロー
app/optout/confirm/.../page.tsx):markMemberOptedOut後に退会者ロールを付与app/api/optout/rejoin/route.ts):markMemberRejoined後に退会者ロールを削除し、プロフィールに応じた通常ロールを付与その他修正
app/api/onboarding/route.ts:memberTypeをsyncMemberDiscordRolesに渡すよう修正lib/admin/actions.ts: バルク同期の Firestore select にmemberTypeを追加、種別ごとに正しいロール名をensureRolesInMapに渡すよう修正Test plan
手動テスト済み(実機の Discord サーバーで確認)
学部X年+ 学部ロールのみ付与される卒業生ロールのみ付与される(年度・学部ロールなし)その他ロールのみ付与される退会者ロールが付き、他の管理対象ロールが削除される退会者ロールが削除され、正しいロールが付与される🤖 Generated with Claude Code