]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4100 Handle case when dispatcher/channel does not exist anymore
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Fri, 1 Feb 2013 09:07:42 +0000 (10:07 +0100)
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>
Fri, 1 Feb 2013 09:07:42 +0000 (10:07 +0100)
sonar-server/src/main/webapp/WEB-INF/app/controllers/account_controller.rb

index adff2d48ca50aac70eb69d7dce0f391ee640ea82..47e81d1c9d28f87fb5ccb9b7a130bf4c83dd1a32 100644 (file)
@@ -103,28 +103,34 @@ class AccountController < ApplicationController
   end
   
   def load_notification_properties
+    channel_keys = @channels.map {|c| c.getKey()}
+    
     Property.find(:all, :conditions => ['prop_key like ? AND user_id = ?', 'notification.%', current_user.id]).each do |property|
       r_id = property.resource_id
       if r_id
         # This is a per-project notif
-        project_notifs = @per_project_notifications[r_id]
-        unless project_notifs
-          project_notifs = {}
-          @per_project_dispatchers.each do |dispatcher|
-            project_notifs[dispatcher] = []
-          end
-          @per_project_notifications[r_id] = project_notifs
-        end
         parts = property.key.split('.')
         dispatcher_key = parts[1]
         channel_key = parts[2]
-        project_notifs[dispatcher_key] << channel_key
+        if @per_project_dispatchers.include?(dispatcher_key) && channel_keys.include?(channel_key)
+          project_notifs = get_project_notifications(r_id)
+          project_notifs[dispatcher_key] << channel_key
+        end
       else
         # This is a global notif
         @global_notifications[property.key.sub('notification.', '')] = true
       end
     end
   end
+
+  def get_project_notifications(resource_id)
+    project_notifs = @per_project_notifications[resource_id]
+    unless project_notifs
+      project_notifs = init_project_notifications
+      @per_project_notifications[resource_id] = project_notifs
+    end
+    project_notifs
+  end
   
   def init_project_notifications
     project_notifs = {}