-
Notifications
You must be signed in to change notification settings - Fork 13.1k
feat: adds new endpoint to disable Contacts by id #36589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
28104b0
feat: adds new model func to disable Contacts by id
lucas-a-pelegrino f8c1291
feat: adds new endpoint to remove a contact by its id
lucas-a-pelegrino a08f491
tests: adds unit testing for disableContactById
lucas-a-pelegrino af2a780
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into feat…
lucas-a-pelegrino 1fe2302
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into feat…
lucas-a-pelegrino c1b1c7f
tests: adds e2e testing for removing a contact
lucas-a-pelegrino 047e9b9
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into feat…
lucas-a-pelegrino 9acd054
tests: adds improvements to e2e testing
lucas-a-pelegrino d7bfad8
feat: adds new permission and setting to handle livechat contact removal
lucas-a-pelegrino 224adf4
tests: adds setting check for unit/e2e tests
lucas-a-pelegrino 0ed996a
docs: adds .changeset
lucas-a-pelegrino a60636a
Merge branch 'develop' into feat/CTZ-173
lucas-a-pelegrino 4466e37
chore: addresses pull request requested changes
lucas-a-pelegrino f151d93
chore: addresses further PR requested changes
lucas-a-pelegrino c6a273c
chore: attempt at fixing endpoint action response types
lucas-a-pelegrino be4c961
chore: attempt at fixing endpoint action response types #2
lucas-a-pelegrino 20800f3
chore: uses general response validators
lucas-a-pelegrino 71a8091
fix types
KevLehman 9e476ce
chore: adds 403 resposne validation
lucas-a-pelegrino d5f8bec
chore: removes unused schema validators
lucas-a-pelegrino 30ec706
tests: improves after logic to clean rooms
lucas-a-pelegrino f8fbb23
tests: moves disableContact.spec.ts to tests/unit/
lucas-a-pelegrino a99b1d5
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into feat…
lucas-a-pelegrino edffaff
fix: merge conflicts
lucas-a-pelegrino 306b44b
chore: updates .changeset to remove new setting mention
lucas-a-pelegrino 9be8d70
tests: removes old setting mock logic
lucas-a-pelegrino 0010981
chore: adds minor improvements and fixes
lucas-a-pelegrino 4a7589d
chore: removes NotFound exception to adhere to v1 designs
lucas-a-pelegrino d2281c1
tests: removes contact not found 404 test suite
lucas-a-pelegrino d28fd32
tests: minor improvements to test suite
lucas-a-pelegrino 48195f9
tests: removes .only call
lucas-a-pelegrino 02baa51
tests: removes duplicate code
lucas-a-pelegrino 849626c
chore: updates model interface func return type to match actual model…
lucas-a-pelegrino 742bd94
chore: improves logic to handle contacts visitors as well
lucas-a-pelegrino 25831e8
Merge branch 'feat/CTZ-173' of github.com:RocketChat/Rocket.Chat into…
lucas-a-pelegrino ee80cd0
chore: adds GDPR check logic and improves unit tests
lucas-a-pelegrino 3226609
chore: adds api test coverage for GDPR rules check
lucas-a-pelegrino 03be304
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into feat…
lucas-a-pelegrino 442a446
fix: removeGuest call sequence
lucas-a-pelegrino d8b940e
fix: removeGuest call sequence old code
lucas-a-pelegrino 9a07659
fix: remove .only
lucas-a-pelegrino 689df06
chore: replaces findOpenByContactId by countOpenByContact
lucas-a-pelegrino e3533e8
Revert "chore: replaces findOpenByContactId by countOpenByContact"
lucas-a-pelegrino 4ccc52b
chore: replaces findOpenByContactId by findOne
lucas-a-pelegrino 5c8ef7e
fix: findOne query params on disableContact
lucas-a-pelegrino cb7f89d
chore: abstracts findOne into a new model func
lucas-a-pelegrino 8cceade
Merge branch 'develop' into feat/CTZ-173
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,9 @@ | ||
| --- | ||
| "@rocket.chat/meteor": minor | ||
| "@rocket.chat/i18n": minor | ||
| "@rocket.chat/model-typings": minor | ||
| "@rocket.chat/models": minor | ||
| "@rocket.chat/rest-typings": minor | ||
| --- | ||
|
|
||
| Adds new endpoint to disable Livechat Contacts by its id, with a new permission `delete-livechat-contact`. |
This file contains hidden or 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 hidden or 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
23 changes: 23 additions & 0 deletions
23
apps/meteor/app/livechat/server/lib/contacts/disableContact.ts
This file contains hidden or 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,23 @@ | ||
| import type { ILivechatContact } from '@rocket.chat/core-typings'; | ||
| import { LivechatContacts, LivechatRooms } from '@rocket.chat/models'; | ||
|
|
||
| import { settings } from '../../../../settings/server'; | ||
| import { removeGuest } from '../guests'; | ||
|
|
||
| export async function disableContactById(contactId: string): Promise<void> { | ||
lucas-a-pelegrino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const contact = await LivechatContacts.findOneEnabledById<Pick<ILivechatContact, '_id' | 'channels'>>(contactId); | ||
| if (!contact) { | ||
| throw new Error('error-contact-not-found'); | ||
| } | ||
|
|
||
| // Checking if the contact has any open channel/room before removing its data. | ||
| const contactOpenRooms = await LivechatRooms.checkContactOpenRooms(contactId); | ||
| if (contactOpenRooms && !settings.get<boolean>('Livechat_Allow_collect_and_store_HTTP_header_informations')) { | ||
| throw new Error('error-contact-has-open-rooms'); | ||
| } | ||
|
|
||
| // Cleaning contact/visitor data; | ||
| await Promise.all(contact.channels.map((channel) => removeGuest({ _id: channel.visitor.visitorId }))); | ||
|
|
||
| await LivechatContacts.disableByContactId(contactId); | ||
| } | ||
This file contains hidden or 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 hidden or 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
105 changes: 105 additions & 0 deletions
105
apps/meteor/tests/unit/app/livechat/server/lib/disableContact.spec.ts
This file contains hidden or 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,105 @@ | ||
| import { expect } from 'chai'; | ||
| import proxyquire from 'proxyquire'; | ||
| import sinon from 'sinon'; | ||
|
|
||
| const modelsMock = { | ||
| LivechatContacts: { | ||
| findOneEnabledById: sinon.stub(), | ||
| disableByContactId: sinon.stub(), | ||
| }, | ||
| LivechatRooms: { | ||
| checkContactOpenRooms: sinon.stub(), | ||
| }, | ||
| }; | ||
|
|
||
| const settingsMock = { | ||
| get: sinon.stub(), | ||
| }; | ||
|
|
||
| const removeGuestMock = { removeGuest: sinon.stub() }; | ||
|
|
||
| const { disableContactById } = proxyquire.noCallThru().load('../../../../../../app/livechat/server/lib/contacts/disableContact.ts', { | ||
| '@rocket.chat/models': modelsMock, | ||
| '../guests': removeGuestMock, | ||
| '../../../../settings/server': { settings: settingsMock }, | ||
| }); | ||
|
|
||
| describe('disableContact', () => { | ||
| const contact = { | ||
| _id: 'contact-id', | ||
| channels: [ | ||
| { | ||
| visitor: { | ||
| visitorId: 'visitor-id', | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| modelsMock.LivechatContacts.findOneEnabledById.reset(); | ||
| modelsMock.LivechatRooms.checkContactOpenRooms.reset(); | ||
| modelsMock.LivechatContacts.disableByContactId.reset(); | ||
| settingsMock.get.reset(); | ||
| removeGuestMock.removeGuest.reset(); | ||
| }); | ||
|
|
||
| it('should disable the contact', async () => { | ||
| settingsMock.get.withArgs('Livechat_Allow_collect_and_store_HTTP_header_informations').returns(true); | ||
| modelsMock.LivechatContacts.findOneEnabledById.resolves(contact); | ||
| modelsMock.LivechatRooms.checkContactOpenRooms.resolves(null); | ||
| removeGuestMock.removeGuest.resolves(); | ||
| modelsMock.LivechatContacts.disableByContactId.resolves(); | ||
|
|
||
| await disableContactById(contact._id); | ||
|
|
||
| expect(modelsMock.LivechatContacts.findOneEnabledById.calledOnceWith(contact._id)).to.be.true; | ||
| expect(modelsMock.LivechatRooms.checkContactOpenRooms.calledOnceWith(contact._id)).to.be.true; | ||
| expect(removeGuestMock.removeGuest.calledOnceWith({ _id: 'visitor-id' })).to.be.true; | ||
| expect(modelsMock.LivechatContacts.disableByContactId.calledOnceWith(contact._id)).to.be.true; | ||
| }); | ||
|
|
||
| it('should call removeGuest for each channel the contact has communicated from', async () => { | ||
| contact.channels.push({ visitor: { visitorId: 'visitor-id-2' } }); | ||
|
|
||
| settingsMock.get.withArgs('Livechat_Allow_collect_and_store_HTTP_header_informations').returns(true); | ||
| modelsMock.LivechatContacts.findOneEnabledById.resolves(contact); | ||
| modelsMock.LivechatRooms.checkContactOpenRooms.resolves(null); | ||
| removeGuestMock.removeGuest.resolves(); | ||
| modelsMock.LivechatContacts.disableByContactId.resolves(); | ||
|
|
||
| await disableContactById(contact._id); | ||
|
|
||
| expect(modelsMock.LivechatContacts.findOneEnabledById.calledOnceWith(contact._id)).to.be.true; | ||
| expect(modelsMock.LivechatContacts.findOneEnabledById.calledOnceWith(contact._id)).to.be.true; | ||
| expect(modelsMock.LivechatRooms.checkContactOpenRooms.calledOnceWith(contact._id)).to.be.true; | ||
| expect(removeGuestMock.removeGuest.calledTwice).to.be.true; | ||
| expect(removeGuestMock.removeGuest.getCall(0).args[0]).to.deep.equal({ _id: 'visitor-id' }); | ||
| expect(removeGuestMock.removeGuest.getCall(1).args[0]).to.deep.equal({ _id: 'visitor-id-2' }); | ||
| expect(modelsMock.LivechatContacts.disableByContactId.calledOnceWith(contact._id)).to.be.true; | ||
| }); | ||
|
|
||
| it('should throw error if contact is not found', async () => { | ||
| modelsMock.LivechatContacts.findOneEnabledById.resolves(null); | ||
|
|
||
| await expect(disableContactById('nonexistent-contact-id')).to.be.rejectedWith('error-contact-not-found'); | ||
|
|
||
| expect(modelsMock.LivechatContacts.findOneEnabledById.calledOnceWith('nonexistent-contact-id')).to.be.true; | ||
| expect(modelsMock.LivechatRooms.checkContactOpenRooms.notCalled).to.be.true; | ||
| expect(removeGuestMock.removeGuest.notCalled).to.be.true; | ||
| expect(modelsMock.LivechatContacts.disableByContactId.notCalled).to.be.true; | ||
| }); | ||
|
|
||
| it('should throw error if contact has open rooms and GDPR is disabled', async () => { | ||
| settingsMock.get.withArgs('Livechat_Allow_collect_and_store_HTTP_header_informations').returns(false); | ||
| modelsMock.LivechatContacts.findOneEnabledById.resolves(contact); | ||
| modelsMock.LivechatRooms.checkContactOpenRooms.resolves({ _id: 'room-id' }); | ||
| modelsMock.LivechatContacts.disableByContactId.resolves(); | ||
|
|
||
| await expect(disableContactById(contact._id)).to.be.rejectedWith('error-contact-has-open-rooms'); | ||
|
|
||
| expect(modelsMock.LivechatRooms.checkContactOpenRooms.calledOnceWith(contact._id)).to.be.true; | ||
| expect(removeGuestMock.removeGuest.notCalled).to.be.true; | ||
| expect(modelsMock.LivechatContacts.disableByContactId.notCalled).to.be.true; | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.