(action, roleName)
| 641 | } |
| 642 | |
| 643 | async function updateRole(action, roleName) { |
| 644 | if (!roleName) throw new Error("请输入角色名。"); |
| 645 | setStatus(`${ROLE_ACTION_LABELS[action] || "更新"}角色 ${roleName}`, true); |
| 646 | const data = await api("/api/roles", { |
| 647 | method: "POST", |
| 648 | body: JSON.stringify({ action, role_name: roleName }), |
| 649 | }); |
| 650 | state.roles = data.roles || []; |
| 651 | renderRoles(state.roles); |
| 652 | const active = state.roles.find((role) => role.is_current); |
| 653 | const nextUserId = active?.user_id || state.userId; |
| 654 | await loadUsers(nextUserId); |
| 655 | if (active && active.user_id) { |
| 656 | setActiveUser(active.user_id); |
| 657 | } |
| 658 | await Promise.allSettled([refreshDashboard(), refreshWikiStats(), refreshProfile(), refreshMustRead()]); |
| 659 | setStatus(ROLE_ACTION_LABELS[action] ? `角色已${ROLE_ACTION_LABELS[action]}` : "角色已更新"); |
| 660 | } |
| 661 | |
| 662 | async function syncRoleForUser(userId) { |
| 663 | const role = state.roles.find((item) => item.user_id === userId); |
no test coverage detected