Skip to content

Commit

Permalink
Fix display name when rendering users
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Feb 9, 2023
1 parent f8e07f9 commit e8193ff
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 34 deletions.
15 changes: 9 additions & 6 deletions x-pack/plugins/cases/common/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@

import * as rt from 'io-ts';

const UserWithoutProfileUidRt = rt.type({
email: rt.union([rt.undefined, rt.null, rt.string]),
full_name: rt.union([rt.undefined, rt.null, rt.string]),
username: rt.union([rt.undefined, rt.null, rt.string]),
});

export const UserRt = rt.intersection([
rt.type({
email: rt.union([rt.undefined, rt.null, rt.string]),
full_name: rt.union([rt.undefined, rt.null, rt.string]),
username: rt.union([rt.undefined, rt.null, rt.string]),
}),
UserWithoutProfileUidRt,
rt.partial({ profile_uid: rt.string }),
]);

export const UserWithProfileInfoRt = rt.intersection([
rt.type({
user: UserRt,
user: UserWithoutProfileUidRt,
}),
rt.partial({ uid: rt.string }),
rt.partial({
avatar: rt.partial({ initials: rt.string, color: rt.string, imageUrl: rt.string }),
}),
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/common/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export type CasesStatus = SnakeToCamelCase<CasesStatusResponse>;
export type CasesMetrics = SnakeToCamelCase<CasesMetricsResponse>;
export type CaseUpdateRequest = SnakeToCamelCase<CasePatchRequest>;
export type CaseConnectors = SnakeToCamelCase<GetCaseConnectorsResponse>;
export type CaseUsers = SnakeToCamelCase<GetCaseUsersResponse>;
export type CaseUsers = GetCaseUsersResponse;

export interface ResolvedCase {
case: Case;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ const buildUserProfilesMap = (users?: CaseUsers): Map<string, UserProfileWithAva
* profile UID is not enough as a user can use our API to add
* an assignee with a non existing UID.
*/
if (user.user.profileUid != null && user.user.username != null) {
userProfiles.set(user.user.profileUid, {
uid: user.user.profileUid,
if (user.uid != null && user.user.username != null) {
userProfiles.set(user.uid, {
uid: user.uid,
user: user.user,
data: {
avatar: user.avatar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,15 @@ const getValidUsers = (
userProfiles: Map<string, UserProfileWithAvatar>
): UserInfoWithAvatar[] => {
const validUsers = users.reduce<Map<string, UserInfoWithAvatar>>((acc, user) => {
const convertedUser = convertToUserInfo(user.user, userProfiles);
const userCamelCase = {
email: user.user.email,
fullName: user.user.full_name,
username: user.user.username,
profileUid: user.uid,
};

const convertedUser = convertToUserInfo(userCamelCase, userProfiles);

if (convertedUser != null) {
acc.set(convertedUser.key, convertedUser.userInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import type { UserProfileWithAvatar } from '@kbn/user-profile-components';
import type { UserWithProfileInfo } from '../../../common/api';
import type { SnakeToCamelCase } from '../../../common/types';

export interface Assignee {
uid: string;
Expand All @@ -20,4 +19,4 @@ export interface AssigneeWithProfile extends Assignee {

export type UserInfoWithAvatar = Partial<Pick<UserProfileWithAvatar, 'user' | 'data'>>;
export type AssigneesFilteringSelection = UserProfileWithAvatar | null;
export type CaseUserWithProfileInfo = SnakeToCamelCase<UserWithProfileInfo>;
export type CaseUserWithProfileInfo = UserWithProfileInfo;
5 changes: 1 addition & 4 deletions x-pack/plugins/cases/public/containers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import type {
SingleCaseMetricsResponse,
CasesFindResponse,
GetCaseConnectorsResponse,
GetCaseUsersResponse,
} from '../../common/api';
import {
CommentType,
Expand Down Expand Up @@ -411,10 +410,8 @@ export const getCaseConnectors = async (
};

export const getCaseUsers = async (caseId: string, signal: AbortSignal): Promise<CaseUsers> => {
const res = await KibanaServices.get().http.fetch<GetCaseUsersResponse>(getCaseUsersUrl(caseId), {
return KibanaServices.get().http.fetch<CaseUsers>(getCaseUsersUrl(caseId), {
method: 'GET',
signal,
});

return convertToCamelCase<GetCaseUsersResponse, CaseUsers>(res);
};
32 changes: 16 additions & 16 deletions x-pack/plugins/cases/public/containers/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -965,23 +965,23 @@ export const getCaseUsersMockResponse = (): CaseUsers => {
{
user: {
email: '[email protected]',
fullName: 'Cases',
full_name: 'Cases',
username: 'cases_all',
},
},
{
user: {
email: null,
fullName: null,
full_name: null,
username: 'elastic',
profileUid: 'u_mGBROF_q5bmFCATbLXAcCwKa0k8JvONAwSruelyKA5E_0',
},
uid: 'u_mGBROF_q5bmFCATbLXAcCwKa0k8JvONAwSruelyKA5E_0',
},
],
reporter: {
user: {
email: '[email protected]',
fullName: 'Cases',
full_name: 'Cases',
username: 'cases_all',
},
},
Expand All @@ -990,52 +990,52 @@ export const getCaseUsersMockResponse = (): CaseUsers => {
{
user: {
email: '',
fullName: '',
full_name: '',
username: 'alerts_read_only',
profileUid: 'u_62h24XVQzG4-MuH1-DqPmookrJY23aRa9h4fyULR6I8_0',
},
uid: 'u_62h24XVQzG4-MuH1-DqPmookrJY23aRa9h4fyULR6I8_0',
},
{
user: {
email: null,
fullName: null,
full_name: null,
username: 'elastic',
profileUid: 'u_mGBROF_q5bmFCATbLXAcCwKa0k8JvONAwSruelyKA5E_0',
},
uid: 'u_mGBROF_q5bmFCATbLXAcCwKa0k8JvONAwSruelyKA5E_0',
},
{
user: {
email: '[email protected]',
fullName: 'Fuzzy Marten',
full_name: 'Fuzzy Marten',
username: 'fuzzy_marten',
profileUid: 'u_3OgKOf-ogtr8kJ5B0fnRcqzXs2aQQkZLtzKEEFnKaYg_0',
},
uid: 'u_3OgKOf-ogtr8kJ5B0fnRcqzXs2aQQkZLtzKEEFnKaYg_0',
},
{
user: {
email: '[email protected]',
fullName: 'Misty Mackerel',
full_name: 'Misty Mackerel',
username: 'misty_mackerel',
profileUid: 'u_BXf_iGxcnicv4l-3-ER7I-XPpfanAFAap7uls86xV7A_0',
},
uid: 'u_BXf_iGxcnicv4l-3-ER7I-XPpfanAFAap7uls86xV7A_0',
},
],
unassignedUsers: [
{
user: {
email: '',
fullName: '',
full_name: '',
username: 'cases_no_connectors',
profileUid: 'u_o0kPgaXwJ7odc3sNWH83yx9JMoVbou_z2CgIEhl2I8M_0',
},
uid: 'u_o0kPgaXwJ7odc3sNWH83yx9JMoVbou_z2CgIEhl2I8M_0',
},
{
user: {
email: '[email protected]',
fullName: 'Valid Chimpanzee',
full_name: 'Valid Chimpanzee',
username: 'valid_chimpanzee',
profileUid: 'u_wEtPffVJIgxWIN8W79Rp84bbORN6x0wKiJ5eTsQvpBA_0',
},
uid: 'u_wEtPffVJIgxWIN8W79Rp84bbORN6x0wKiJ5eTsQvpBA_0',
},
],
};
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/client/user_actions/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ const getUserInformation = (
email: userProfile?.user.email ?? userInfo?.email ?? null,
full_name: userProfile?.user.full_name ?? userInfo?.full_name ?? null,
username: userProfile?.user.username ?? userInfo?.username ?? null,
profile_uid: userProfile?.uid ?? uid ?? userInfo?.profile_uid,
},
avatar: userProfile?.data.avatar,
uid: userProfile?.uid ?? uid ?? userInfo?.profile_uid,
};
};

Expand Down

0 comments on commit e8193ff

Please sign in to comment.