feat(teams): always show site-admin banner, add "normal view" toggle - #28
Merged
Conversation
…" toggle A site administrator now holds owner-level authority as the site on every team, including one they own by membership — previously an owner-by-membership admin acted as themselves with no banner. The team page always shows the site-admin banner and every action is stamped `site_admin: true`. Add "switch to normal view": an opt-out that drops the override for the session (an `X-Prism-Team-View: member` header suppressed in actorFor the same way a PAT is), letting an admin act as their own membership instead. It is session-only and resets on reload, so an admin can't get locked out of a team they don't belong to. The banner offers the switch only when the admin has a real membership to fall back to; the mirror banner offers the way back, and a non-member admin in normal view gets a friendly "switch back" prompt instead of a bare 404. Docs (en + zh) and i18n updated.
审查者指南该 PR 统一了所有团队的网站管理员权限提升行为,新增了一个不持久化的会话切换开关,通过发送成员视图请求头来恢复真实的成员权限,并更新团队 UI、翻译和文档,以解释和控制这两种模式。 Sequence diagram for switching site-admin team viewsequenceDiagram
actor Admin
participant TeamDetail
participant AdminViewStore
participant Request as API_request
participant TeamsWorker
Admin->>TeamDetail: Click Switch to normal view
TeamDetail->>AdminViewStore: setNormalView(true)
TeamDetail->>Request: invalidateQueries()
Request->>AdminViewStore: isNormalView()
Request->>TeamsWorker: Request with X-Prism-Team-View: member
TeamsWorker->>TeamsWorker: wantsNormalView()
TeamsWorker->>TeamsWorker: actorFor()
TeamsWorker-->>Request: Apply real membership authority
Request-->>TeamDetail: Team detail with my_member_role
Flow diagram for site-admin and normal team viewsflowchart TD
A[Session-authenticated site admin opens a team] --> B[Default site-admin view]
B --> C[actorFor grants site-admin authority]
C --> D[Team response sets site_admin_access and my_member_role]
D --> E[Show site-admin banner]
E --> F{Real membership exists?}
F -- Yes --> G[Switch to normal view]
G --> H[Send X-Prism-Team-View: member]
H --> I[Use real membership role and audit identity]
I --> J[Show member-view banner]
F -- No --> K[Remain in site-admin view]
J --> L[Switch to site admin view]
L --> B
I --> M{Team membership exists?}
M -- No --> N[Show switch-back prompt]
M -- Yes --> J
文件级变更
提示和命令与 Sourcery 交互
自定义你的体验访问你的控制面板以:
获取帮助Original review guide in EnglishReviewer's GuideThe PR makes site-admin elevation uniform across all teams, adds a non-persisted session toggle that sends a member-view header to revert to real membership authority, and updates the team UI, translations, and documentation to explain and control both modes. Sequence diagram for switching site-admin team viewsequenceDiagram
actor Admin
participant TeamDetail
participant AdminViewStore
participant Request as API_request
participant TeamsWorker
Admin->>TeamDetail: Click Switch to normal view
TeamDetail->>AdminViewStore: setNormalView(true)
TeamDetail->>Request: invalidateQueries()
Request->>AdminViewStore: isNormalView()
Request->>TeamsWorker: Request with X-Prism-Team-View: member
TeamsWorker->>TeamsWorker: wantsNormalView()
TeamsWorker->>TeamsWorker: actorFor()
TeamsWorker-->>Request: Apply real membership authority
Request-->>TeamDetail: Team detail with my_member_role
Flow diagram for site-admin and normal team viewsflowchart TD
A[Session-authenticated site admin opens a team] --> B[Default site-admin view]
B --> C[actorFor grants site-admin authority]
C --> D[Team response sets site_admin_access and my_member_role]
D --> E[Show site-admin banner]
E --> F{Real membership exists?}
F -- Yes --> G[Switch to normal view]
G --> H[Send X-Prism-Team-View: member]
H --> I[Use real membership role and audit identity]
I --> J[Show member-view banner]
F -- No --> K[Remain in site-admin view]
J --> L[Switch to site admin view]
L --> B
I --> M{Team membership exists?}
M -- No --> N[Show switch-back prompt]
M -- Yes --> J
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Deploying prism-docs with
|
| Latest commit: |
611770a
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://56d4baa4.siiway-prism.pages.dev |
| Branch Preview URL: | https://feat-site-admin-team-normal.siiway-prism.pages.dev |
There was a problem hiding this comment.
你好——我发现了 1 个问题
面向 AI Agent 的提示
请处理本次代码审查中的评论:
## 单条评论
### 评论 1
<location path="src/pages/teams/TeamDetail.tsx" line_range="252" />
<code_context>
- const { data, isLoading } = useQuery({
+ const { data, isLoading, isError } = useQuery({
queryKey: ["team", id],
queryFn: () => api.getTeam(id!),
enabled: !!id,
+ // In normal view a non-member admin legitimately gets a 404 — don't retry
</code_context>
<issue_to_address>
**issue (broader_impact):** React Query 的缓存键不包含 `normalView`,因此站点管理员模式和成员模式会复用同一个缓存的团队条目。切换模式会使当前查询失效,但在重新获取期间进行导航或渲染时,仍可能显示之前模式下的角色、横幅和管理控件,直到请求完成。
**触发条件:** 管理员切换视图,或在之前模式的团队响应已缓存时在不同团队之间导航。
**建议修复:** 将 `normalView` 包含在团队作用域的查询键中,或者在渲染新模式之前清除/移除相关的缓存条目。
```suggestion
queryKey: ["team", id, normalView],
```
</issue_to_address>帮助我变得更有用!请对每条评论点击 👍 或 👎,我会利用这些反馈来改进审查结果。
Original comment in English
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/pages/teams/TeamDetail.tsx" line_range="252" />
<code_context>
- const { data, isLoading } = useQuery({
+ const { data, isLoading, isError } = useQuery({
queryKey: ["team", id],
queryFn: () => api.getTeam(id!),
enabled: !!id,
+ // In normal view a non-member admin legitimately gets a 404 — don't retry
</code_context>
<issue_to_address>
**issue (broader_impact):** The React Query cache key does not include `normalView`, so the same cached team entry is reused for both site-admin and member modes. Switching modes invalidates the active query, but navigation or rendering during the refetch can still display the previous mode's role, banner, and management controls until the request completes.
**Triggers:** When an admin switches views or navigates between teams while a prior-mode team response is cached.
**Suggested fix:** Include `normalView` in the team-scoped query keys, or clear/remove the relevant cached entries before rendering the new mode.
```suggestion
queryKey: ["team", id, normalView],
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Preview deployed: https://prism-preview.siiway.workers.dev (shared preview Worker + database, so the newest PR deploy is what is live there). |
…stale UI Address Sourcery review: the team query cache entry was shared between site-admin and normal view, so toggling modes (or landing on a team cached in the other mode) briefly showed the previous mode's role, banner and management controls until the refetch completed. Include `normalView` in the query key so each mode has its own entry. Existing `["team", id]` invalidations still match by prefix, and the server stays authoritative via the request header — this was a transient display issue only.
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.
Summary
Two related changes to how site administrators access teams:
Site admins are always elevated on every team — including ones they own by membership. Previously an admin who was the owner-by-membership of a team acted as themselves (no banner, no
site_adminaudit stamp). Now the override applies uniformly: the team page always shows the "You're here as a site administrator…" banner and every action is stampedsite_admin: true."Switch to normal view" — the opt-out. A site admin can drop the override for the session and act as their own team membership instead.
How it works
worker/routes/teams.ts):actorFornow honors anX-Prism-Team-View: memberrequest header, suppressing the site-admin override exactly the way a PAT already does.getTeamAuthorityno longer special-cases owner-by-membership admins, and gainedmember_role(the role you'd hold without the override), surfaced asmy_member_roleon the team-detail response.src/store/adminView.ts, deliberately not persisted) drives the header through the singlerequest()chokepoint. A page reload returns to the default admin view, so nobody gets locked out of a team they don't belong to.TeamDetail.tsx):my_member_roleis set (a real membership to fall back to).Notes
docs/admin.md,docs/teams.md+docs/zh/counterparts); en/zh i18n keys added and parity-checked.Testing
Sourcery 摘要
确保站点管理员的团队访问始终限定在相应站点范围内,同时提供一种清晰且仅限当前会话的方式,以普通团队成员身份进行操作。
新功能:
错误修复:
增强功能:
文档:
杂项:
Original summary in English
Sourcery 总结
统一所有团队中的站点管理员访问权限,同时提供一种明确标示的、仅限当前会话的方式,让管理员以普通团队成员身份进行操作。
新功能:
错误修复:
增强功能:
文档:
杂项:
Original summary in English
Summary by Sourcery
Unify site-administrator access across all teams while providing a clearly indicated, session-only way to operate as a normal team member.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Chores: