Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

improve: use scoped users, fix underscore display

Tre Dubrava1910721ca919
diff --git a/frontend/src/hooks/api/auditLogs/useAuditLogActorSuggestions.ts b/frontend/src/hooks/api/auditLogs/useAuditLogActorSuggestions.ts
index f14f4b6517..0fc0e0fc92 100644
--- a/frontend/src/hooks/api/auditLogs/useAuditLogActorSuggestions.ts
+++ b/frontend/src/hooks/api/auditLogs/useAuditLogActorSuggestions.ts
@@ -1,10 +1,14 @@
import { useMemo } from "react";
import { useQuery } from "@tanstack/react-query";
+import { apiRequest } from "@app/config/request";
import { useOrganization } from "@app/context";
import { orgIdentityQuery } from "@app/hooks/api/orgIdentity/queries";
+import { projectIdentityQuery } from "@app/hooks/api/projectIdentity/queries";
+import { projectKeys } from "@app/hooks/api/projects/query-keys";
import { fetchOrgUsers } from "@app/hooks/api/users/queries";
import { userKeys } from "@app/hooks/api/users/query-keys";
+import { TWorkspaceUser } from "@app/hooks/api/users/types";
import { ActorType } from "./enums";
@@ -15,41 +19,87 @@ type UseAuditLogActorSuggestionsResult = {
isLoading: boolean;
};
+const useScopedUsers = (orgId: string, projectId?: string, enabled = false) => {
+ const { data: orgUsers = [], isLoading: isLoadingOrg } = useQuery({
+ queryKey: userKeys.getOrgUsers(orgId),
+ queryFn: () => fetchOrgUsers(orgId),
+ enabled: enabled && !!orgId && !projectId
+ });
+
+ const { data: projectUsers = [], isLoading: isLoadingProject } = useQuery({
+ queryKey: projectKeys.getProjectUsers(projectId ?? ""),
+ queryFn: async () => {
+ const { data } = await apiRequest.get<{ users: TWorkspaceUser[] }>(
+ `/api/v1/projects/${projectId}/users`
+ );
+ return data.users;
+ },
+ enabled: enabled && !!projectId
+ });
+
+ return {
+ users: projectId ? projectUsers : orgUsers,
+ isLoading: isLoadingOrg || isLoadingProject
+ };
+};
+
+const useScopedIdentities = (projectId?: string, enabled = false) => {
+ const { data: orgIdentities, isLoading: isLoadingOrg } = useQuery({
+ ...orgIdentityQuery.list({ limit: 100 }),
+ enabled: enabled && !projectId
+ });
+
+ const { data: projectIdentities, isLoading: isLoadingProject } = useQuery({
+ ...projectIdentityQuery.list({ projectId: projectId ?? "", limit: 100 }),
+ enabled: enabled && !!projectId
+ });
+
+ return {
+ identities: projectId
+ ? (projectIdentities?.identities ?? [])
+ : (orgIdentities?.identities ?? []),
+ isLoading: isLoadingOrg || isLoadingProject
+ };
+};
+
export const useAuditLogActorSuggestions = (
actorType?: ActorType,
- enabled = false
+ enabled = false,
+ projectId?: string
): UseAuditLogActorSuggestionsResult => {
const { currentOrg } = useOrganization();
const orgId = currentOrg?.id ?? "";
- const { data: orgUsers = [], isLoading: isLoadingUsers } = useQuery({
- queryKey: userKeys.getOrgUsers(orgId),
- queryFn: () => fetchOrgUsers(orgId),
- enabled: enabled && Boolean(orgId) && (!actorType || actorType === ActorType.USER)
- });
+ const isUserType = !actorType || actorType === ActorType.USER;
+ const isIdentityType = actorType === ActorType.IDENTITY;
- const { data: orgIdentities, isLoading: isLoadingIdentities } = useQuery({
- ...orgIdentityQuery.list({ limit: 100 }),
- enabled: enabled && actorType === ActorType.IDENTITY
- });
+ const { users, isLoading: isLoadingUsers } = useScopedUsers(
+ orgId,
+ projectId,
+ enabled && isUserType
+ );
+ const { identities, isLoading: isLoadingIdentities } = useScopedIdentities(
+ projectId,
+ enabled && isIdentityType
+ );
const suggestions = useMemo<ActorSuggestion[]>(() => {
switch (actorType) {
case ActorType.IDENTITY:
- return (orgIdentities?.identities ?? []).map((identity) => ({
+ return identities.map((identity) => ({
label: `${identity.name} (${identity.id})`,
value: identity.id
}));
case undefined:
case ActorType.USER:
- return orgUsers.map((orgUser) => ({
- label: `${orgUser.user.email || orgUser.user.username} (${orgUser.user.id})`,
- value: orgUser.user.id
+ return users.map((u) => ({
+ label: `${u.user.email || u.user.username} (${u.user.id})`,
+ value: u.user.id
}));
default:
return [];
}
- }, [actorType, orgUsers, orgIdentities]);
+ }, [actorType, users, identities]);
- return { suggestions, isLoading: isLoadingIdentities || isLoadingUsers };
+ return { suggestions, isLoading: isLoadingUsers || isLoadingIdentities };
};
diff --git a/frontend/src/pages/organization/AuditLogsPage/components/AuditSearchFilter.tsx b/frontend/src/pages/organization/AuditLogsPage/components/AuditSearchFilter.tsx
index 8841e25a81..3dc95f4227 100644
--- a/frontend/src/pages/organization/AuditLogsPage/components/AuditSearchFilter.tsx
+++ b/frontend/src/pages/organization/AuditLogsPage/components/AuditSearchFilter.tsx
@@ -38,7 +38,6 @@ const FILTER_PROPERTIES: FilterProperty[] = [
},
{
key: "actor_id",
- displayLabel: "actor id",
hints: "filter by specific user or identity ID"
},
{
@@ -51,8 +50,8 @@ const FILTER_PROPERTIES: FilterProperty[] = [
},
{ key: "project", hints: "project ID" },
{ key: "environment", hints: "e.g. production, staging, dev" },
- { key: "secret_path", displayLabel: "secret path", hints: "e.g. /, /app, /services" },
- { key: "secret_key", displayLabel: "secret key", hints: "e.g. DATABASE_URL, API_KEY" }
+ { key: "secret_path", hints: "e.g. /, /app, /services" },
+ { key: "secret_key", hints: "e.g. DATABASE_URL, API_KEY" }
];
const PROJECT_DEPENDENT_KEYS = new Set(["environment", "secret_path", "secret_key"]);
@@ -67,9 +66,15 @@ type Props = {
filters: AppliedFilter[];
onFiltersChange: (filters: AppliedFilter[]) => void;
hasProjectContext?: boolean;
+ projectId?: string;
};
-export const AuditSearchFilter = ({ filters, onFiltersChange, hasProjectContext }: Props) => {
+export const AuditSearchFilter = ({
+ filters,
+ onFiltersChange,
+ hasProjectContext,
+ projectId
+}: Props) => {
const currentActorType = filters.find((f) => f.property === "actor")?.value as
| ActorType
| undefined;
@@ -94,7 +99,8 @@ export const AuditSearchFilter = ({ filters, onFiltersChange, hasProjectContext
const hasActorId = propertyKey === "actor_id" || filters.some((f) => f.property === "actor_id");
const { suggestions: actorIdSuggestions } = useAuditLogActorSuggestions(
currentActorType,
- hasActorId
+ hasActorId,
+ projectId
);
const valueSuggestions = useMemo(() => {
diff --git a/frontend/src/pages/organization/AuditLogsPage/components/LogsSection.tsx b/frontend/src/pages/organization/AuditLogsPage/components/LogsSection.tsx
index 72e1b0a40a..a1583dba3d 100644
--- a/frontend/src/pages/organization/AuditLogsPage/components/LogsSection.tsx
+++ b/frontend/src/pages/organization/AuditLogsPage/components/LogsSection.tsx
@@ -112,6 +112,7 @@ const LogsSectionComponent = ({
filters={searchFilters}
onFiltersChange={setSearchFilters}
hasProjectContext={Boolean(project)}
+ projectId={project?.id}
/>
{searchFilters.length > 0 && (
<p className="mt-2 text-xs text-mineshaft-400">