THSRC KeyCloak 權限確認 Email 回覆處理
Trigger
User asks to process/reply to received KeyCloak permission review emails, or handle unread emails in the "KeyCloak權限確認" folder.
Folder Structure Convention
系統權限Review/
├── <系統名稱>/ (e.g., OP, BSM)
│ ├── <群組名稱>/ (e.g., GroupA, GroupB)
│ │ ├── Mail.md # Contains 收件人 and 副本
│ │ └── <群組名稱>.xlsx # Base file
│ │ └── <群組名稱>_YYYYQx.xlsx # Historical versions
Workflow: Processing Received Review Emails (Unread -> Done)
Step 1: Connect and Open Outlook
playwright-cli attach --extension
playwright-cli goto "https://outlook.cloud.microsoft/mail"
playwright-cli snapshot
- Wait for "郵件 - elliot_chen (陳俊杰) - Outlook" title.
Step 2: Find Unread Email in "KeyCloak權限確認"
- Click the folder:
playwright-cli click e<ref_of_folder>
- Parse Subject:
.*: <系統> <年度> <季度> <群組> KeyCloak權限確認
- Example:
BSM 2026 Q2 GroupB KeyCloak權限確認
- Extract: System=BSM, Year=2026, Quarter=Q2, Group=GroupB.
Step 3: Navigate to OneDrive
- Go to OneDrive:
playwright-cli goto "https://thsrc-my.sharepoint.com/my"
- Click "My files" if needed.
- Navigate folders:
- Click
系統權限Review
- Click
<系統名稱> (e.g., BSM)
- Click
<群組名稱> (e.g., GroupB)
Step 4: Copy and Rename File
- Target: Copy
<群組>.xlsx to <群組>_<年度><季度>.xlsx (e.g., GroupB_2026Q2.xlsx).
- Check if target already exists: If
<群組>_<年度><季度>.xlsx already exists in the folder:
- Check if the base
<群組>.xlsx file exists in the same folder.
- If base file DOES NOT exist: The target file was likely already created in a previous run. Skip the copy step entirely and proceed to Step 5 (Compare Files).
- If base file EXISTS: Delete the existing
<群組>_<年度><季度>.xlsx first, then proceed with the copy.
- Select the existing
<群組>_<年度><季度>.xlsx file.
- Click "Delete" or press Delete key.
- Wait for deletion to complete (verify it's gone from the list).
- Note: If deletion fails with "file is open", dismiss the notification and skip the copy — the existing file is likely fine.
- Flow (only if base
<群組>.xlsx exists):
- Select
<群組>.xlsx.
- Click "Copy to".
- Click "Copy here" (in same folder).
- OneDrive creates
<群組>1.xlsx.
- Click "Rename" -> Type
<群組>_<年度><季度>.xlsx -> Update.
Step 5: Compare Files
- Compare the new file with the previous quarter's file (e.g.,
GroupB_2026Q1.xlsx).
- Check file sizes or modification times as a heuristic.
- Record differences for the To Do task description.
Step 6: Create To Do Task
- Navigate:
playwright-cli goto "https://to-do.office.com/tasks/?app"
- Click "Keycloak" list in sidebar.
- Type task name:
<系統> <年度> <季度> <群組> KeyCloak 權限確認 - 檔案差異檢查.
- Click "Add due date" -> "Pick a date" -> Select date (usually 1 week later) -> Save.
- Press Enter or click Add.
Step 7: Mark Email as Complete and Move
- Go back to Outlook:
playwright-cli goto "https://outlook.cloud.microsoft/mail"
- Open the "KeyCloak權限確認" folder.
- Open the email.
- Click "Flag" -> "展開以查看標幟選項" -> "標示完成" (Mark as complete).
- Verify the email no longer shows as unread/incomplete.
- Move to "ISO27001" folder:
- With the email still selected/open, click the "移動" (Move) button in the toolbar.
- Select "ISO27001" from the folder list. If not visible, click "移動至資料夾" (Move to folder) to open the dialog, search for "ISO27001", select it, and click OK.
- Verify the email disappears from the "KeyCloak權限確認" folder.
Pitfalls
- Connection Stability:
playwright-cli attach --extension may drop. Re-run if disconnected.
- Snapshot Refs: Refs change after every navigation. Always call
playwright-cli snapshot after page changes.
- OneDrive Copy Naming: Copying always creates
Filename1.ext. You MUST rename it immediately.
- To Do Navigation: Direct URL
https://to-do.office.com/tasks/?app works best within the attached browser session.
- Excel Comparison: Browser cannot easily diff Excel files. Rely on file metadata or user input for diff details.
- Marking Email Done: The "Mark as complete" option is inside the Flag dropdown menu. Look for "標示完成".
- Existing Target File: If
<群組>_<年度><季度>.xlsx already exists (e.g. from a previous run), check if the base <群組>.xlsx still exists. If the base file is gone (consumed in a previous copy/rename), skip the copy step — the existing target file is already correct.
- playwright-cli type Fails with Spaces: The
playwright-cli type command may fail with "too many arguments" when typing text containing spaces or special characters. Use playwright-cli fill <ref> "<text>" instead for reliable text input.
- OneDrive Deletion "File Open" Error: Attempting to delete a file in OneDrive may fail with "It looks like someone has the file open." Dismiss the notification and proceed — the file will typically delete on next refresh or can be skipped if it's not blocking the workflow.
- OneDrive REST API Available: Within the playwright-cli attached session, you can use
fetch('/_api/v2.0/...') via playwright-cli eval to list folder children and check file existence directly. This is faster than UI navigation. Use const/let (NOT var) — eval runs in strict mode.
- Post-Move Verification: After moving to ISO27001, navigate to that folder and verify the email appears there. The KeyCloak權限確認 folder should show "資料夾中沒有項目" or the unread count should decrease.
1---2name: thsrc-keycloak-reply3description: Process received THSRC KeyCloak permission review emails. Reads unread emails, copies/renames OneDrive files, creates To-Do tasks, marks emails complete, and moves them to ISO27001 folder.4---56# THSRC KeyCloak 權限確認 Email 回覆處理78## Trigger9User asks to process/reply to received KeyCloak permission review emails, or handle unread emails in the "KeyCloak權限確認" folder.1011## Folder Structure Convention12```13系統權限Review/14├── <系統名稱>/ (e.g., OP, BSM)15│ ├── <群組名稱>/ (e.g., GroupA, GroupB)16│ │ ├── Mail.md # Contains 收件人 and 副本17│ │ └── <群組名稱>.xlsx # Base file18│ │ └── <群組名稱>_YYYYQx.xlsx # Historical versions19```2021## Workflow: Processing Received Review Emails (Unread -> Done)2223### Step 1: Connect and Open Outlook24```bash25playwright-cli attach --extension26playwright-cli goto "https://outlook.cloud.microsoft/mail"27playwright-cli snapshot28```29- Wait for "郵件 - elliot_chen (陳俊杰) - Outlook" title.3031### Step 2: Find Unread Email in "KeyCloak權限確認"32- Click the folder: `playwright-cli click e<ref_of_folder>`33- Parse Subject: `.*: <系統> <年度> <季度> <群組> KeyCloak權限確認`34 - Example: `BSM 2026 Q2 GroupB KeyCloak權限確認`35 - Extract: System=BSM, Year=2026, Quarter=Q2, Group=GroupB.3637### Step 3: Navigate to OneDrive38- Go to OneDrive: `playwright-cli goto "https://thsrc-my.sharepoint.com/my"`39- Click "My files" if needed.40- Navigate folders:41 1. Click `系統權限Review`42 2. Click `<系統名稱>` (e.g., BSM)43 3. Click `<群組名稱>` (e.g., GroupB)4445### Step 4: Copy and Rename File46- Target: Copy `<群組>.xlsx` to `<群組>_<年度><季度>.xlsx` (e.g., `GroupB_2026Q2.xlsx`).47- **Check if target already exists**: If `<群組>_<年度><季度>.xlsx` already exists in the folder:48 - Check if the base `<群組>.xlsx` file exists in the same folder.49 - If base file DOES NOT exist: The target file was likely already created in a previous run. Skip the copy step entirely and proceed to Step 5 (Compare Files).50 - If base file EXISTS: Delete the existing `<群組>_<年度><季度>.xlsx` first, then proceed with the copy.51 - Select the existing `<群組>_<年度><季度>.xlsx` file.52 - Click "Delete" or press Delete key.53 - Wait for deletion to complete (verify it's gone from the list).54 - **Note**: If deletion fails with "file is open", dismiss the notification and skip the copy — the existing file is likely fine.55- Flow (only if base `<群組>.xlsx` exists):56 1. Select `<群組>.xlsx`.57 2. Click "Copy to".58 3. Click "Copy here" (in same folder).59 4. OneDrive creates `<群組>1.xlsx`.60 5. Click "Rename" -> Type `<群組>_<年度><季度>.xlsx` -> Update.6162### Step 5: Compare Files63- Compare the new file with the previous quarter's file (e.g., `GroupB_2026Q1.xlsx`).64- Check file sizes or modification times as a heuristic.65- Record differences for the To Do task description.6667### Step 6: Create To Do Task68- Navigate: `playwright-cli goto "https://to-do.office.com/tasks/?app"`69- Click "Keycloak" list in sidebar.70- Type task name: `<系統> <年度> <季度> <群組> KeyCloak 權限確認 - 檔案差異檢查`.71- Click "Add due date" -> "Pick a date" -> Select date (usually 1 week later) -> Save.72- Press Enter or click Add.7374### Step 7: Mark Email as Complete and Move75- Go back to Outlook: `playwright-cli goto "https://outlook.cloud.microsoft/mail"`76- Open the "KeyCloak權限確認" folder.77- Open the email.78- Click "Flag" -> "展開以查看標幟選項" -> "標示完成" (Mark as complete).79- Verify the email no longer shows as unread/incomplete.80- **Move to "ISO27001" folder**:81 1. With the email still selected/open, click the **"移動" (Move)** button in the toolbar.82 2. Select **"ISO27001"** from the folder list. If not visible, click "移動至資料夾" (Move to folder) to open the dialog, search for "ISO27001", select it, and click OK.83 3. Verify the email disappears from the "KeyCloak權限確認" folder.8485## Pitfalls861. **Connection Stability**: `playwright-cli attach --extension` may drop. Re-run if disconnected.872. **Snapshot Refs**: Refs change after every navigation. Always call `playwright-cli snapshot` after page changes.883. **OneDrive Copy Naming**: Copying always creates `Filename1.ext`. You MUST rename it immediately.894. **To Do Navigation**: Direct URL `https://to-do.office.com/tasks/?app` works best within the attached browser session.905. **Excel Comparison**: Browser cannot easily diff Excel files. Rely on file metadata or user input for diff details.916. **Marking Email Done**: The "Mark as complete" option is inside the Flag dropdown menu. Look for "標示完成".927. **Existing Target File**: If `<群組>_<年度><季度>.xlsx` already exists (e.g. from a previous run), check if the base `<群組>.xlsx` still exists. If the base file is gone (consumed in a previous copy/rename), skip the copy step — the existing target file is already correct.938. **playwright-cli type Fails with Spaces**: The `playwright-cli type` command may fail with "too many arguments" when typing text containing spaces or special characters. Use `playwright-cli fill <ref> "<text>"` instead for reliable text input.949. **OneDrive Deletion "File Open" Error**: Attempting to delete a file in OneDrive may fail with "It looks like someone has the file open." Dismiss the notification and proceed — the file will typically delete on next refresh or can be skipped if it's not blocking the workflow.9510. **OneDrive REST API Available**: Within the playwright-cli attached session, you can use `fetch('/_api/v2.0/...')` via `playwright-cli eval` to list folder children and check file existence directly. This is faster than UI navigation. Use `const`/`let` (NOT `var`) — eval runs in strict mode.9611. **Post-Move Verification**: After moving to ISO27001, navigate to that folder and verify the email appears there. The KeyCloak權限確認 folder should show "資料夾中沒有項目" or the unread count should decrease.