Google 帳號登入整合、RBAC 角色權限矩陣與 UGC 自建考試科目/考題實作計畫
本計畫針對使用者的五項需求進行全面規劃:
AuthController 與 LoginScreen,支援真實/擬真的 Google OAuth 登入互動流程與帳號持久化綁定。UserRole 與 AppUser,明確劃分 admin (系統管理員)、creator (題目創作者/出題教師)、pro (進階專業學員)、viewer (一般學員) 與 guest (未登入訪客)。[!IMPORTANT]
任何 Google 帳號登入者的預設角色與權限:
業界現代化 UGC 學習平台(如 Quizlet、AnkiWeb、LeetCode 社群)的標準做法是:
- 任何使用者只要以 Google 帳號登入,系統即自動註冊/綁定其 Google 身分,並預設賦予
creator(創作者/學員雙重身分)。- 此身分立即可在首頁建立任何新考試科目(例如:AWS Certified Solutions Architect、日語檢定 JLPT N1、多益 TOEIC 等),並在自創科目內自由新增考題。
- 對於其他人建立的科目與考題,系統強制提供「練習模式」與「討論區」,但編輯與刪除權限嚴格由 Google UID 所有權隔離。
- 若為未登入之訪客(
guest),首頁提供瀏覽與前 5 題試做,當點擊「建立科目」、「新增考題」或「發表討論」時,自動彈出 Google 登入引導。
[!NOTE]
目前專案內的所有.md文件已完成grep_search全盤掃描,確認搜尋結果為 0 筆 Supabase,全部文檔均已對齊純 Google 雲端架構(Cloud Firestore, Firebase RTDB, Vertex AI, Google Cloud Run)。
| 角色 (UserRole) | 建立新科目 | 建立考題 | 編輯自己考題 | 編輯他人考題 | 發表討論 | AI 導師解析 | 模擬考 | 管理員後台 |
|---|---|---|---|---|---|---|---|---|
admin (管理員) |
✅ | ✅ | ✅ | ✅ (審核) | ✅ | ✅ (無限制) | ✅ | ✅ (全站模型廣播) |
creator (Google登入出題者) |
✅ | ✅ | ✅ | ❌ (唯讀) | ✅ | ✅ | ✅ | ❌ |
pro (付費專業學員) |
✅ | ✅ | ✅ | ❌ (唯讀) | ✅ | ✅ | ✅ | ❌ |
viewer (一般學員) |
❌ (引導出題) | ❌ | ❌ | ❌ (唯讀) | ✅ | 點數限制 | ✅ | ❌ |
guest (未登入訪客) |
❌ (彈窗登入) | ❌ (彈窗登入) | ❌ | ❌ | ❌ (彈窗登入) | 僅試用 3 次 | 體驗模式 | ❌ |
UserRole:新增 creator 角色。bool get canCreateSubject => isAdmin || role == UserRole.creator || role == UserRole.pro;
bool get canCreateQuestion => isLoggedIn;
bool get canAccessAiTutor => isLoggedIn;
bool get canManageSystem => isAdmin;
bool get isGuest => role == UserRole.guest;
photoUrl、provider: 'google'、isGoogleUser: true。signInWithGoogleAccount({required String email, required String displayName, String? photoUrl})。loginWithGoogle,提供可自訂或快捷選擇常用 Google 帳號進行登入的流暢體驗。ISubjectRepository:
getSubjects(): 合併官方 18+ Cisco 認證科目與本機/雲端由學員自建之科目。createSubject(ExamSubject subject, {required String currentUserId}): 驗證登入與建立者 UID 綁定。deleteSubject(String subjectId, {required String currentUserId}): 驗證所有權。LocalPersistentCache,連線後同步至 Cloud Firestore exam_subjects。SubjectRepository,支援動態載入、篩選(「官方科目」與「社群自建科目」)。addNewSubject(...) 與 deleteCustomSubject(...) 方法。AWS-SAA-C03, TOEIC-900, PMP-2026)AWS 雲端架構師認證, 多益核心文法閱讀)cloud, code, school, security, language 等)建立者:[Google姓名] 與創作者標章)。test/unit/google_auth_and_rbac_test.dart:
canCreateSubject, canCreateQuestion, canManageSystem)。flutter analyze 確保 0 個 Warning 與 0 個 Error。flutter test 確保全數測試通過。AWS-SAA-C03),並成功在該科目下新增考題。Google 帳號登入、RBAC 角色矩陣與 UGC 社群考科出題平台實作完成驗證報告
本報告總結針對五項重大需求所完成之架構改造、程式碼升級與驗證成果。
app_docs/ 全套新手與部署手冊、docs_opensource/ 11 大系統架構設計規範。login_screen.dart):
_showGoogleSignInModal),支援快速切換本機預設 Google 帳號(如 alan.nanpie@gmail.com),或自由輸入任何 Gmail / Google Workspace 企業與學校帳號。user_repository.dart & auth_controller.dart):
google_{sanitized_email})。在 app_user.dart 中落實細粒度能力屬性(Capability-based Access Control):
| 角色 (UserRole) | 中文識別名稱 | 自建考試科目 (UGC) | 各考科自由出題 CRUD | 存取 AI 導師 | 模擬測驗 | 討論區互動 | 全站模型管控 |
|---|---|---|---|---|---|---|---|
admin |
👑 系統管理員 | ✅ | ✅ | ✅ (無限) | ✅ | ✅ | ✅ (全站廣播) |
creator |
✍️ 出題創作者 | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
pro |
💎 專業版學員 | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
viewer |
🎓 備考學員 | ❌ (引導出題) | ❌ | 點數限制 | ✅ | ✅ | ❌ |
guest |
👤 訪客體驗 | ❌ (彈窗引導) | ❌ (彈窗引導) | 體驗 3 次 | 體驗模式 | ❌ (需登入) | ❌ |
subject_repository.dart):
creatorId 與 creatorName。create_subject_dialog.dart):
AWS-SAA-C03, TOEIC-990, PMP-2026)、科目全名、領域分類、章節綱要與專屬代表圖示(雲端、程式、語言、商管等)。home_screen.dart):
全部科目、⭐ 官方認證、🌐 學員自建。subject_detail_screen.dart):
question_editor_screen.dart),支援單選、複選、拖曳與詳細題解。profile_screen.dart):
flutter analyze
# 結果:No issues found! (0 warnings, 0 errors, 耗時 2.0 秒)
flutter test
# 結果:All 41 tests passed! (包含 7 項全新 Google 認證與 UGC 權限單元測試)
test/unit/google_auth_and_rbac_test.dart)預設未登入時應為訪客角色,且具備訪客限制權限
Google 帳號登入後自動取得 Google 識別碼與創作者出題權限
系統管理員角色 (admin) 應享有全站最高管控權限
登出後應清除 Google 憑證並重設為訪客身分
可以載入官方科目,且官方科目不可被非管理員修改或刪除
Google 學員建立自訂考試科目 (如 AWS 考科) 並進行 CRUD 管控
自建科目下建立專屬考題,所有權限完整貫通隔離
本計畫針對兩大核心任務擬定嚴謹、安全、合規的執行步驟:
[!IMPORTANT]
GitHub 資安防護承諾:
- 我們已檢查
.gitignore,確認所有私密檔案(包括scripts/deploy.env、service-account*.json、*.keystore、*.env等)均被嚴密排除在 Git 之外,絕對不會上傳到 GitHub。- 專案採用標準 BYOK(Bring Your Own Key)架構,程式碼內無任何寫死之 API Key 或敏感私鑰。
- Cloud Run 將部署至您的專案
openpassexam-576290(亞洲台灣區域asia-east1,服務名稱passexam-web)。
更新專案主要說明檔 README.md 與新手手冊,清楚指引任何開源社群使用者:
flutter pub get ➔ flutter run -d chrome 或 flutter run -d windows)。scripts/deploy.env.example 填入自己的 Project ID,執行 ./deploy.ps1 即可完成建置)。deploy.ps1 或執行 Google Cloud Build:
openpassexam-576290
asia-east1 (台灣)passexam-repo
passexam-web
https://passexam-web-960431413562.asia-east1.run.app)。git status 與 git diff,確認無任何機密文件被暫存。git add lib/ test/ firestore.rules README.md app_docs/
feat: add Google Identity sign-in, RBAC permissions matrix, community UGC exam creation, and Cloud Run deploy pipeline
git push origin main
flutter test 確認通過。gcloud run services describe passexam-web --region=asia-east1 --project=openpassexam-576290 確認線上運行狀態。git log -n 1 --stat 與 git status --ignored 確保未洩漏任何 deploy.env 或憑證。Google Cloud Run 正式發布與 GitHub 開源上傳驗證報告
本報告總結針對「發布到 Google Cloud Run」與「上傳到 GitHub(資安零機密外洩防護)」兩大任務所完成之成果。
openpassexam-576290 (OpenPassExam)asia-east1 (台灣彰濱資料中心)asia-east1-docker.pkg.dev/openpassexam-576290/passexam-repo/passexam-web:latest
passexam-web-00004-7ws,承接 100% 流量)即時 HTTP 驗證:
HTTP/1.1 200 OK
content-type: text/html
server: Google Frontend
(任何人以手機或電腦瀏覽器點擊該網址即可直接進入完整 Web 題庫系統)
main
d21e409
feat: integrate Google Identity sign-in, RBAC permissions matrix, community UGC exam creation, cross-platform offline AI, and automated Cloud Run deploy pipeline
scripts/deploy.env 已經被 .gitignore 徹底排除(git status --ignored 證實被標記為忽略檔案,絕無上傳)。scripts/deploy.env.example 僅提供不含機密的佔位符模板。.gcloudignore 與 .dockerignore 雙重保護,本機的暫存檔、私密檔與 Android/iOS 原生快取絕不打包進容器。已在公開首頁 README.md 增補醒目的教學章節,任何人進入 GitHub 倉庫首頁皆能依照以下 3 個步驟輕鬆跑起來:
AIzaSy... 金鑰。git clone https://github.com/alan-nanpie/OpenPassExam.git
flutter pub get ➔ flutter test (驗證 41 題) ➔ flutter run -d chrome 或 flutter run -d windows。copy scripts/deploy.env.example scripts/deploy.env 並填入自己的 Project ID。.\deploy.ps1 即自動完成雲端一鍵編譯與部署。