From 56198b02a595a5f8b0cc41c45cb51dd7db9fd694 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Fri, 1 Feb 2013 10:07:42 +0100 Subject: [PATCH] SONAR-4100 Handle case when dispatcher/channel does not exist anymore --- .../app/controllers/account_controller.rb | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/account_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/account_controller.rb index adff2d48ca5..47e81d1c9d2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/account_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/account_controller.rb @@ -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 = {} -- 2.39.5