feat: invalidate cache after inbox members or team members update (#10869)
At the moment, when updating the inbox members, or team members the account cache used for IndexedDB is not invalidated. This can cause inconsistencies in the UI. This PR fixes this by adding explicit invalidation after performing the member changes ### Summary of changes 1. Added a new method `add_members` and `remove_members` to both `team` and `inbox` models. The change was necessary for two reasons - Since the individual `add_member` and `remove_member` is called in a loop, it's wasteful to run the cache invalidation in the method. - Moving the account cache invalidation call in the controller pollutes the controller business logic 2. Updated tests across the board ### More improvements We can make a concern called `Memberable` with usage like `memberable_with :inbox_members`, that can encapsulate the functionality --- Related: https://github.com/chatwoot/chatwoot/issues/10578
This commit is contained in:
@@ -255,28 +255,30 @@ RSpec.describe 'Inbox Member API', type: :request do
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
|
||||
it 'renders error on invalid params' do
|
||||
it 'ignores invalid params' do
|
||||
params = { inbox_id: inbox.id, user_ids: ['invalid'] }
|
||||
original_count = inbox.inbox_members&.count
|
||||
|
||||
delete "/api/v1/accounts/#{account.id}/inbox_members",
|
||||
headers: administrator.create_new_auth_token,
|
||||
params: params,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
expect(response.body).to include('Resource could not be found')
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(inbox.inbox_members&.count).to eq(original_count)
|
||||
end
|
||||
|
||||
it 'renders error on non member params' do
|
||||
it 'ignores non member params' do
|
||||
params = { inbox_id: inbox.id, user_ids: [non_member_agent.id] }
|
||||
original_count = inbox.inbox_members&.count
|
||||
|
||||
delete "/api/v1/accounts/#{account.id}/inbox_members",
|
||||
headers: administrator.create_new_auth_token,
|
||||
params: params,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
expect(response.body).to include('Resource could not be found')
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(inbox.inbox_members&.count).to eq(original_count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user