]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4464 Fixed migration of existing default permissions properties
authorJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Tue, 16 Jul 2013 10:42:34 +0000 (12:42 +0200)
committerJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Tue, 16 Jul 2013 10:42:34 +0000 (12:42 +0200)
sonar-server/src/main/webapp/WEB-INF/db/migrate/418_migrate_default_permissions.rb

index 5fecb4e6de2c6e05afe80f4cc2d1956e828c641e..0e2c6239ee282a75f314d664ec7d5a1dbb06622b 100644 (file)
@@ -113,18 +113,22 @@ class MigrateDefaultPermissions < ActiveRecord::Migration
         role = key_fields[2]
         if 'defaultGroups'.eql?(key_fields[4])
           value_fields.each do |group_name|
-            group_id = 'Anyone'.eql?(group_name) ? nil : Group.find_by_name(group_name).id
-            PermissionTemplateGroup.create(:group_id => group_id, :permission_reference => role, :template_id => qualifier_template.id)
+            if 'Anyone'.eql?(group_name) || !Group.find_by_name(group_name).nil?
+              group_id = 'Anyone'.eql?(group_name) ? nil : Group.find_by_name(group_name).id
+              PermissionTemplateGroup.create(:group_id => group_id, :permission_reference => role, :template_id => qualifier_template.id)
+            end
           end
         else
-          value_fields.each do |user_name|
-            user = User.find_by_name(user_name)
-            PermissionTemplateUser.create(:user_id => user.id, :permission_reference => role, :template_id => qualifier_template.id)
+          value_fields.each do |user_login|
+            user = User.find_by_login(user_login)
+            unless user.nil?
+              PermissionTemplateUser.create(:user_id => user.id, :permission_reference => role, :template_id => qualifier_template.id)
+            end
           end
         end
       end
 
-      Property.create(:prop_key => "sonar.permission.template.#{qualifier}.default", :text_value => qualifier_template.id.to_s)
+      Property.create(:prop_key => "sonar.permission.template.#{qualifier}.default", :text_value => qualifier_template.kee)
 
     end