FEATURE: Custom unsubscribe options (#17090)

With this change, plugins can create custom unsubscribe keys, extend the unsubscribe view with custom preferences, and decide how they are updated.
This commit is contained in:
Roman Rizzi
2022-06-21 15:49:47 -03:00
committed by GitHub
parent deee3c6f02
commit e0ba35350e
15 changed files with 376 additions and 246 deletions

View File

@ -720,4 +720,26 @@ describe Plugin::Instance do
)
end
end
describe '#register_email_unsubscriber' do
let(:plugin) { Plugin::Instance.new }
after do
DiscoursePluginRegistry.reset_register!(:email_unsubscribers)
end
it "doesn't let you override core unsubscribers" do
expect { plugin.register_email_unsubscriber(UnsubscribeKey::ALL_TYPE, Object) }.to raise_error(ArgumentError)
end
it "finds the plugin's custom unsubscriber" do
new_unsubscriber_type = 'new_type'
key = UnsubscribeKey.new(unsubscribe_key_type: new_unsubscriber_type)
CustomUnsubscriber = Class.new(EmailControllerHelper::BaseEmailUnsubscriber)
plugin.register_email_unsubscriber(new_unsubscriber_type, CustomUnsubscriber)
expect(UnsubscribeKey.get_unsubscribe_strategy_for(key).class).to eq(CustomUnsubscriber)
end
end
end