diff --git a/app/models/user/user.rb b/app/models/user/user.rb index 4e11ae105..661d8e72d 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -89,9 +89,9 @@ class User var[:id].each do |id,val| # binding.pry if id == '5052c5b22b5c49ab02000004' if (val=="true") - self.roles = self.roles.reject{|t| t.id.to_s==id} + self.role_ids.reject!{|t| t.to_s == id} elsif(val=="false") - self.roles << Role.find(id) + self.role_ids += Array(id) end end end @@ -106,9 +106,9 @@ class User # binding.pry if id == '5052c5b22b5c49ab02000004' if ( self.roles.include?(@roid) == false or val=="true") - self.sub_roles = self.sub_roles.reject{|t| t.id.to_s==id} + self.sub_role_ids.reject!{|t| t.to_s == id} elsif(val=="false") - self.sub_roles << SubRole.find(id) + self.sub_role_ids += Array(id) end end diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index a5e0d11b0..d67b039c7 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -326,4 +326,24 @@ namespace :migrate do `mongo #{Mongoid.config.database.name} --eval "db.tags.remove({_type: {$ne: 'Tag'}})"` end + task :add_missing_user_link => :environment do + User.all.each do |user| + user.role_ids.uniq! + user.sub_role_ids.uniq! + user.save + user.roles.each do |role| + unless role.user_ids.include?(user.id) + role.user_ids << user.id + role.save + end + end + user.sub_roles.each do |sub_role| + unless sub_role.user_ids.include?(user.id) + sub_role.user_ids << user.id + sub_role.save + end + end + end + end + end