Fix for user and role relationship
This commit is contained in:
parent
865be29b37
commit
06203d27b9
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue