-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Invalid association between visitors and contacts. (#33868)
* fix: Invalid association between visitors and contacts. * types * types * some tests * removed pointless tests * fix api test * uneeded import * fixed some tests * fixed some tests * fixing tests * added tests with different invalid associations * do not migrate visitors with no rooms * tests * tests * Update apps/meteor/ee/app/livechat-enterprise/server/api/contacts.ts Co-authored-by: Rafael Tapia <[email protected]> * no need for array * adjusting tests --------- Co-authored-by: Rafael Tapia <[email protected]>
- Loading branch information
1 parent
33f955c
commit 7f46d97
Showing
62 changed files
with
960 additions
and
545 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import type { IAppContactsConverter, IAppsLivechatContact } from '@rocket.chat/apps'; | ||
import type { ILivechatContact } from '@rocket.chat/core-typings'; | ||
import { LivechatContacts } from '@rocket.chat/models'; | ||
import cloneDeep from 'lodash.clonedeep'; | ||
|
||
import { transformMappedData } from './transformMappedData'; | ||
|
||
export class AppContactsConverter implements IAppContactsConverter { | ||
async convertById(contactId: ILivechatContact['_id']): Promise<IAppsLivechatContact | undefined> { | ||
const contact = await LivechatContacts.findOneById(contactId); | ||
if (!contact) { | ||
return; | ||
} | ||
|
||
return this.convertContact(contact); | ||
} | ||
|
||
async convertContact(contact: undefined | null): Promise<undefined>; | ||
|
||
async convertContact(contact: ILivechatContact): Promise<IAppsLivechatContact>; | ||
|
||
async convertContact(contact: ILivechatContact | undefined | null): Promise<IAppsLivechatContact | undefined> { | ||
if (!contact) { | ||
return; | ||
} | ||
|
||
return cloneDeep(contact); | ||
} | ||
|
||
convertAppContact(contact: undefined | null): Promise<undefined>; | ||
|
||
convertAppContact(contact: IAppsLivechatContact): Promise<ILivechatContact>; | ||
|
||
async convertAppContact(contact: IAppsLivechatContact | undefined | null): Promise<ILivechatContact | undefined> { | ||
if (!contact) { | ||
return; | ||
} | ||
|
||
// Map every attribute individually to ensure there are no extra data coming from the app and leaking into anything else. | ||
const map = { | ||
_id: '_id', | ||
_updatedAt: '_updatedAt', | ||
name: 'name', | ||
phones: { | ||
from: 'phones', | ||
list: true, | ||
map: { | ||
phoneNumber: 'phoneNumber', | ||
}, | ||
}, | ||
emails: { | ||
from: 'emails', | ||
list: true, | ||
map: { | ||
address: 'address', | ||
}, | ||
}, | ||
contactManager: 'contactManager', | ||
unknown: 'unknown', | ||
conflictingFields: { | ||
from: 'conflictingFields', | ||
list: true, | ||
map: { | ||
field: 'field', | ||
value: 'value', | ||
}, | ||
}, | ||
customFields: 'customFields', | ||
channels: { | ||
from: 'channels', | ||
list: true, | ||
map: { | ||
name: 'name', | ||
verified: 'verified', | ||
visitor: { | ||
from: 'visitor', | ||
map: { | ||
visitorId: 'visitorId', | ||
source: { | ||
from: 'source', | ||
map: { | ||
type: 'type', | ||
id: 'id', | ||
}, | ||
}, | ||
}, | ||
}, | ||
blocked: 'blocked', | ||
field: 'field', | ||
value: 'value', | ||
verifiedAt: 'verifiedAt', | ||
details: { | ||
from: 'details', | ||
map: { | ||
type: 'type', | ||
id: 'id', | ||
alias: 'alias', | ||
label: 'label', | ||
sidebarIcon: 'sidebarIcon', | ||
defaultIcon: 'defaultIcon', | ||
destination: 'destination', | ||
}, | ||
}, | ||
lastChat: { | ||
from: 'lastChat', | ||
map: { | ||
_id: '_id', | ||
ts: 'ts', | ||
}, | ||
}, | ||
}, | ||
}, | ||
createdAt: 'createdAt', | ||
lastChat: { | ||
from: 'lastChat', | ||
map: { | ||
_id: '_id', | ||
ts: 'ts', | ||
}, | ||
}, | ||
importIds: 'importIds', | ||
}; | ||
|
||
return transformMappedData(contact, map); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { ILivechatContactVisitorAssociation } from '@rocket.chat/core-typings'; | ||
|
||
export function isSameChannel(channel1: ILivechatContactVisitorAssociation, channel2: ILivechatContactVisitorAssociation): boolean { | ||
if (!channel1 || !channel2) { | ||
return false; | ||
} | ||
|
||
if (channel1.visitorId !== channel2.visitorId) { | ||
return false; | ||
} | ||
if (channel1.source.type !== channel2.source.type) { | ||
return false; | ||
} | ||
|
||
if ((channel1.source.id || channel2.source.id) && channel1.source.id !== channel2.source.id) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.