diff --git a/app/models/app.rb b/app/models/app.rb index 37d9ca7..e7be608 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -24,12 +24,13 @@ class App embeds_many :watchers embeds_one :issue_tracker, class_name: 'IssueTracker' embeds_one :notification_service - embeds_one :notice_fingerprinter, autobuild: true + embeds_one :notice_fingerprinter has_many :problems, inverse_of: :app, dependent: :destroy before_validation :generate_api_key, on: :create before_save :normalize_github_repo + before_create :build_notice_fingerprinter after_update :store_cached_attributes_on_problems validates :name, :api_key, presence: true, uniqueness: { allow_blank: true } @@ -52,6 +53,11 @@ class App where watchers: { "$elemMatch" => { "user_id" => user.id } } } + def build_notice_fingerprinter + attrs = SiteConfig.document.notice_fingerprinter_attributes + self.notice_fingerprinter = attrs + end + def watched_by?(user) watchers.pluck("user_id").include? user.id end diff --git a/app/models/site_config.rb b/app/models/site_config.rb index 434a93e..d5b321c 100644 --- a/app/models/site_config.rb +++ b/app/models/site_config.rb @@ -19,18 +19,19 @@ class SiteConfig # Denormalize SiteConfig onto individual apps so that this record doesn't # need to be accessed when inserting new error notices def denormalize - notice_fingerprinter_attributes = notice_fingerprinter.attributes.tap do |attrs| - attrs.delete('_id') - attrs[:source] = :site - end - App.each do |app| f = app.notice_fingerprinter + next if f.source && f.source != CONFIG_SOURCE_SITE - if !f || f.source == CONFIG_SOURCE_SITE - app.update_attributes( - notice_fingerprinter: notice_fingerprinter_attributes) - end + app.update_attributes( + notice_fingerprinter: notice_fingerprinter_attributes) + end + end + + def notice_fingerprinter_attributes + notice_fingerprinter.attributes.tap do |attrs| + attrs.delete('_id') + attrs[:source] = :site end end end -- libgit2 0.21.2