user id set & user fields set & role set & member frontend list & user translation & create new member bug fix
This commit is contained in:
1 parent
12e39b4d77
commit
697944a029
172 files changed
+3631
-96
No files matched your search
@@ -11,9 +11,14 @@ class Role < Attribute
|
||||
|
||||
has_many :sub_roles, :autosave => true, :dependent => :destroy
|
||||
has_many :users
|
||||
has_many :statuses, :autosave => true, :dependent => :destroy
|
||||
# has_many :statuses, :autosave => true, :dependent => :destroy
|
||||
# has_many :attribute_fields, :autosave => true, :dependent => :destroy
|
||||
has_many :role_statuses, :autosave => true, :dependent => :destroy
|
||||
has_many :role_categorys, :autosave => true, :dependent => :destroy
|
||||
|
||||
accepts_nested_attributes_for :sub_roles, :allow_destroy => true
|
||||
accepts_nested_attributes_for :role_statuses, :allow_destroy => true
|
||||
accepts_nested_attributes_for :role_categorys, :allow_destroy => true
|
||||
|
||||
def is_built_in?
|
||||
self.built_in
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
class RoleCategory < RoleFilter
|
||||
|
||||
has_and_belongs_to_many :users
|
||||
belongs_to :role
|
||||
|
||||
def self.get_role_data(role_key)
|
||||
|
||||
@role = Role.where(:key =>role_key).first
|
||||
|
||||
return @role.id
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,26 @@
|
||||
class RoleFilter
|
||||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
# include OrbitCoreLib::ObjectAuthable
|
||||
include OrbitCoreLib::ObjectDisable
|
||||
|
||||
|
||||
field :key
|
||||
field :title, localize: true
|
||||
|
||||
# belongs_to :role
|
||||
|
||||
def pp_object
|
||||
title
|
||||
end
|
||||
|
||||
def self.from_id(id)
|
||||
RoleFilter.find(id) rescue nil
|
||||
end
|
||||
|
||||
def self.is_localized?(field_name)
|
||||
self.fields[field_name.to_s].localized?
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
class RoleStatus < RoleFilter
|
||||
|
||||
has_and_belongs_to_many :users
|
||||
belongs_to :role
|
||||
|
||||
scope :can_display,where(disable: false)
|
||||
|
||||
def self.get_role_data(role_key)
|
||||
|
||||
@role = Role.where(:key =>role_key).first
|
||||
|
||||
return @role.id
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
+62
-5
@@ -9,7 +9,13 @@ class User
|
||||
|
||||
field :admin, :type => Boolean, :default => true
|
||||
field :active_role
|
||||
field :user_id
|
||||
field :sid
|
||||
field :first_name, localize: true
|
||||
field :last_name, localize: true
|
||||
field :email
|
||||
field :sex, :default => 'unknown'
|
||||
field :office_tel
|
||||
field :cache_dept,type: Hash
|
||||
field :status_record,type: Hash
|
||||
|
||||
@@ -25,9 +31,11 @@ class User
|
||||
# has_many :papers, :autosave => true, :dependent => :destroy
|
||||
has_and_belongs_to_many :sub_role_tags
|
||||
|
||||
has_and_belongs_to_many :statuses
|
||||
# has_and_belongs_to_many :statuses
|
||||
has_and_belongs_to_many :roles
|
||||
has_and_belongs_to_many :sub_roles
|
||||
has_and_belongs_to_many :role_statuses
|
||||
has_and_belongs_to_many :role_categorys
|
||||
accepts_nested_attributes_for :attribute_values, :allow_destroy => true
|
||||
|
||||
before_create :initialize_desktop
|
||||
@@ -36,6 +44,9 @@ class User
|
||||
scope :remote_account, where(:nccu_id.ne => nil)
|
||||
scope :not_guest_user, all_of(:name.ne => "guest")
|
||||
|
||||
validates :user_id,
|
||||
:presence => { :message => I18n.t("users.user_id_not_null") } ,
|
||||
:length => {:minimum => 3, :maximum => 50, :message => I18n.t("users.user_id_length") }
|
||||
# validates_uniqueness_of :email,:message=> I18n.t("devise.registrations.email_not_unique")
|
||||
|
||||
# def new_attribute_values=(vars)
|
||||
@@ -101,6 +112,24 @@ class User
|
||||
end
|
||||
end
|
||||
|
||||
def role_status=(var)
|
||||
self.role_statuses = []
|
||||
var[:id].each do |id,val|
|
||||
if (val=="true")
|
||||
self.role_statuses << RoleStatus.find(id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def role_category=(var)
|
||||
self.role_categorys = []
|
||||
var[:id].each do |id,val|
|
||||
if (val=="true")
|
||||
self.role_categorys << RoleCategory.find(id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def set_sub_role(sub_role_id,status_id)
|
||||
@@ -144,6 +173,17 @@ class User
|
||||
}.uniq!
|
||||
end
|
||||
|
||||
def self.get_member_list_attribute_field_name(role_type,field_key)
|
||||
@attribute = ::Attribute.where(:key => role_type).first
|
||||
return ::AttributeField.where(:key => field_key, :attribute_id => @attribute.id).first.title
|
||||
end
|
||||
|
||||
def self.get_member_list_attribute_value(user_id,role_type,field_key)
|
||||
@attribute = ::Attribute.where(:key => role_type).first
|
||||
@AttributeField = ::AttributeField.where(:key => field_key, :attribute_id => @attribute.id).first
|
||||
return ::AttributeValue.where(attribute_field_id: @AttributeField.id, :user_id => user_id).first[I18n.locale.to_s]
|
||||
end
|
||||
|
||||
def create_dept_cache
|
||||
dept_hash = {}
|
||||
|
||||
@@ -170,12 +210,30 @@ class User
|
||||
(query1 + query2).uniq
|
||||
end
|
||||
|
||||
# def name
|
||||
# info = Class::Info.first(:conditions => {:key => 'profile'})
|
||||
# if info
|
||||
# first_name = get_attribute_values.detect {|value| value.key.to_s.eql?('first_name') }[I18n.locale.to_s] rescue nil
|
||||
# last_name = get_attribute_values.detect {|value| value.key.to_s.eql?('last_name') }[I18n.locale.to_s] rescue nil
|
||||
# full_name = "#{last_name} #{first_name}"
|
||||
|
||||
# if full_name.strip.empty?
|
||||
# full_name = email
|
||||
# end
|
||||
|
||||
# return full_name
|
||||
# else
|
||||
# return nil
|
||||
# end
|
||||
# end
|
||||
|
||||
def name
|
||||
info = Class::Info.first(:conditions => {:key => 'profile'})
|
||||
if info
|
||||
first_name = get_attribute_values.detect {|value| value.key.to_s.eql?('first_name') }[I18n.locale.to_s] rescue nil
|
||||
last_name = get_attribute_values.detect {|value| value.key.to_s.eql?('last_name') }[I18n.locale.to_s] rescue nil
|
||||
full_name = "#{last_name} #{first_name}"
|
||||
# first_name = get_attribute_values.detect {|value| value.key.to_s.eql?('first_name') }[I18n.locale.to_s] rescue nil
|
||||
# last_name = get_attribute_values.detect {|value| value.key.to_s.eql?('last_name') }[I18n.locale.to_s] rescue nil
|
||||
# full_name = (I18n.locale != 'zh_tw') ? "#{self.last_name} #{self.first_name}" : "#{self.first_name} #{self.last_name}"
|
||||
full_name = (I18n.locale.to_s == 'zh_tw') ? "#{self.last_name} #{self.first_name}" : "#{self.first_name} #{self.last_name}"
|
||||
|
||||
if full_name.strip.empty?
|
||||
full_name = email
|
||||
@@ -211,7 +269,6 @@ class User
|
||||
self.roles = self.roles.uniq
|
||||
end
|
||||
|
||||
|
||||
def rebuild_status_record
|
||||
self.status_record = {}
|
||||
self.attribute_values.reject{|t| t.key!='status'}.each do |status|
|
||||
|
||||
Reference in new issue
Block a user