Fix for user and role relationship

This commit is contained in:
chris 2013-09-06 15:21:40 +08:00 committed by saurabhbhatia
parent 865be29b37
commit 06203d27b9
2 changed files with 24 additions and 4 deletions

View File

@ -93,9 +93,9 @@ class User
var[:id].each do |id,val| var[:id].each do |id,val|
# binding.pry if id == '5052c5b22b5c49ab02000004' # binding.pry if id == '5052c5b22b5c49ab02000004'
if (val=="true") 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") elsif(val=="false")
self.roles << Role.find(id) self.role_ids += Array(id)
end end
end end
end end
@ -110,9 +110,9 @@ class User
# binding.pry if id == '5052c5b22b5c49ab02000004' # binding.pry if id == '5052c5b22b5c49ab02000004'
if ( self.roles.include?(@roid) == false or val=="true") 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") elsif(val=="false")
self.sub_roles << SubRole.find(id) self.sub_role_ids += Array(id)
end end
end end

View File

@ -310,4 +310,24 @@ namespace :migrate do
Rake::Task["web_link_url:web_link_url_i18n"].execute Rake::Task["web_link_url:web_link_url_i18n"].execute
end 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 end