Override mongoid-tree callback condition for default position
This commit is contained in:
parent
b3e16ce23b
commit
061225f56c
|
@ -52,6 +52,7 @@ class User
|
|||
accepts_nested_attributes_for :attribute_values, :allow_destroy => true
|
||||
|
||||
before_create :initialize_desktop
|
||||
before_save :assign_default_position, :if => :assign_default_position?
|
||||
before_save :rebuild_status_record
|
||||
scope :remote_account, where(:nccu_id.ne => nil)
|
||||
scope :not_guest_user, all_of(:name.ne => "guest")
|
||||
|
@ -289,7 +290,7 @@ class User
|
|||
end
|
||||
end
|
||||
|
||||
protected
|
||||
private
|
||||
|
||||
def rebuild_status_record
|
||||
self.status_record = {}
|
||||
|
@ -299,4 +300,9 @@ class User
|
|||
end
|
||||
end
|
||||
|
||||
# override mongoid-tree's method
|
||||
def assign_default_position?
|
||||
!self['name'].eql?('guest') && (self.position.nil? || self.parent_id_changed?)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -92,6 +92,7 @@ namespace :new_ui do
|
|||
end
|
||||
|
||||
task :reset_user_position => :environment do
|
||||
User.where(email: /guest/).each{|d|d.update_attribute(:position, nil)}
|
||||
User.not_guest_user.each_with_index do |user, i|
|
||||
user.update_attribute(:position, i)
|
||||
end
|
||||
|
|
Reference in New Issue