-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathedition_services.rb
64 lines (52 loc) · 2.03 KB
/
edition_services.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Whitehall::Application.config.to_prepare do
Whitehall.edition_services.tap do |coordinator|
coordinator.subscribe do |event, edition, _options|
if %w[publish force_publish].include?(event)
ServiceListeners::AttachmentAssetPublisher.call(edition)
elsif event == "delete"
ServiceListeners::AttachmentAssetDeleter.call(edition)
else
ServiceListeners::AttachmentUpdater.call(attachable: edition)
end
end
coordinator.subscribe("unpublish") do |_event, edition, _options|
# handling edition's dependency on other content
edition.edition_dependencies.destroy_all
# search
ServiceListeners::SearchIndexer
.new(edition)
.remove!
# Update attachment redirect urls
ServiceListeners::AttachmentRedirectUrlUpdater.call(attachable: edition)
end
coordinator.subscribe(/^(force_publish|publish|unwithdraw)$/) do |_event, edition, options|
ServiceListeners::EditionDependenciesPopulator
.new(edition)
.populate!
ServiceListeners::AttachmentDependencyPopulator
.new(edition)
.populate!
# handling edition's dependency on other content
edition.republish_dependent_editions
ServiceListeners::AnnouncementClearer
.new(edition)
.clear!
AuthorNotifierWorker.perform_async(edition.id, *[options[:user]&.id].compact)
# Update attachment redirect urls
ServiceListeners::AttachmentRedirectUrlUpdater.call(attachable: edition)
end
coordinator.subscribe(/^(force_publish|publish|withdraw|unwithdraw)$/) do |_event, edition, _options|
ServiceListeners::SearchIndexer
.new(edition)
.index!
end
coordinator.subscribe(/^(force_publish|publish|unwithdraw|unpublish|withdraw)$/) do |_event, edition, options|
ServiceListeners::EditorialRemarker
.new(edition, options[:user], options[:remark])
.save_remark!
ServiceListeners::FeaturableOrganisationRepublisher
.new(edition)
.call
end
end
end