Commit 14c71aa4aa61080eda91e3dd0fbabb87332d0a68
1 parent
1453287a
Exists in
master
Refs #984 ensure fingerprinter updates on apps
Showing
2 changed files
with
17 additions
and
10 deletions
Show diff stats
app/models/app.rb
@@ -24,12 +24,13 @@ class App | @@ -24,12 +24,13 @@ class App | ||
24 | embeds_many :watchers | 24 | embeds_many :watchers |
25 | embeds_one :issue_tracker, class_name: 'IssueTracker' | 25 | embeds_one :issue_tracker, class_name: 'IssueTracker' |
26 | embeds_one :notification_service | 26 | embeds_one :notification_service |
27 | - embeds_one :notice_fingerprinter, autobuild: true | 27 | + embeds_one :notice_fingerprinter |
28 | 28 | ||
29 | has_many :problems, inverse_of: :app, dependent: :destroy | 29 | has_many :problems, inverse_of: :app, dependent: :destroy |
30 | 30 | ||
31 | before_validation :generate_api_key, on: :create | 31 | before_validation :generate_api_key, on: :create |
32 | before_save :normalize_github_repo | 32 | before_save :normalize_github_repo |
33 | + before_create :build_notice_fingerprinter | ||
33 | after_update :store_cached_attributes_on_problems | 34 | after_update :store_cached_attributes_on_problems |
34 | 35 | ||
35 | validates :name, :api_key, presence: true, uniqueness: { allow_blank: true } | 36 | validates :name, :api_key, presence: true, uniqueness: { allow_blank: true } |
@@ -52,6 +53,11 @@ class App | @@ -52,6 +53,11 @@ class App | ||
52 | where watchers: { "$elemMatch" => { "user_id" => user.id } } | 53 | where watchers: { "$elemMatch" => { "user_id" => user.id } } |
53 | } | 54 | } |
54 | 55 | ||
56 | + def build_notice_fingerprinter | ||
57 | + attrs = SiteConfig.document.notice_fingerprinter_attributes | ||
58 | + self.notice_fingerprinter = attrs | ||
59 | + end | ||
60 | + | ||
55 | def watched_by?(user) | 61 | def watched_by?(user) |
56 | watchers.pluck("user_id").include? user.id | 62 | watchers.pluck("user_id").include? user.id |
57 | end | 63 | end |
app/models/site_config.rb
@@ -19,18 +19,19 @@ class SiteConfig | @@ -19,18 +19,19 @@ class SiteConfig | ||
19 | # Denormalize SiteConfig onto individual apps so that this record doesn't | 19 | # Denormalize SiteConfig onto individual apps so that this record doesn't |
20 | # need to be accessed when inserting new error notices | 20 | # need to be accessed when inserting new error notices |
21 | def denormalize | 21 | def denormalize |
22 | - notice_fingerprinter_attributes = notice_fingerprinter.attributes.tap do |attrs| | ||
23 | - attrs.delete('_id') | ||
24 | - attrs[:source] = :site | ||
25 | - end | ||
26 | - | ||
27 | App.each do |app| | 22 | App.each do |app| |
28 | f = app.notice_fingerprinter | 23 | f = app.notice_fingerprinter |
24 | + next if f.source && f.source != CONFIG_SOURCE_SITE | ||
29 | 25 | ||
30 | - if !f || f.source == CONFIG_SOURCE_SITE | ||
31 | - app.update_attributes( | ||
32 | - notice_fingerprinter: notice_fingerprinter_attributes) | ||
33 | - end | 26 | + app.update_attributes( |
27 | + notice_fingerprinter: notice_fingerprinter_attributes) | ||
28 | + end | ||
29 | + end | ||
30 | + | ||
31 | + def notice_fingerprinter_attributes | ||
32 | + notice_fingerprinter.attributes.tap do |attrs| | ||
33 | + attrs.delete('_id') | ||
34 | + attrs[:source] = :site | ||
34 | end | 35 | end |
35 | end | 36 | end |
36 | end | 37 | end |