feat(hub): manage service trust and company grants
This commit is contained in:
@@ -39,6 +39,7 @@ import {
|
||||
updateAdminService,
|
||||
updateAdminSettings,
|
||||
updateAdminUserProfile,
|
||||
upsertAdminGrant,
|
||||
type ControlPlaneMutationResult,
|
||||
type TaskManagerWorkspaceMemberRole,
|
||||
type TaskManagerWorkspaceSummary,
|
||||
@@ -68,8 +69,10 @@ import { subscribeToNodeDCLogoutEvents } from "../shared/session/sessionSync";
|
||||
import { loadPersistedLauncherData } from "../shared/api/storageApi";
|
||||
import type {
|
||||
AccessAssignmentValue,
|
||||
ClientGrantAssignmentValue,
|
||||
CreateUserCommand,
|
||||
EnsureTaskManagerProjectMemberCommand,
|
||||
SetClientServiceGrantCommand,
|
||||
SetServiceModuleEntitlementCommand,
|
||||
SetUserServiceAccessCommand,
|
||||
} from "../widgets/admin-overlay/AdminOverlay";
|
||||
@@ -110,6 +113,7 @@ export function LauncherApp() {
|
||||
const [runtimeReady, setRuntimeReady] = useState(false);
|
||||
const [profileSettingsOpen, setProfileSettingsOpen] = useState(false);
|
||||
const [pendingAccessAssignments, setPendingAccessAssignments] = useState<Record<string, AccessAssignmentValue>>({});
|
||||
const [pendingClientGrantAssignments, setPendingClientGrantAssignments] = useState<Record<string, ClientGrantAssignmentValue>>({});
|
||||
const [pendingServiceModuleEntitlements, setPendingServiceModuleEntitlements] = useState<Record<string, boolean>>({});
|
||||
const [pendingTaskManagerMemberships, setPendingTaskManagerMemberships] = useState<Record<string, boolean>>({});
|
||||
const [pendingTaskManagerProjectMemberships, setPendingTaskManagerProjectMemberships] = useState<Record<string, boolean>>({});
|
||||
@@ -580,6 +584,39 @@ export function LauncherApp() {
|
||||
});
|
||||
}
|
||||
|
||||
function handleSetClientServiceGrant({ clientId, serviceId, value }: SetClientServiceGrantCommand) {
|
||||
const assignmentKey = `${clientId}:${serviceId}`;
|
||||
|
||||
if (pendingClientGrantAssignments[assignmentKey] !== undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const existingGrant = data.grants.find((grant) =>
|
||||
grant.targetType === "client"
|
||||
&& grant.targetId === clientId
|
||||
&& grant.serviceId === serviceId);
|
||||
const appRole = value === "unset" ? (existingGrant?.appRole ?? "member") : value;
|
||||
const status = value === "unset" ? "disabled" : "active";
|
||||
|
||||
setPendingClientGrantAssignments((current) => ({ ...current, [assignmentKey]: value }));
|
||||
upsertAdminGrant(
|
||||
{ serviceId, targetType: "client", targetId: clientId, appRole, status },
|
||||
`launcher-client-grant:${clientId}:${serviceId}:${crypto.randomUUID()}`
|
||||
)
|
||||
.then((result) => {
|
||||
setData(syncLauncherServiceLinks(result.data));
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
console.warn(error instanceof Error ? error.message : "Не удалось обновить доступ контура");
|
||||
})
|
||||
.finally(() => {
|
||||
setPendingClientGrantAssignments((current) => {
|
||||
const { [assignmentKey]: _completed, ...rest } = current;
|
||||
return rest;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function handleSetServiceModuleEntitlement(command: SetServiceModuleEntitlementCommand) {
|
||||
const entitlementKey = `${command.userId}:${command.serviceId}:${command.moduleId}`;
|
||||
|
||||
@@ -992,6 +1029,7 @@ export function LauncherApp() {
|
||||
setAdminOpen(false);
|
||||
}}
|
||||
onSetUserServiceAccess={handleSetUserServiceAccess}
|
||||
onSetClientServiceGrant={handleSetClientServiceGrant}
|
||||
onCreateInvite={handleCreateInvite}
|
||||
onUpdateInvite={handleUpdateInvite}
|
||||
onDeleteInvite={handleDeleteInvite}
|
||||
@@ -1012,6 +1050,7 @@ export function LauncherApp() {
|
||||
onUpdateMembership={handleUpdateMembership}
|
||||
onDeleteMembership={handleDeleteMembership}
|
||||
pendingAccessAssignments={pendingAccessAssignments}
|
||||
pendingClientGrantAssignments={pendingClientGrantAssignments}
|
||||
pendingServiceModuleEntitlements={pendingServiceModuleEntitlements}
|
||||
onCreateGroup={handleCreateGroup}
|
||||
onUpdateGroup={handleUpdateGroup}
|
||||
|
||||
@@ -3324,6 +3324,36 @@ code {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.service-integration-heading {
|
||||
margin-top: 0.2rem;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.08);
|
||||
padding-top: 0.9rem;
|
||||
}
|
||||
|
||||
.service-integration-heading strong {
|
||||
color: var(--text-primary);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.service-content-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.65rem;
|
||||
min-height: 2.7rem;
|
||||
border-radius: 1rem;
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
padding: 0.7rem 0.85rem;
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.78rem;
|
||||
font-weight: 750;
|
||||
}
|
||||
|
||||
.service-content-toggle input {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.service-content-field span {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -3640,6 +3670,42 @@ code {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.client-service-grants {
|
||||
grid-column: 1 / -1;
|
||||
min-width: 0;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.client-service-grants__grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
|
||||
gap: 0.55rem;
|
||||
}
|
||||
|
||||
.client-service-grant {
|
||||
display: grid;
|
||||
width: 100%;
|
||||
min-height: 3.5rem;
|
||||
align-content: center;
|
||||
gap: 0.18rem;
|
||||
border: 0;
|
||||
border-radius: 1rem;
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
color: var(--text-primary);
|
||||
padding: 0.65rem 0.8rem;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.client-service-grant:hover,
|
||||
.client-service-grant[aria-expanded="true"] {
|
||||
background: rgba(255, 255, 255, 0.11);
|
||||
}
|
||||
|
||||
.client-service-grant span {
|
||||
color: var(--text-muted);
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
|
||||
.access-tabs-card {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const overlaySource = readFileSync(resolve(process.cwd(), "src/widgets/admin-overlay/AdminOverlay.tsx"), "utf8");
|
||||
const appSource = readFileSync(resolve(process.cwd(), "src/app/LauncherApp.tsx"), "utf8");
|
||||
|
||||
describe("generic service control-plane administration", () => {
|
||||
it("edits every Launcher handoff identity through the generic service editor", () => {
|
||||
for (const marker of [
|
||||
"Authentik application slug",
|
||||
"Authentik group",
|
||||
"Handoff path",
|
||||
"Login sync URL",
|
||||
"Logout URL",
|
||||
"isAvailableForAllNewClients",
|
||||
]) {
|
||||
expect(overlaySource).toContain(marker);
|
||||
}
|
||||
|
||||
expect(overlaySource).not.toContain("DEVICE CORE</");
|
||||
expect(overlaySource).not.toContain("device-core</");
|
||||
});
|
||||
|
||||
it("manages a company-wide grant separately from personal access cells", () => {
|
||||
expect(overlaySource).toContain("Доступ контура · {matrix.client.name}");
|
||||
expect(overlaySource).toContain("onSetClientServiceGrant");
|
||||
expect(appSource).toContain("upsertAdminGrant(");
|
||||
expect(appSource).toContain('targetType: "client"');
|
||||
expect(appSource).toContain('value === "unset" ? "disabled" : "active"');
|
||||
expect(appSource).toContain("crypto.randomUUID()");
|
||||
});
|
||||
});
|
||||
@@ -117,6 +117,14 @@ export interface SetUserServiceAccessCommand {
|
||||
value: AccessAssignmentValue;
|
||||
}
|
||||
|
||||
export type ClientGrantAssignmentValue = Exclude<AccessAssignmentValue, "deny">;
|
||||
|
||||
export interface SetClientServiceGrantCommand {
|
||||
clientId: string;
|
||||
serviceId: string;
|
||||
value: ClientGrantAssignmentValue;
|
||||
}
|
||||
|
||||
export interface SetServiceModuleEntitlementCommand {
|
||||
clientId: string;
|
||||
userId: string;
|
||||
@@ -208,6 +216,7 @@ export function AdminOverlay({
|
||||
activeClientId,
|
||||
onClose,
|
||||
onSetUserServiceAccess,
|
||||
onSetClientServiceGrant,
|
||||
onCreateInvite,
|
||||
onUpdateInvite,
|
||||
onDeleteInvite,
|
||||
@@ -228,6 +237,7 @@ export function AdminOverlay({
|
||||
onUpdateMembership,
|
||||
onDeleteMembership,
|
||||
pendingAccessAssignments,
|
||||
pendingClientGrantAssignments,
|
||||
pendingServiceModuleEntitlements,
|
||||
onCreateGroup,
|
||||
onUpdateGroup,
|
||||
@@ -253,6 +263,7 @@ export function AdminOverlay({
|
||||
activeClientId: string;
|
||||
onClose: () => void;
|
||||
onSetUserServiceAccess: (command: SetUserServiceAccessCommand) => void;
|
||||
onSetClientServiceGrant: (command: SetClientServiceGrantCommand) => void;
|
||||
onCreateInvite: (invite: Pick<Invite, "clientId" | "email" | "role">) => void;
|
||||
onUpdateInvite: (inviteId: string, patch: Partial<Invite>) => void;
|
||||
onDeleteInvite: (inviteId: string) => void;
|
||||
@@ -285,6 +296,7 @@ export function AdminOverlay({
|
||||
onUpdateMembership: (membershipId: string, patch: Partial<ClientMembership>) => void;
|
||||
onDeleteMembership: (membershipId: string) => void;
|
||||
pendingAccessAssignments: Record<string, AccessAssignmentValue>;
|
||||
pendingClientGrantAssignments: Record<string, ClientGrantAssignmentValue>;
|
||||
pendingServiceModuleEntitlements: Record<string, boolean>;
|
||||
onCreateGroup: (clientId: string) => void;
|
||||
onUpdateGroup: (groupId: string, patch: Partial<ClientGroup>) => void;
|
||||
@@ -601,7 +613,9 @@ export function AdminOverlay({
|
||||
selectedCell={selectedAccessCell}
|
||||
onSelectCell={(cell) => setSelectedCell({ userId: cell.userId, serviceId: cell.serviceId })}
|
||||
onSetUserServiceAccess={onSetUserServiceAccess}
|
||||
onSetClientServiceGrant={onSetClientServiceGrant}
|
||||
pendingAccessAssignments={pendingAccessAssignments}
|
||||
pendingClientGrantAssignments={pendingClientGrantAssignments}
|
||||
pendingServiceModuleEntitlements={pendingServiceModuleEntitlements}
|
||||
onUpdateUser={onUpdateUser}
|
||||
onUpdateMembership={onUpdateMembership}
|
||||
@@ -1509,6 +1523,13 @@ const accessAssignmentOptions: Array<NodeDcSelectOption<AccessAssignmentValue>>
|
||||
{ value: "deny", label: "Заблокирован", description: "Запрет доступа", tone: "red" },
|
||||
];
|
||||
|
||||
const clientGrantAssignmentOptions: Array<NodeDcSelectOption<ClientGrantAssignmentValue>> = [
|
||||
{ value: "unset", label: "—", description: "Грант контура выключен" },
|
||||
{ value: "viewer", label: "Гость", description: "Просмотр для контура", tone: "green" },
|
||||
{ value: "member", label: "Участник", description: "Рабочий доступ для контура", tone: "green" },
|
||||
{ value: "admin", label: "Админ", description: "Администрирование в контуре", tone: "green" },
|
||||
];
|
||||
|
||||
const operationalCoreAccessAssignmentOptions: Array<NodeDcSelectOption<AccessAssignmentValue>> = [
|
||||
{ value: "unset", label: "—", description: "Не назначен" },
|
||||
{ value: "viewer", label: "Гость", description: "Просмотр", tone: "green" },
|
||||
@@ -2253,6 +2274,12 @@ function ServiceContentModal({
|
||||
fullDescription: currentDraft.fullDescription,
|
||||
url: currentDraft.url,
|
||||
launchUrl: currentDraft.launchUrl,
|
||||
logoutUrl: currentDraft.logoutUrl,
|
||||
loginSyncUrl: currentDraft.loginSyncUrl,
|
||||
authentikApplicationSlug: currentDraft.authentikApplicationSlug,
|
||||
authentikGroupName: currentDraft.authentikGroupName,
|
||||
authHandoffPath: currentDraft.authHandoffPath,
|
||||
isAvailableForAllNewClients: currentDraft.isAvailableForAllNewClients,
|
||||
coverImageUrl: currentDraft.coverImageUrl,
|
||||
coverMediaKind: currentDraft.coverMediaKind,
|
||||
coverMediaSource: currentDraft.coverMediaSource,
|
||||
@@ -2315,6 +2342,63 @@ function ServiceContentModal({
|
||||
/>
|
||||
</label>
|
||||
|
||||
<div className="service-content-field service-content-field--wide service-integration-heading">
|
||||
<strong>Интеграция и SSO</strong>
|
||||
<span>Общие параметры Launcher handoff и синхронизации доступа для любого сервиса.</span>
|
||||
</div>
|
||||
|
||||
<label className="service-content-field">
|
||||
<span>Authentik application slug</span>
|
||||
<input
|
||||
value={draft.authentikApplicationSlug ?? ""}
|
||||
onChange={(event) => update("authentikApplicationSlug", event.target.value || null)}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="service-content-field">
|
||||
<span>Authentik group</span>
|
||||
<input
|
||||
value={draft.authentikGroupName ?? ""}
|
||||
onChange={(event) => update("authentikGroupName", event.target.value || null)}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="service-content-field">
|
||||
<span>Handoff path</span>
|
||||
<input
|
||||
value={draft.authHandoffPath ?? ""}
|
||||
placeholder="/auth/nodedc/handoff"
|
||||
onChange={(event) => update("authHandoffPath", event.target.value || null)}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="service-content-field">
|
||||
<span>Login sync URL</span>
|
||||
<input
|
||||
value={draft.loginSyncUrl ?? ""}
|
||||
placeholder="https://service.example/auth/login-sync"
|
||||
onChange={(event) => update("loginSyncUrl", event.target.value || null)}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="service-content-field service-content-field--wide">
|
||||
<span>Logout URL</span>
|
||||
<input
|
||||
value={draft.logoutUrl ?? ""}
|
||||
placeholder="https://service.example/auth/logout"
|
||||
onChange={(event) => update("logoutUrl", event.target.value || null)}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="service-content-toggle service-content-field--wide">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={Boolean(draft.isAvailableForAllNewClients)}
|
||||
onChange={(event) => update("isAvailableForAllNewClients", event.target.checked)}
|
||||
/>
|
||||
<span>Автоматически выдавать новым контурам</span>
|
||||
</label>
|
||||
|
||||
<MediaSourceField
|
||||
label="Карточка"
|
||||
icon={<ImageIcon size={14} />}
|
||||
@@ -3112,7 +3196,9 @@ function AccessSection({
|
||||
selectedCell,
|
||||
onSelectCell,
|
||||
onSetUserServiceAccess,
|
||||
onSetClientServiceGrant,
|
||||
pendingAccessAssignments,
|
||||
pendingClientGrantAssignments,
|
||||
pendingServiceModuleEntitlements,
|
||||
onUpdateUser,
|
||||
onUpdateMembership,
|
||||
@@ -3129,7 +3215,9 @@ function AccessSection({
|
||||
selectedCell: AccessMatrixCell | null;
|
||||
onSelectCell: (cell: AccessMatrixCell) => void;
|
||||
onSetUserServiceAccess: (command: SetUserServiceAccessCommand) => void;
|
||||
onSetClientServiceGrant: (command: SetClientServiceGrantCommand) => void;
|
||||
pendingAccessAssignments: Record<string, AccessAssignmentValue>;
|
||||
pendingClientGrantAssignments: Record<string, ClientGrantAssignmentValue>;
|
||||
pendingServiceModuleEntitlements: Record<string, boolean>;
|
||||
onUpdateUser: (userId: string, patch: Partial<LauncherUser>) => void;
|
||||
onUpdateMembership: (membershipId: string, patch: Partial<ClientMembership>) => void;
|
||||
@@ -3168,6 +3256,55 @@ function AccessSection({
|
||||
|
||||
return (
|
||||
<div className={cn("access-layout", isPublicPoolContext && "access-layout--single")}>
|
||||
{!isPublicPoolContext ? (
|
||||
<GlassSurface className="client-service-grants">
|
||||
<div className="table-toolbar">
|
||||
<div>
|
||||
<h3>Доступ контура · {matrix.client.name}</h3>
|
||||
<span className="muted-text">Базовая роль наследуется участниками компании и может быть уточнена персонально.</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="client-service-grants__grid">
|
||||
{matrix.services.map((service) => {
|
||||
const pendingKey = clientGrantAssignmentKey(matrix.client.id, service.id);
|
||||
const pendingValue = pendingClientGrantAssignments[pendingKey];
|
||||
const value = pendingValue ?? clientGrantAssignmentValue(data, matrix.client.id, service.id);
|
||||
const options = isEngineServiceForAccessControl(service) || isOperationalCoreService(service)
|
||||
? clientGrantAssignmentOptions.filter((option) => option.value !== "admin")
|
||||
: clientGrantAssignmentOptions;
|
||||
|
||||
return (
|
||||
<NodeDcSelect
|
||||
key={service.id}
|
||||
value={value}
|
||||
options={options}
|
||||
label={`Доступ контура ${matrix.client.name} / ${service.title}`}
|
||||
minMenuWidth={220}
|
||||
disabled={pendingValue !== undefined}
|
||||
onChange={(nextValue) => onSetClientServiceGrant({
|
||||
clientId: matrix.client.id,
|
||||
serviceId: service.id,
|
||||
value: nextValue,
|
||||
})}
|
||||
trigger={({ open, toggle, setTriggerRef }) => (
|
||||
<button
|
||||
ref={setTriggerRef}
|
||||
className="client-service-grant"
|
||||
type="button"
|
||||
aria-expanded={open}
|
||||
aria-busy={pendingValue !== undefined}
|
||||
onClick={toggle}
|
||||
>
|
||||
<strong>{service.title}</strong>
|
||||
<span>{pendingValue !== undefined ? "Сохраняем..." : clientGrantAssignmentLabel(value)}</span>
|
||||
</button>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</GlassSurface>
|
||||
) : null}
|
||||
<GlassSurface className="access-matrix">
|
||||
<div className="table-toolbar table-toolbar--access-matrix">
|
||||
<h3>Матрица доступа · {matrix.client.name}</h3>
|
||||
@@ -5348,6 +5485,27 @@ function accessAssignmentLabel(value: AccessAssignmentValue): string {
|
||||
return accessAssignmentOptions.find((option) => option.value === value)?.label ?? value;
|
||||
}
|
||||
|
||||
function clientGrantAssignmentKey(clientId: string, serviceId: string): string {
|
||||
return `${clientId}:${serviceId}`;
|
||||
}
|
||||
|
||||
function clientGrantAssignmentValue(data: LauncherData, clientId: string, serviceId: string): ClientGrantAssignmentValue {
|
||||
const grant = data.grants.find((candidate) =>
|
||||
candidate.targetType === "client"
|
||||
&& candidate.targetId === clientId
|
||||
&& candidate.serviceId === serviceId);
|
||||
|
||||
if (!grant || grant.status !== "active") return "unset";
|
||||
if (grant.appRole === "owner") return "admin";
|
||||
return grant.appRole === "viewer" || grant.appRole === "member" || grant.appRole === "admin"
|
||||
? grant.appRole
|
||||
: "unset";
|
||||
}
|
||||
|
||||
function clientGrantAssignmentLabel(value: ClientGrantAssignmentValue): string {
|
||||
return clientGrantAssignmentOptions.find((option) => option.value === value)?.label ?? value;
|
||||
}
|
||||
|
||||
function accessAssignmentRoleLabel(role?: ServiceAppRole | null): string {
|
||||
if (!role) return "—";
|
||||
return accessAssignmentLabel(role === "owner" ? "admin" : role);
|
||||
|
||||
Reference in New Issue
Block a user