Skip to content

Commit

Permalink
use profile_id instead of username
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme committed Sep 17, 2024
1 parent f17bad8 commit 32c647a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function InvestigationNotes({ user }: Props) {
const theme = useTheme();
const { investigation, addNote, isAddingNote } = useInvestigation();
const { data: userProfiles, isLoading: isLoadingUserProfiles } = useFetchUserProfiles({
profileIds: new Set(investigation?.notes.map((note) => note.createdBy) ?? []),
profileIds: new Set(investigation?.notes.map((note) => note.createdBy)),
});

const [noteInput, setNoteInput] = useState('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
import {
Criteria,
EuiAvatar,
EuiBadge,
EuiBasicTable,
EuiBasicTableColumn,
Expand All @@ -14,6 +15,7 @@ import {
EuiLink,
EuiLoadingSpinner,
EuiText,
EuiToolTip,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { InvestigationResponse } from '@kbn/investigation-shared/src/rest_specs/investigation';
Expand All @@ -27,6 +29,7 @@ import { InvestigationListActions } from './investigation_list_actions';
import { InvestigationStats } from './investigation_stats';
import { InvestigationsError } from './investigations_error';
import { SearchBar } from './search_bar/search_bar';
import { useFetchUserProfiles } from '../../../hooks/use_fetch_user_profiles';

export function InvestigationList() {
const {
Expand All @@ -51,6 +54,10 @@ export function InvestigationList() {
filter: toFilter(status, tags),
});

const { data: userProfiles, isLoading: isUserProfilesLoading } = useFetchUserProfiles({
profileIds: new Set(data?.results.map((i) => i.createdBy)),
});

const investigations = data?.results ?? [];
const totalItemCount = data?.total ?? 0;

Expand All @@ -77,6 +84,27 @@ export function InvestigationList() {
defaultMessage: 'Created by',
}),
truncateText: true,
render: (value: InvestigationResponse['createdBy']) => {
return isUserProfilesLoading ? (
<EuiLoadingSpinner size="m" />
) : (
<EuiToolTip
position="top"
content={
userProfiles?.[value]?.user.full_name ?? userProfiles?.[value]?.user.username ?? value
}
>
<EuiAvatar
name={
userProfiles?.[value]?.user.full_name ??
userProfiles?.[value]?.user.username ??
value
}
size="s"
/>
</EuiToolTip>
);
},
},
{
field: 'tags',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function createInvestigation(
...params,
updatedAt: now,
createdAt: now,
createdBy: user.username,
createdBy: user.profile_uid!,
status: 'triage',
notes: [],
items: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function createInvestigationItem(
const now = Date.now();
const investigationItem = {
id: v4(),
createdBy: user.username,
createdBy: user.profile_uid!,
createdAt: now,
updatedAt: now,
...params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function deleteInvestigationItem(
throw new Error('Note not found');
}

if (item.createdBy !== user.username) {
if (item.createdBy !== user.profile_uid) {
throw new Error('User does not have permission to delete note');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function updateInvestigationItem(
throw new Error('Cannot change item type');
}

if (item.createdBy !== user.username) {
if (item.createdBy !== user.profile_uid) {
throw new Error('User does not have permission to update item');
}

Expand Down

0 comments on commit 32c647a

Please sign in to comment.