fixes for import, fixes for deletes

This commit is contained in:
Saurabh Bhatia 2014-07-10 14:48:18 +08:00
parent f9dcd32252
commit cbf1114c4f
5 changed files with 15 additions and 7 deletions

View File

@ -494,7 +494,7 @@ class Admin::ImportController < OrbitAdminController
fields.each do |f|
type = f["type"]
key = f["name"]["en"].gsub("/"," ").split(' ').join('_').underscore rescue nil
field = AttributeField.find_by(key: key) rescue nil
field = AttributeField.find_by(key: key, role_id: new_role.id) rescue nil
if (field.nil? && key != "category" && key != "academic_status")
if type == "text"
attribute = new_role.attribute_fields.build(key: key, title_translations: {"en"=>f["name"]["en"],"zh_tw"=>f["name"]["zh-tw"]})

View File

@ -181,7 +181,9 @@ class Admin::MembersController < OrbitMemberController
else
@member_profile = MemberProfile.find(params[:id])
@member_profile.user.delete if @member_profile.user.present?
@member_profile.delete
@member_profile.destroy
@member_profile.roles.clear
@member_profile.role_statuses.clear
end
respond_to do |format|

View File

@ -69,10 +69,6 @@ class AttributeField
end
def role
self.attribute.role
end
def panel
panel = LIST[:markups][self[:markup]]["panel"]
end

View File

@ -40,6 +40,8 @@ class MemberProfile
scope :can_display, ->{where(is_hidden: false).order_by([:is_top,:desc],[:created_at,:desc])}
before_save :assign_default_position, :if => :assign_default_position?
before_destroy :delete_personal_plugin_data
mount_uploader :avatar, AvatarUploader
paginates_per 10
@ -151,6 +153,14 @@ class MemberProfile
end
end
def delete_personal_plugin_data
OrbitApp::Plugin::Registration.all.each do |plugin|
class_name = plugin.app_name.constantize
plugin_data = class_name.where(member_profile_id: self.id)
plugin_data.delete
end
end
def assign_default_position?
self.position.nil? || self.parent_id_changed?
end

View File

@ -13,7 +13,7 @@ class Role
has_many :attribute_fields
accepts_nested_attributes_for :attribute_fields
has_many :role_statuses
has_many :role_statuses, dependent: :destroy
def is_built_in?
self.built_in