From 97e289f823e8caac62887390f7c1936bbf1e4759 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 22 May 2012 17:55:18 +0800 Subject: [PATCH 1/3] 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 bc546ac87..42e82b479 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 2a2dbd861..203b6ce6c 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 @@ -10,6 +10,10 @@ class User field :admin, :type => Boolean, :default => true field :active_role + # 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" @@ -21,6 +25,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 90f5cb65b..5d5f6e7f6 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 From 3e60b34491ef2b9a5b38ea3bb3b8d23eaec7eae2 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 22 May 2012 17:57:45 +0800 Subject: [PATCH 2/3] add script for cache user --- app/jobs/sync_db.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/jobs/sync_db.rb b/app/jobs/sync_db.rb index d4bda7901..4f47b8d07 100644 --- a/app/jobs/sync_db.rb +++ b/app/jobs/sync_db.rb @@ -10,6 +10,7 @@ class SyncDb task = 'mid_site:sync' args = [] %x[rake #{task} --trace >> #{Rails.root}/log/rake.log] + User.all.each{|ur| ur.create_dept_cache} puts "SyncDb Synced" end end From 20eb8b4d155698575bfaeee5ee3cb69b28b954f3 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 23 May 2012 13:00:51 +0800 Subject: [PATCH 3/3] Clean up code , cache other auths. Fix sidebar --- .../module_apps_new_interface_controller.rb | 2 +- app/helpers/application_helper.rb | 2 +- .../_privilege_user.html.erb | 25 ------------------- .../setting.html.erb | 2 +- .../_privilege_user.html.erb | 20 --------------- .../setting.html.erb | 4 +-- app/views/layouts/_side_bar.html.erb | 2 +- .../layouts/_users_checkbox_ary.html.erb | 3 +++ app/views/shared/_privilege_user.html.erb | 16 ++++++++++++ .../back_end/approvals_controller.rb | 2 +- .../approvals/_privilege_user.html.erb | 25 ------------------- .../back_end/approvals/setting.html.erb | 2 +- .../back_end/approvals/setting.js.erb | 2 +- .../back_end/news_approvals_controller.rb | 2 +- .../news_approvals/_privilege_user.html.erb | 25 ------------------- .../back_end/news_approvals/setting.html.erb | 2 +- .../back_end/news_approvals/setting.js.erb | 2 +- 17 files changed, 31 insertions(+), 107 deletions(-) delete mode 100644 app/views/admin/module_apps_new_interface/_privilege_user.html.erb delete mode 100644 app/views/admin/object_auths_new_interface/_privilege_user.html.erb create mode 100644 app/views/layouts/_users_checkbox_ary.html.erb create mode 100644 app/views/shared/_privilege_user.html.erb delete mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/_privilege_user.html.erb delete mode 100644 vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/_privilege_user.html.erb diff --git a/app/controllers/admin/module_apps_new_interface_controller.rb b/app/controllers/admin/module_apps_new_interface_controller.rb index 404ac6930..d9989fab1 100644 --- a/app/controllers/admin/module_apps_new_interface_controller.rb +++ b/app/controllers/admin/module_apps_new_interface_controller.rb @@ -6,7 +6,7 @@ class Admin::ModuleAppsNewInterfaceController < OrbitBackendController layout "new_admin" def setting - @sys_users = User.all(conditions: {admin: false}) + @sys_users = User.all(conditions: {admin: false}).includes(:avatar) @module_app = ModuleApp.find(params[:module_app_id]) @options_from_collection_for_select_bulletin_categorys = [@module_app].collect{|ma| [ma.title,ma.id] } # if params.has_key? :category diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 26dbddc47..81faa3568 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,7 +1,7 @@ module ApplicationHelper FLASH_NOTICE_KEYS = [:error, :notice, :warning] - + def colorize_in_use_locale(locale) @site_in_use_locales.include?(locale)? 'green' : 'red' end diff --git a/app/views/admin/module_apps_new_interface/_privilege_user.html.erb b/app/views/admin/module_apps_new_interface/_privilege_user.html.erb deleted file mode 100644 index 90f5cb65b..000000000 --- a/app/views/admin/module_apps_new_interface/_privilege_user.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -<%= 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 %> -
-
-
- <% if sys_user.avatar? %> - <%= image_tag(sys_user.avatar.thumb.url,:class => "member-img") %> - <% else %> - <%= image_tag "person.png",:class => "member-img" %> - <% end %> -
- <%= 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 -%> \ No newline at end of file diff --git a/app/views/admin/module_apps_new_interface/setting.html.erb b/app/views/admin/module_apps_new_interface/setting.html.erb index 7d1179f0d..d3d769b01 100644 --- a/app/views/admin/module_apps_new_interface/setting.html.erb +++ b/app/views/admin/module_apps_new_interface/setting.html.erb @@ -26,7 +26,7 @@
<%= content_tag :div do -%> <% form_tag admin_module_app_manager_auth_proc_path do %> - <%= render :partial => "privilege_user", :locals => {:users => @users_array} %> + <%= render :partial => "layouts/users_checkbox_ary" %>
<%= submit_tag "Update", :class => 'btn btn-primary' %>
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 deleted file mode 100644 index 5d5f6e7f6..000000000 --- a/app/views/admin/object_auths_new_interface/_privilege_user.html.erb +++ /dev/null @@ -1,20 +0,0 @@ -<%= 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 %> -
-
-
- <% if sys_user.avatar? %> - <%= image_tag(sys_user.avatar.thumb.url,:class => "member-img") %> - <% else %> - <%= image_tag "person.png",:class => "member-img" %> - <% end %> -
- <%= 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 %> \ No newline at end of file diff --git a/app/views/admin/object_auths_new_interface/setting.html.erb b/app/views/admin/object_auths_new_interface/setting.html.erb index f5d17370f..e66330c7c 100644 --- a/app/views/admin/object_auths_new_interface/setting.html.erb +++ b/app/views/admin/object_auths_new_interface/setting.html.erb @@ -27,8 +27,8 @@
<%= content_tag :div do -%> <% form_tag admin_object_auth_ob_auth_path do %> - <%= render :partial => "privilege_user", :locals => {:users => @users_array} %> -
+ <%= render :partial => "layouts/users_checkbox_ary" %> +
<%= submit_tag "Update", :class => 'btn btn-primary' %>
<% end -%> diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index c5719fce4..73b5191ae 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -7,7 +7,7 @@ <%= content_tag :li, :class => (active_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals') || active_for_app_auth('Announcement') || active_for_ob_auths_object("BulletinCategory") ) do -%> <%= link_to content_tag(:i, nil, :class => 'icons-announcement') + t('admin.announcement'), panel_announcement_back_end_bulletins_path %> - <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals')) do -%> + <%= content_tag :ul, :class => ("nav nav-list " + (visible_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals')||active_for_ob_auths_object("BulletinCategory"))) do -%> <%= content_tag :li, link_to(t('announcement.all_articles'), panel_announcement_back_end_bulletins_path), :class => active_for_action('bulletins', 'index') %> <%= content_tag :li, link_to(t('announcement.add_new'), new_panel_announcement_back_end_bulletin_path), :class => active_for_action('bulletins', 'new') %> <%= content_tag :li, link_to(t('announcement.categories'), panel_announcement_back_end_bulletin_categorys_path), :class =>( active_for_action('bulletin_categorys', 'index') || active_for_ob_auths_object("BulletinCategory") ) %> diff --git a/app/views/layouts/_users_checkbox_ary.html.erb b/app/views/layouts/_users_checkbox_ary.html.erb new file mode 100644 index 000000000..92cf8242e --- /dev/null +++ b/app/views/layouts/_users_checkbox_ary.html.erb @@ -0,0 +1,3 @@ +<%= content_tag :div ,:id => "users_checkbox_ary",:class => 'clear' do %> + <%= render :partial => "shared/privilege_user",:collection =>@sys_users,:as=>:user ,:locals =>{ :chosen_users=> @users_array } %> +<%end -%> \ No newline at end of file diff --git a/app/views/shared/_privilege_user.html.erb b/app/views/shared/_privilege_user.html.erb new file mode 100644 index 000000000..9d49be356 --- /dev/null +++ b/app/views/shared/_privilege_user.html.erb @@ -0,0 +1,16 @@ +
+ + <%= content_tag :div,:data=>{'original-title'=>t('announcement.bulletin.approval_setting_window_title'),:content => user.cache_dept[I18n.locale.to_s]},:class=>"checkbox clear" do %> +
+
+
+ <% if user.avatar? %> + <%= image_tag(user.avatar.thumb.url,:class => "member-img") %> + <% else %> + <%= image_tag "person.png",:class => "member-img" %> + <% end %> +
+ <%= label_tag "lab-user-#{user.id}", (user.name rescue ''),:class=>"member-name",:id=>nil -%> + <%= check_box_tag "[users][#{user.id}]", 'true',chosen_users.include?(user),:class => "check" -%> + <%end %> +
diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb index 22c3a6dd5..a41c27acf 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb @@ -12,7 +12,7 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle # end def setting - @sys_users = User.all(conditions: {admin: false}) + @sys_users = User.all(conditions: {admin: false}).includes(:avatar) @bulletin_categorys = BulletinCategory.all @options_from_collection_for_select_bulletin_categorys = @bulletin_categorys.collect{|bc| [bc.i18n_variable[I18n.locale],bc.id] } if params.has_key? :category diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/_privilege_user.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/_privilege_user.html.erb deleted file mode 100644 index 90f5cb65b..000000000 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/_privilege_user.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -<%= 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 %> -
-
-
- <% if sys_user.avatar? %> - <%= image_tag(sys_user.avatar.thumb.url,:class => "member-img") %> - <% else %> - <%= image_tag "person.png",:class => "member-img" %> - <% end %> -
- <%= 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 -%> \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/setting.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/setting.html.erb index 57d3105b1..4dfa549e6 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/setting.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/setting.html.erb @@ -24,7 +24,7 @@
<%= content_tag :div do -%> <% form_tag panel_announcement_back_end_approval_setting_path do %> - <%= render :partial => "privilege_user", :locals => {:users => @users_array} %> + <%= render :partial => "layouts/users_checkbox_ary" %>
<%= submit_tag "Update", :class => 'btn btn-primary' %>
diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/setting.js.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/setting.js.erb index 0ca148da1..7eb41c72a 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/setting.js.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/setting.js.erb @@ -1,2 +1,2 @@ -$("#users_checkbox_ary").replaceWith('<%= escape_javascript(render :partial => "privilege_user", :locals => {:users => @users_array})%>'); +$("#users_checkbox_ary").replaceWith('<%= escape_javascript(render :partial=> "layouts/users_checkbox_ary" )%>'); permissionCheckbox(); \ No newline at end of file diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_approvals_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_approvals_controller.rb index 3eb3e9c04..0f10fe91f 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_approvals_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_approvals_controller.rb @@ -12,7 +12,7 @@ class Panel::News::BackEnd::NewsApprovalsController < OrbitBackendController end def setting - @sys_users = User.all(conditions: {admin: false}) + @sys_users = User.all(conditions: {admin: false}).includes(:avatar) @news_bulletin_categorys = NewsBulletinCategory.all @options_from_collection_for_select_news_bulletin_categorys = @news_bulletin_categorys.collect{|bc| [bc.i18n_variable[I18n.locale],bc.id] } if params.has_key? :news_category diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/_privilege_user.html.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/_privilege_user.html.erb deleted file mode 100644 index 60c5a7823..000000000 --- a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/_privilege_user.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -<%= content_tag :div ,:id => "users_checkbox_ary",:class => 'clear' do -%> - <% @sys_users.each do |user| -%> - -
- - <% user.sub_roles.each do |sr| %> - - <% end %> - <%= content_tag :div,:data=>{'original-title'=>t('news.news_bulletin.approval_setting_window_title'),:content => "#{user.sub_roles.collect{|sr| sr.i18n_variable[I18n.locale]}.join(',')}"},:class=>"checkbox clear" do %> -
-
-
- <% if user.avatar? %> - <%= image_tag(user.avatar.thumb.url,:class => "member-img") %> - <% else %> - <%= image_tag "person.png",:class => "member-img" %> - <% end %> -
- <%= label_tag "lab-user-#{user.id}", (user.name rescue ''),:class=>"member-name",:id=>nil -%> - <%= check_box_tag "[users][#{user.id}]", 'true',users.include?(user),:class => "check" -%> - <%end -%> -
- - <% end -%> -<% end -%> \ No newline at end of file diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/setting.html.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/setting.html.erb index 298e21eb7..c8e9c3142 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/setting.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/setting.html.erb @@ -24,7 +24,7 @@
<%= content_tag :div do -%> <% form_tag panel_news_back_end_approval_setting_path do %> - <%= render :partial => "privilege_user", :locals => {:users => @users_array} %> + <%= render :partial => "layouts/users_checkbox_ary" %>
<%= submit_tag "Update", :class => 'btn btn-primary' %>
diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/setting.js.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/setting.js.erb index 0ca148da1..7eb41c72a 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/setting.js.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/setting.js.erb @@ -1,2 +1,2 @@ -$("#users_checkbox_ary").replaceWith('<%= escape_javascript(render :partial => "privilege_user", :locals => {:users => @users_array})%>'); +$("#users_checkbox_ary").replaceWith('<%= escape_javascript(render :partial=> "layouts/users_checkbox_ary" )%>'); permissionCheckbox(); \ No newline at end of file