Skip to content

Commit 1e5672f

Browse files
committed
feat(profile): 开发者选项入口 — 密钥管理 (Infisical)
和 AdminLinkIfOwnerAdmin 刻意分开:AdminLink 是 admin 专属入口,这个对所有登录 用户开放(只要访问的是自己主页)。对应的访问控制不在前端——Infisical 自己有 GitHub OAuth + project-level RBAC,非 admin 协作者登录后只看得到自己有权限的 secrets。 - 新加 DeveloperToolsIfOwner client 组件:owner 判定条件和 AdminLinkIfOwnerAdmin 保持一致(githubId 或 username 任一匹配即视为本人) - profile 页按钮栏里插在 AdminLink 前,顺序:编辑 → 密钥管理 → 管理员界面 → 排行 - data-umami-event 埋点 profile_devtools_secrets_click,方便看谁在用 - target=_blank 到 secrets.involutionhell.com(自托管 Infisical 实例)
1 parent a965ef9 commit 1e5672f

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"use client";
2+
3+
/**
4+
* 个人主页的"开发者选项"入口块。
5+
*
6+
* 和 AdminLinkIfOwnerAdmin 的区别——这里**不限 admin**,只要是主页 owner(当前登录
7+
* 用户 === 这个主页本人)就看得见。理由:
8+
* - 密钥管理 (Infisical) 是每个开发者都要用的,不是管理员专属。
9+
* Infisical 自己按 project / environment 做权限细分,进去后看不到自己没权限的 secrets。
10+
* - 以后其他"个人开发者工具"(比如 CI tokens、个人 API key 管理)也可以挂在这里
11+
*
12+
* 渲染条件:
13+
* 1. 已登录
14+
* 2. 当前登录用户就是这个主页的 owner(路人看不到)
15+
*
16+
* 注意:单独加 Link 而不是走 AdminGuard 风格,因为这是"入口按钮"不是"整页权限",
17+
* 二次校验由目标服务(Infisical)自己做。
18+
*/
19+
20+
import Link from "next/link";
21+
import { useAuth } from "@/lib/use-auth";
22+
23+
interface Props {
24+
ownerGithubId: number | null;
25+
ownerUsername: string;
26+
}
27+
28+
export function DeveloperToolsIfOwner({ ownerGithubId, ownerUsername }: Props) {
29+
const { user, status } = useAuth();
30+
if (status !== "authenticated" || !user) return null;
31+
32+
const isOwner =
33+
(ownerGithubId != null && user.githubId === ownerGithubId) ||
34+
user.username === ownerUsername;
35+
if (!isOwner) return null;
36+
37+
return (
38+
<Link
39+
href="https://secrets.involutionhell.com"
40+
target="_blank"
41+
rel="noopener noreferrer"
42+
className="font-mono text-[11px] uppercase tracking-widest px-2 py-1 border border-[var(--foreground)] text-[var(--foreground)] hover:bg-[var(--foreground)] hover:text-[var(--background)] transition-colors font-bold"
43+
data-umami-event="profile_devtools_secrets_click"
44+
title="Infisical 密钥管理(GitHub OAuth 登录,按 project 权限查看)"
45+
>
46+
密钥管理 ↗
47+
</Link>
48+
);
49+
}

app/u/[username]/page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Footer } from "@/app/components/Footer";
88
import { ProfileCard } from "./ProfileCard";
99
import { EditLinkIfOwner } from "./EditLinkIfOwner";
1010
import { AdminLinkIfOwnerAdmin } from "./AdminLinkIfOwnerAdmin";
11+
import { DeveloperToolsIfOwner } from "./DeveloperToolsIfOwner";
1112
import { ActivityHeatmap } from "./ActivityHeatmap";
1213
import { FollowButton } from "./FollowButton";
1314
import { GithubRepos, GithubReposSkeleton } from "./GithubRepos";
@@ -411,6 +412,12 @@ export default async function UserProfilePage({ params }: Param) {
411412
ownerUsername={user.username}
412413
identifier={username}
413414
/>
415+
{/* 开发者工具入口(所有本人都看得见;权限由目标服务自己管):
416+
目前只有 Infisical 密钥管理,未来可挂 CI token / API key 等 */}
417+
<DeveloperToolsIfOwner
418+
ownerGithubId={user.githubId ?? null}
419+
ownerUsername={user.username}
420+
/>
414421
{/* 管理员自见入口:只有 roles=admin 的本人访问自己主页时才渲染 */}
415422
<AdminLinkIfOwnerAdmin
416423
ownerGithubId={user.githubId ?? null}

0 commit comments

Comments
 (0)