From 6f0cf0e92e3edb197e011172a9a10f9972821473 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 22 May 2012 17:55:18 +0800 Subject: [PATCH] cache privilege user list. --- .../object_auths_new_interface_controller.rb | 2 +- app/models/user/user.rb | 22 ++++++++++++++++++- .../_privilege_user.html.erb | 21 +++++++----------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/app/controllers/admin/object_auths_new_interface_controller.rb b/app/controllers/admin/object_auths_new_interface_controller.rb index bc546ac8..42e82b47 100644 --- a/app/controllers/admin/object_auths_new_interface_controller.rb +++ b/app/controllers/admin/object_auths_new_interface_controller.rb @@ -4,7 +4,7 @@ class Admin::ObjectAuthsNewInterfaceController < OrbitBackendController def setting - @sys_users = User.all(conditions: {admin: false}) + @sys_users = User.all(conditions: {admin: false}).includes(:avatar) @ob_auth = ObjectAuth.find params[:object_auth_id] @options_from_collection_for_select_ob_auth = [@ob_auth].collect{|oa| [oa.auth_obj.pp_object,oa.id] } @users_array = @ob_auth.privilege_users rescue [] diff --git a/app/models/user/user.rb b/app/models/user/user.rb index 9cbd9967..7c1e4c63 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -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 diff --git a/app/views/admin/object_auths_new_interface/_privilege_user.html.erb b/app/views/admin/object_auths_new_interface/_privilege_user.html.erb index 90f5cb65..5d5f6e7f 100644 --- a/app/views/admin/object_auths_new_interface/_privilege_user.html.erb +++ b/app/views/admin/object_auths_new_interface/_privilege_user.html.erb @@ -1,12 +1,8 @@ -<%= content_tag :div ,:id => "users_checkbox_ary",:class => 'clear' do -%> - <% @sys_users.each do |sys_user| -%> - -
- - <% sys_user.sub_roles.each do |sr| %> - - <% end %> - <%= content_tag :div,:data=>{'original-title'=>t('announcement.bulletin.approval_setting_window_title'),:content => "#{sys_user.sub_roles.collect{|sr| sr.i18n_variable[I18n.locale]}.join(',')}"},:class=>"checkbox clear" do %> +<%= content_tag :div ,:id => "users_checkbox_ary",:class => 'clear' do %> + <% @sys_users.each do |sys_user| %> +
+ + <%= content_tag :div,:data=>{'original-title'=>t('announcement.bulletin.approval_setting_window_title'),:content => sys_user.cache_dept[I18n.locale.to_s]},:class=>"checkbox clear" do %>
@@ -18,8 +14,7 @@
<%= label_tag "lab-user-#{sys_user.id}", (sys_user.name rescue ''),:class=>"member-name",:id=>nil -%> <%= check_box_tag "[users][#{sys_user.id}]", 'true',users.include?(sys_user),:class => "check" -%> - <%end -%> + <%end %>
- - <% end -%> -<% end -%> \ No newline at end of file + <% end %> +<% end %> \ No newline at end of file