cache privilege user list.
This commit is contained in:
1 parent
a663231c8c
commit
6f0cf0e92e
3 files changed
+30
-15
No files matched your search
+21
-1
@@ -2,7 +2,7 @@ class User
|
||||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
|
||||
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable
|
||||
|
||||
mount_uploader :avatar, AvatarUploader
|
||||
@@ -11,6 +11,10 @@ class User
|
||||
field :active_role
|
||||
field :nccu_ldap_uid
|
||||
|
||||
# field :cache_dept
|
||||
# has_one :cache_dept, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
field :cache_dept,type: Hash
|
||||
|
||||
has_many :attribute_values, :autosave => true, :dependent => :destroy
|
||||
has_many :app_auths,as: :privilege_apps,:inverse_of => :privilege_lists
|
||||
has_many :blocked_apps, :inverse_of => :blocked_users, :class_name => "AppAuth"
|
||||
@@ -22,6 +26,22 @@ class User
|
||||
has_and_belongs_to_many :sub_roles
|
||||
accepts_nested_attributes_for :attribute_values, :allow_destroy => true
|
||||
|
||||
def create_dept_cache
|
||||
dept_hash = {}
|
||||
|
||||
VALID_LOCALES.each do |loc|
|
||||
locale = loc.to_sym
|
||||
# debugger
|
||||
# if(self.cache_dept.nil?)
|
||||
# self.build_cache_dept key: "dept_cache_user_#{self.id}"
|
||||
# end
|
||||
dept_hash[locale] = sub_roles.collect{|sr| sr.i18n_variable[locale]}.join(',')
|
||||
# self.cache_dept[locale] = sub_roles.collect{|sr| sr.i18n_variable[locale]}.join(',')
|
||||
end
|
||||
self.cache_dept = dept_hash
|
||||
self.save!
|
||||
end
|
||||
|
||||
def self.current
|
||||
Thread.current[:user]
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user