From 86a4a6cbe24f370c01746d715a771f2d46fc15aa Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Fri, 22 Jun 2012 14:32:28 +0800 Subject: [PATCH 01/32] put ldap setting into config file. should load be rails env. Also make god config more friendly. --- config/initializers/load_config.rb | 1 + config/initializers/nccu_ldap_connection.rb | 17 ++++------------- config/ldap.yml | 12 ++++++++++++ config/resque.god | 16 +++++++++++++--- 4 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 config/ldap.yml diff --git a/config/initializers/load_config.rb b/config/initializers/load_config.rb index e6874293..0d22eac8 100644 --- a/config/initializers/load_config.rb +++ b/config/initializers/load_config.rb @@ -1 +1,2 @@ APP_CONFIG = YAML.load_file("#{Rails.root}/config/config.yml")[Rails.env] +LDAP_CONFIG = YAML.load_file("#{Rails.root}/config/ldap.yml")[Rails.env] \ No newline at end of file diff --git a/config/initializers/nccu_ldap_connection.rb b/config/initializers/nccu_ldap_connection.rb index 35e9ded8..00e03367 100644 --- a/config/initializers/nccu_ldap_connection.rb +++ b/config/initializers/nccu_ldap_connection.rb @@ -6,20 +6,11 @@ $nccu_ldap_connection module NccuLdapConnection BASE = 'ou=People,dc=nccu,dc=edu,dc=tw' - @ldap_host = { - :host => '127.0.0.1', #140.119.166.23 or 127.0.0.1 - :port => 8001, #389 or 8001 - # :filter => "(uid=#{login_uid})", - # :base => "ou=People,dc=nccu,dc=edu,dc=tw", - :authenticate_info => "cn=uccn,ou=profile,dc=nccu,dc=edu,dc=tw", - :authenticate_pwd => "nccu2ucc" - } - def self.establish - $nccu_ldap_connection = Net::LDAP.new - $nccu_ldap_connection.port = @ldap_host[:port] - $nccu_ldap_connection.host = @ldap_host[:host] - $nccu_ldap_connection.authenticate(@ldap_host[:authenticate_info],@ldap_host[:authenticate_pwd]) + $nccu_ldap_connection = Net::LDAP.new + $nccu_ldap_connection.port =LDAP_CONFIG["port"] + $nccu_ldap_connection.host = LDAP_CONFIG["host"] + $nccu_ldap_connection.authenticate(LDAP_CONFIG["authenticate_info"],LDAP_CONFIG["authenticate_pwd"]) end end \ No newline at end of file diff --git a/config/ldap.yml b/config/ldap.yml new file mode 100644 index 00000000..5c48fc1a --- /dev/null +++ b/config/ldap.yml @@ -0,0 +1,12 @@ +defaults: &defaults + authenticate_info: 'cn=uccn,ou=profile,dc=nccu,dc=edu,dc=tw' + authenticate_pwd: 'nccu2ucc' + +development: + <<: *defaults + host: '127.0.0.1' + port: 8001 +production: + <<: *defaults + host: '140.119.166.23' + port: 389 diff --git a/config/resque.god b/config/resque.god index 6f331dd8..80da5abe 100644 --- a/config/resque.god +++ b/config/resque.god @@ -1,7 +1,14 @@ +#developer pls change here +default_uid = 'kaito' +default_gid = 'staff' + rails_env = 'development' #ENV['RAILS_ENV'] || "production" -rails_root = ENV['RAILS_ROOT'] || "/Users/kaito/Documents/MyWorkspeace/NCCU" + + +rails_root = ENV['RAILS_ROOT'] || File.expand_path("..",File.dirname(__FILE__)) num_workers = rails_env == 'production' ? 5 : 2 + num_workers.times do |num| God.watch do |w| w.dir = "#{rails_root}" @@ -12,8 +19,11 @@ num_workers.times do |num| # w.env = {"QUEUE"=>"critical,high,low", "RAILS_ENV"=>rails_env} w.start = "rake -f #{rails_root}/Rakefile resque:work QUEUE=* RAILS_ENV=#{rails_env}" - w.uid = 'kaito' - w.gid = 'staff' + w.uid = rails_env == 'production' ? nccu : default_uid + w.gid = rails_env == 'production' ? nccu : default_gid + + + w.log = "#{rails_root}/log/god.log" # restart if memory gets too high w.transition(:up, :restart) do |on| From a36f73bafccf997d111596ddd84249ccf348d14e Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Fri, 22 Jun 2012 18:19:40 +0800 Subject: [PATCH 02/32] =?UTF-8?q?fix=200621=20Trello:"171=20=E9=A0=81?= =?UTF-8?q?=E9=9D=A2=E7=AE=A1=E7=90=86=E4=B8=8D=E8=83=BD=E4=BD=BF=E7=94=A8?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shared/_privilege_user.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/shared/_privilege_user.html.erb b/app/views/shared/_privilege_user.html.erb index 9d49be35..ba68996f 100644 --- a/app/views/shared/_privilege_user.html.erb +++ b/app/views/shared/_privilege_user.html.erb @@ -1,6 +1,6 @@
- - <%= 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 %> + + <%= content_tag :div,:data=>{'original-title'=>t('announcement.bulletin.approval_setting_window_title'),:content => (user.cache_dept[I18n.locale.to_s] rescue '')},:class=>"checkbox clear" do %>
From ffd95ee1fd4e997957722077b4909b9110941f24 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Mon, 25 Jun 2012 16:23:16 +0800 Subject: [PATCH 03/32] =?UTF-8?q?fix=20=E6=96=B0=E8=81=9E=E8=88=87?= =?UTF-8?q?=E5=85=AC=E5=91=8AQA-=E6=AC=8A=E9=99=90=E8=A8=AD=E5=AE=9A--?= =?UTF-8?q?=E5=84=AA=E5=85=88=E8=99=95=E7=90=863.=E4=B8=80=E8=88=AC?= =?UTF-8?q?=E7=99=BC=E4=BD=88=E6=96=B0=E8=81=9E&=E5=85=AC=E5=91=8A?= =?UTF-8?q?=E4=BA=BA=EF=BC=8C=E6=87=89=E8=A9=B2=E5=8F=AA=E8=83=BD=E7=9C=8B?= =?UTF-8?q?=E5=88=B0=E8=87=AA=E5=B7=B1=E7=99=BC=E4=BD=88=E7=9A=84=E6=96=B0?= =?UTF-8?q?=E8=81=9E&=E5=85=AC=E5=91=8A=EF=BC=8C=E4=BD=86=E6=98=AF?= =?UTF-8?q?=E7=9B=AE=E5=89=8D=E5=8F=AF=E4=BB=A5=E7=9C=8B=E5=88=B0=E5=85=A8?= =?UTF-8?q?=E9=83=A8=EF=BC=8C=E8=80=8C=E4=B8=94=E5=8F=AF=E4=BB=A5=E5=88=AA?= =?UTF-8?q?=E9=99=A4=E5=85=B6=E4=BB=96=E4=BA=BA=E7=9A=84=E5=85=AC=E5=91=8A?= =?UTF-8?q?.=E8=87=B3=E5=B0=91=E8=A6=81=E4=B8=8D=E8=83=BD=E5=88=AA?= =?UTF-8?q?=E9=99=A4=E5=88=A5=E4=BA=BA=E7=9A=84=E5=85=AC=E5=91=8A=20?= =?UTF-8?q?=E6=96=B0=E8=81=9E=E8=88=87=E5=85=AC=E5=91=8AQA-=E7=B7=A8?= =?UTF-8?q?=E8=BC=AF=E5=95=8F=E9=A1=8C-=E7=99=BC=E4=BD=88=E6=96=B0?= =?UTF-8?q?=E8=81=9E=E6=99=82=EF=BC=8C=E7=99=BC=E4=BD=88=E5=96=AE=E4=BD=8D?= =?UTF-8?q?=E9=A0=90=E8=A8=AD=E7=82=BA=E8=AB=8B=E9=81=B8=E6=93=87=20?= =?UTF-8?q?=E6=96=B0=E8=81=9E=E8=88=87=E5=85=AC=E5=91=8AQA-=E7=B7=A8?= =?UTF-8?q?=E8=BC=AF=E5=95=8F=E9=A1=8C-=E5=85=AC=E5=91=8A=E6=A8=A1?= =?UTF-8?q?=E7=B5=84=E8=AB=8B=E7=A7=BB=E9=99=A4=20Subtitle=20=E6=AC=84?= =?UTF-8?q?=E4=BD=8D=20put=20rb-readline=20only=20in=20Linux=20make=20app?= =?UTF-8?q?=5Fmanager=20destroy=20after=20user=20deletion.=20=20=20may=20n?= =?UTF-8?q?eed=20to=20run:=20=20AppManager.all.collect{|am|=20=20am=20if?= =?UTF-8?q?=20am.user.nil=3F=20}.delete=5Fif=20{|x|=20x=20=3D=3D=20nil}.ea?= =?UTF-8?q?ch{|am|=20am.destroy}=20for=20clean=20up=20DB.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 3 ++- Gemfile.lock | 2 -- app/models/app_manager.rb | 2 +- app/models/module_app.rb | 6 +++--- app/models/user/user.rb | 6 +++--- app/views/layouts/_side_bar.html.erb | 4 ++-- config/resque.god | 8 ++++---- .../announcement/back_end/bulletins_helper.rb | 6 ++++++ .../back_end/bulletins/_bulletin.html.erb | 8 ++++---- .../back_end/bulletins/_form.html.erb | 15 ++++----------- .../announcement/config/locales/zh_tw.yml | 1 + .../panel/news/back_end/news_bulletins_helper.rb | 6 ++++++ .../news/back_end/news_bulletins/_form.html.erb | 12 ++++++------ .../news_bulletins/_news_bulletin.html.erb | 2 ++ .../built_in_modules/news/config/locales/en.yml | 1 + .../news/config/locales/zh_tw.yml | 4 ++++ 16 files changed, 49 insertions(+), 37 deletions(-) diff --git a/Gemfile b/Gemfile index 6eccd600..ca660050 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,6 @@ gem 'rake' gem 'resque' # background jobs gem 'resque-scheduler' # job scheduling gem 'resque-restriction' -gem 'rb-readline' gem 'ruby-debug19' gem 'rubyzip' gem 'therubyracer' @@ -34,6 +33,8 @@ gem 'sinatra' gem 'sprockets' gem 'tinymce-rails' gem 'therubyracer' if RUBY_PLATFORM.downcase.include?("linux") +gem 'rb-readline' if RUBY_PLATFORM.downcase.include?("linux") + gem "impressionist", :require => "impressionist", :path => "vendor/impressionist" diff --git a/Gemfile.lock b/Gemfile.lock index e21da804..776d0b32 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -168,7 +168,6 @@ GEM rdoc (~> 3.4) thor (~> 0.14.6) rake (0.9.2.2) - rb-readline (0.4.2) rdoc (3.12) json (~> 1.4) redis (2.2.2) @@ -302,7 +301,6 @@ DEPENDENCIES radius rails (>= 3.1.0, < 3.2.0) rake - rb-readline resque resque-restriction resque-scheduler diff --git a/app/models/app_manager.rb b/app/models/app_manager.rb index 46cbbb91..0d81a0ec 100644 --- a/app/models/app_manager.rb +++ b/app/models/app_manager.rb @@ -1,7 +1,7 @@ class AppManager include Mongoid::Document include Mongoid::Timestamps - + belongs_to :user belongs_to :managing_app, :polymorphic => true #,:class_name => 'ModuleApp',:inverse_of => :managers,:foreign_key => "user_id" diff --git a/app/models/module_app.rb b/app/models/module_app.rb index 7ad4ac1d..9708316f 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -4,7 +4,7 @@ class ModuleApp include OrbitCoreLib::ObjectTokenUnility field :key - field :title + field :title field :version field :organization field :author @@ -16,8 +16,8 @@ class ModuleApp field :app_pages ,type: Array field :widgets ,type: Array - has_many :managers,as: :managing_app ,:class_name => "AppManager" #,:dependent => :destroy,:foreign_key => "managing_app_id",:inverse_of => :managing_app - has_many :sub_managers,as: :sub_managing_app ,:class_name => "AppManager"#, :dependent => :destroy,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app + has_many :managers,as: :managing_app ,:class_name => "AppManager" ,:dependent => :destroy#,:foreign_key => "managing_app_id",:inverse_of => :managing_app + has_many :sub_managers,as: :sub_managing_app ,:class_name => "AppManager", :dependent => :destroy#,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app has_many :tags has_many :page_parts diff --git a/app/models/user/user.rb b/app/models/user/user.rb index 7c1e4c63..4f820c16 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -17,10 +17,10 @@ class User 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" - has_many :privilege_apps, :inverse_of => :privilege_users, :class_name => "AppAuth" + has_many :blocked_apps, :inverse_of => :blocked_users, :class_name => "AppAuth", :dependent => :destroy + has_many :privilege_apps, :inverse_of => :privilege_users, :class_name => "AppAuth", :dependent => :destroy - has_many :managing_apps,:class_name => "AppManager" + has_many :managing_apps,:class_name => "AppManager", :dependent => :destroy belongs_to :role has_and_belongs_to_many :sub_roles diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index 73b5191a..26925aee 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -12,7 +12,7 @@ <%= 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") ) %> <%= content_tag :li, link_to(t('announcement.tags'), panel_announcement_back_end_tags_path), :class => active_for_action('/panel/announcement/back_end/tags', 'index') %> - <%= content_tag :li, link_to(t('announcement.bulletin.approval_setting'), panel_announcement_back_end_approval_setting_path), :class => active_for_action('approvals', 'setting') if (is_manager? rescue nil) %> + <%= content_tag :li, link_to(t('announcement.bulletin.approval_setting'), panel_announcement_back_end_approval_setting_path), :class => active_for_action('approvals', 'setting') if (is_manager? rescue true) %> <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: "Announcement"}))), :class => active_for_app_auth('Announcement') if (is_admin? rescue nil) %> <% end -%> @@ -26,7 +26,7 @@ <%= content_tag :li, link_to(t('announcement.add_new'), new_panel_news_back_end_news_bulletin_path), :class => active_for_action('news_bulletins', 'new') %> <%= content_tag :li, link_to(t('announcement.categories'), panel_news_back_end_news_bulletin_categorys_path), :class => active_for_action('news_bulletin_categorys', 'index') || active_for_ob_auths_object("NewsBulletinCategory") %> <%= content_tag :li, link_to(t('announcement.tags'), panel_news_back_end_tags_path), :class => active_for_action('/panel/news/back_end/tags', 'index') %> - <%= content_tag :li, link_to(t('announcement.bulletin.approval_setting'), panel_news_back_end_approval_setting_path), :class => active_for_action('news_approvals', 'setting') if (is_manager? rescue nil) %> + <%= content_tag :li, link_to(t('announcement.bulletin.approval_setting'), panel_news_back_end_approval_setting_path), :class => active_for_action('news_approvals', 'setting') if (is_manager? rescue true) %> <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {key: "news"}))), :class => active_for_app_auth('news') if (is_admin? rescue nil) %> <% end -%> diff --git a/config/resque.god b/config/resque.god index 80da5abe..aa9cb0b4 100644 --- a/config/resque.god +++ b/config/resque.god @@ -2,7 +2,7 @@ default_uid = 'kaito' default_gid = 'staff' -rails_env = 'development' #ENV['RAILS_ENV'] || "production" +rails_env = ENV['RAILS_ENV'] || "production" rails_root = ENV['RAILS_ROOT'] || File.expand_path("..",File.dirname(__FILE__)) @@ -17,10 +17,10 @@ num_workers.times do |num| w.interval = 30.seconds p "/usr/bin/rake -f #{rails_root}/Rakefile resque:work QUEUE=* RAILS_ENV=#{rails_env}" # w.env = {"QUEUE"=>"critical,high,low", "RAILS_ENV"=>rails_env} - w.start = "rake -f #{rails_root}/Rakefile resque:work QUEUE=* RAILS_ENV=#{rails_env}" + w.start = "rake -f #{rails_root}/Rakefile resque:work QUEUE=* RAILS_ENV=#{rails_env} -P /var/godgod.#{port}.pid" - w.uid = rails_env == 'production' ? nccu : default_uid - w.gid = rails_env == 'production' ? nccu : default_gid + w.uid = rails_env == 'production' ? "nccu" : default_uid + w.gid = rails_env == 'production' ? "nccu" : default_gid w.log = "#{rails_root}/log/god.log" diff --git a/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb b/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb index c384bc8f..49f24079 100644 --- a/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb +++ b/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb @@ -6,4 +6,10 @@ module Panel::Announcement::BackEnd::BulletinsHelper by_bulletin and by_user end + def show_delete_link(bulletin) + by_bulletin = (bulletin.create_user_id == current_user.id) + by_user = (is_manager? or is_admin?) + by_bulletin or by_user + end + end \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb index 8f879e79..afb57306 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb @@ -48,12 +48,12 @@
  • <%= link_to t(:file), load_quick_edit_panel_announcement_back_end_bulletin_path(bulletin, :type => 'files'), :remote => true %>
  • - <%#= debugger %> - <%#= a=1 %> - <% end %> - + <% end -%> + <% if show_delete_link(bulletin) %> + + <% end %> <% if show_approval_link(bulletin) %>
  • <%= link_to t('announcement.bulletin.approval'), panel_announcement_back_end_bulletin_approval_preview_path(bulletin),:class => 'preview_trigger' %>
  • <%#= #TODO add ancher so user can quick access into that part %> <% end %> diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb index c515dc65..c7f544e6 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb @@ -123,7 +123,7 @@ <%#= f.label :unit_list_for_anc%> <%#= f.select :unit_list_for_anc_id,@unit_list_for_anc.collect{|t| [ t.title[I18n.locale], t.id ]}, {}, :class => "input-medium" %> - <%= f.label :category %> + <%= f.label :category,t('announcement.bulletin.category')%> <%= f.select :bulletin_category_id, @bulletin_categorys.collect{|t| [ t.i18n_variable[I18n.locale], t.id ]}, {}, :class => "input-medium" %>