Commit edeb1e0fe315d3dbdd0f1f0fa91b682bd1491107

Authored by Stephen Crosby
2 parents 1b3abc6e 14c71aa4
Exists in master

Merge pull request #1013 from stevecrozz/984_ensure_fingerprinter_updates_on_apps

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 24 embeds_many :watchers
25 25 embeds_one :issue_tracker, class_name: 'IssueTracker'
26 26 embeds_one :notification_service
27   - embeds_one :notice_fingerprinter, autobuild: true
  27 + embeds_one :notice_fingerprinter
28 28  
29 29 has_many :problems, inverse_of: :app, dependent: :destroy
30 30  
31 31 before_validation :generate_api_key, on: :create
32 32 before_save :normalize_github_repo
  33 + before_create :build_notice_fingerprinter
33 34 after_update :store_cached_attributes_on_problems
34 35  
35 36 validates :name, :api_key, presence: true, uniqueness: { allow_blank: true }
... ... @@ -52,6 +53,11 @@ class App
52 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 61 def watched_by?(user)
56 62 watchers.pluck("user_id").include? user.id
57 63 end
... ...
app/models/site_config.rb
... ... @@ -19,18 +19,19 @@ class SiteConfig
19 19 # Denormalize SiteConfig onto individual apps so that this record doesn't
20 20 # need to be accessed when inserting new error notices
21 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 22 App.each do |app|
28 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 35 end
35 36 end
36 37 end
... ...