diff --git a/app/models/user/user.rb b/app/models/user/user.rb index ce1604bce..d1a58d536 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -93,9 +93,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 @@ -110,9 +110,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 615b075fb..61f3e2f30 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -310,4 +310,24 @@ namespace :migrate do Rake::Task["web_link_url:web_link_url_i18n"].execute 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