Fixes #3952 - Notifications are sent for all tickets when an organization of a customer is updated.
This commit is contained in:
parent
a7643fec73
commit
fbc1e4a252
3 changed files with 56 additions and 39 deletions
|
@ -19,9 +19,11 @@ module User::UpdatesTicketOrganization
|
||||||
# update last 100 tickets of user
|
# update last 100 tickets of user
|
||||||
tickets = Ticket.where(customer_id: id).limit(100)
|
tickets = Ticket.where(customer_id: id).limit(100)
|
||||||
tickets.each do |ticket|
|
tickets.each do |ticket|
|
||||||
if ticket.organization_id != organization_id
|
next if ticket.organization_id == organization_id
|
||||||
|
|
||||||
|
Transaction.execute(disable_notification: true, reset_user_id: true) do
|
||||||
ticket.organization_id = organization_id
|
ticket.organization_id = organization_id
|
||||||
ticket.save
|
ticket.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1487,43 +1487,6 @@ RSpec.describe Ticket, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Associations:' do
|
|
||||||
describe '#organization' do
|
|
||||||
subject(:ticket) { build(:ticket, customer: customer, organization: nil) }
|
|
||||||
|
|
||||||
let(:customer) { create(:customer, :with_org) }
|
|
||||||
|
|
||||||
context 'on creation' do
|
|
||||||
it 'automatically adopts the organization of its #customer' do
|
|
||||||
expect { ticket.save }
|
|
||||||
.to change(ticket, :organization).to(customer.organization)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'on update of #customer.organization' do
|
|
||||||
context 'to nil' do
|
|
||||||
it 'automatically updates to #customer’s new value' do
|
|
||||||
ticket.save
|
|
||||||
|
|
||||||
expect { customer.update(organization: nil) }
|
|
||||||
.to change { ticket.reload.organization }.to(nil)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'to a different organization' do
|
|
||||||
let(:new_org) { create(:organization) }
|
|
||||||
|
|
||||||
it 'automatically updates to #customer’s new value' do
|
|
||||||
ticket.save
|
|
||||||
|
|
||||||
expect { customer.update(organization: new_org) }
|
|
||||||
.to change { ticket.reload.organization }.to(new_org)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '.search' do
|
describe '.search' do
|
||||||
|
|
||||||
shared_examples 'search permissions' do
|
shared_examples 'search permissions' do
|
||||||
|
|
52
spec/models/user/updates_ticket_organization_spec.rb
Normal file
52
spec/models/user/updates_ticket_organization_spec.rb
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe User::UpdatesTicketOrganization, type: :model do
|
||||||
|
subject(:ticket) { build(:ticket, customer: customer, organization: nil) }
|
||||||
|
|
||||||
|
let(:customer) { create(:customer, :with_org) }
|
||||||
|
|
||||||
|
context 'when ticket is created' do
|
||||||
|
it 'automatically adopts the organization of its #customer' do
|
||||||
|
expect { ticket.save }
|
||||||
|
.to change(ticket, :organization).to(customer.organization)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when #customer.organization is updated' do
|
||||||
|
context 'when set to nil' do
|
||||||
|
it 'automatically updates to #customer’s new value' do
|
||||||
|
ticket.save
|
||||||
|
|
||||||
|
expect { customer.update(organization: nil) }
|
||||||
|
.to change { ticket.reload.organization }.to(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when #customer.organization is updated to a different organization' do
|
||||||
|
let(:old_org) { customer.organization }
|
||||||
|
let(:new_org) { create(:organization) }
|
||||||
|
|
||||||
|
it 'automatically updates to #customer’s new value' do
|
||||||
|
ticket.save
|
||||||
|
|
||||||
|
expect { customer.update(organization: new_org) }
|
||||||
|
.to change { ticket.reload.organization }.to(new_org)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has made all changes with user id 1' do
|
||||||
|
expect(ticket.updated_by.id).to eq 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# https://github.com/zammad/zammad/issues/3952
|
||||||
|
it 'does not send notifications' do
|
||||||
|
allow(NotificationFactory::Mailer).to receive(:send)
|
||||||
|
|
||||||
|
customer.update(organization: old_org)
|
||||||
|
|
||||||
|
expect(NotificationFactory::Mailer).not_to have_received(:send)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue