Skip to content

Commit c390d94

Browse files
committed
true
1 parent d92e0d1 commit c390d94

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/utils/sharing_helpers.test.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@ describe('getIsConversationOwner', () => {
4545
const user: User = { id: 'user1', name: 'Alice' };
4646
const otherUser: User = { id: 'user2', name: 'Bob' };
4747

48-
it('returns false when undefined user', () => {
48+
it('returns true when undefined user', () => {
4949
const conversation = { id: 'abc', createdBy: user, users: [user] };
50-
expect(getIsConversationOwner(conversation, undefined)).toBe(false);
50+
expect(getIsConversationOwner(conversation, undefined)).toBe(true);
5151
});
5252

53-
it('returns false when undefined conversation', () => {
54-
expect(getIsConversationOwner(undefined, user)).toBe(false);
53+
it('returns true when undefined conversation', () => {
54+
expect(getIsConversationOwner(undefined, user)).toBe(true);
55+
});
56+
57+
it('returns true when user is empty object', () => {
58+
const conversation = { id: 'abc', createdBy: user, users: [user] };
59+
expect(getIsConversationOwner(conversation, {})).toBe(true);
5560
});
5661

5762
it('returns true when empty conversation id (is new conversation)', () => {

x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/utils/sharing_helpers.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ export const getIsConversationOwner = (
6565
conversation: Pick<ConversationResponse, 'createdBy' | 'users' | 'id'> | undefined,
6666
user?: User
6767
): boolean => {
68-
if (user === undefined || conversation === undefined) return false;
69-
if (conversation?.id === '') return true;
68+
if (
69+
user === undefined ||
70+
Object.keys(user).length === 0 ||
71+
conversation === undefined ||
72+
conversation?.id === ''
73+
)
74+
return true;
7075
const conversationUser = getCurrentConversationOwner(conversation);
7176
const hasMatchingId = !!conversationUser?.id && !!user?.id && conversationUser?.id === user?.id;
7277
const hasMatchingName =

0 commit comments

Comments
 (0)