From c5fdff764e8bd574e4261800533a6b420cdc7318 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Thu, 5 Jul 2012 16:00:45 +0800 Subject: [PATCH] orbit disable object for categories --- app/controllers/sessions_controller.rb | 4 ++-- app/helpers/orbit_backend_helper.rb | 4 ++++ config/locales/zh_tw.yml | 4 ++++ lib/orbit_controller_lib.rb | 11 +++++++++ lib/orbit_core_lib.rb | 15 ++++++++++++ .../back_end/bulletin_categorys_controller.rb | 3 ++- .../back_end/bulletins_controller.rb | 7 ++++-- .../widget/bulletins_controller.rb | 2 +- .../back_end/bulletin_categorys_helper.rb | 4 ---- .../app/models/bulletin_category.rb | 11 ++------- .../announcement/config/locales/en.yml | 2 +- .../announcement/config/locales/zh_tw.yml | 2 -- .../news_bulletin_categorys_controller.rb | 24 +++++++++++++------ .../back_end/news_bulletins_controller.rb | 24 +++++++++++-------- .../news/app/models/news_bulletin_category.rb | 6 ++--- .../_news_bulletin_category.html.erb | 2 +- .../news_bulletin_categorys/destroy.js.erb | 2 +- .../news/config/locales/zh_tw.yml | 4 ++++ .../app/models/web_link_category.rb | 2 +- .../_web_link_category.html.erb | 2 +- 20 files changed, 89 insertions(+), 46 deletions(-) create mode 100644 lib/orbit_controller_lib.rb diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 23a89c38..748c225c 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,8 +1,6 @@ class SessionsController < Devise::SessionsController prepend_before_filter :require_no_authentication, :only => [ :new, :create ] include Devise::Controllers::InternalHelpers - MiddleSiteConnection.establish - NccuLdapConnection.establish # POST /resource/sign_in def create @@ -13,6 +11,8 @@ class SessionsController < Devise::SessionsController result = false ldap_filter = "(uid=#{login_uid})" if /@rulingcom.com$/.match(login_uid).nil? + MiddleSiteConnection.establish + NccuLdapConnection.establish if ($nccu_ldap_connection.bind rescue false) logger.info "=LDAP Binded password ok..." diff --git a/app/helpers/orbit_backend_helper.rb b/app/helpers/orbit_backend_helper.rb index 5d47e414..e2865b9f 100644 --- a/app/helpers/orbit_backend_helper.rb +++ b/app/helpers/orbit_backend_helper.rb @@ -42,4 +42,8 @@ module OrbitBackendHelper end end + def show_toggle_archive_btn(object) + object.disable ? t("object_disable.change_to_false") : t("object_disable.change_to_true") + end + end \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 930f5902..09877234 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -511,3 +511,7 @@ zh_tw: sys: not_previewable: "不支援預覽" limit_of_upload_file_size: "上傳檔案大小限制: %{best_size}" + + object_disable: + change_to_true: "設為停用" + change_to_false: "重新啓用" \ No newline at end of file diff --git a/lib/orbit_controller_lib.rb b/lib/orbit_controller_lib.rb new file mode 100644 index 00000000..c0e7031c --- /dev/null +++ b/lib/orbit_controller_lib.rb @@ -0,0 +1,11 @@ +module OrbitControllerLib + module DivisionForDisable + def get_disable_object_by_user(object_class) + if is_admin? or is_manager? + object_class.admin_manager_all + else + object_class.all + end + end + end +end diff --git a/lib/orbit_core_lib.rb b/lib/orbit_core_lib.rb index 8e333b7e..2c24c82f 100644 --- a/lib/orbit_core_lib.rb +++ b/lib/orbit_core_lib.rb @@ -1,4 +1,19 @@ module OrbitCoreLib + module ObjectDisable + def self.included(base) + + base.instance_eval("field :disable,type: Boolean,:default => false") + base.instance_eval("scope :all,where(disable: false)") + base.instance_eval("scope :admin_manager_all,find(:all)") + base.define_singleton_method :find do |*args| + if args ==[:all] + unscoped + else + unscoped.find(args) + end + end + end + end module ObjectAuthable def self.included(base) base.instance_eval("has_many :object_auths,as: :obj_authable,dependent: :delete") diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb index 9ba78b90..e3fe50bc 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb @@ -1,9 +1,10 @@ class Panel::Announcement::BackEnd::BulletinCategorysController < OrbitBackendController - + include OrbitControllerLib::DivisionForDisable before_filter :for_app_manager,:except => [:index] def index @bulletin_categorys = BulletinCategory.all + #TODO 需要做 manager ,admin 才可以 all. 其他 available就好 @bulletin_category = BulletinCategory.new(:display => 'List') @url = panel_announcement_back_end_bulletin_categorys_path diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index 1b6b4336..40a6ff18 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -39,6 +39,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # @bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered_bulletins : Bulletin.all.page(params[:page]).per(10) @bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered("bulletin") : get_viewable("bulletin") @bulletin_categories = BulletinCategory.all + #TODO 需要做 manager ,admin 才可以 all. 其他 available就好 @bulletin_link = BulletinLink.new @link_url = panel_announcement_back_end_bulletins_path @@ -301,6 +302,8 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController @bulletin = Bulletin.find(params[:id]) @type = params[:type] @bulletin_categories = BulletinCategory.all + #TODO 需要做 manager ,admin 才可以 all. 其他 available就好 + get_tags end @@ -328,9 +331,9 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController @bulletin_categorys = [] #@unit_list_for_anc = UnitListForAnc.all if(is_manager? || is_admin?) - @bulletin_categorys = (id ? BulletinCategory.available.find(id).to_a : BulletinCategory.available) + @bulletin_categorys = (id ? BulletinCategory.all.find(id).to_a : BulletinCategory.all) elsif is_sub_manager? - @bulletin_categorys = BulletinCategory.available.authed_for_user(current_user,'submit') + @bulletin_categorys = BulletinCategory.all.authed_for_user(current_user,'submit') end if @bulletin_categorys.empty? && params[:action] != "index" flash[:alert] = t("announcement.error.no_avilb_cate_for_posting") diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb index dbd8844f..8a39862b 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb @@ -52,7 +52,7 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController protected def get_categorys - @bulletin_categorys = BulletinCategory.excludes('disabled' => true) + @bulletin_categorys = BulletinCategory.all end end diff --git a/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletin_categorys_helper.rb b/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletin_categorys_helper.rb index ea413b54..92604985 100644 --- a/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletin_categorys_helper.rb +++ b/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletin_categorys_helper.rb @@ -13,8 +13,4 @@ include ActionView::Helpers::UrlHelper link_to t('announcement.bulletin.cate_auth'),admin_object_auth_ob_auth_path(oa) end - def show_toggle_archive_btn(bulletin_category) - bulletin_category.disable ? t("bulletin_category.disable_change_to_true") : t("bulletin_category.disable_change_to_false") - end - end \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/models/bulletin_category.rb b/vendor/built_in_modules/announcement/app/models/bulletin_category.rb index a5686cc1..2f25c888 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin_category.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin_category.rb @@ -4,7 +4,8 @@ class BulletinCategory include Mongoid::Document include Mongoid::Timestamps include OrbitCoreLib::ObjectAuthable - + include OrbitCoreLib::ObjectDisable + ObjectAuthTitlesOptions = %W{submit_new fact_check} AfterObjectAuthUrl = '/panel/announcement/back_end/bulletin_categorys' # include Mongoid::MultiParameterAttributes @@ -20,15 +21,7 @@ class BulletinCategory has_many :bulletins - scope :available,where(disable: false) - def self.find(*args) - if args ==[:all] - unscoped - else - unscoped.find(args) - end - end def pp_object i18n_variable[I18n.locale] diff --git a/vendor/built_in_modules/announcement/config/locales/en.yml b/vendor/built_in_modules/announcement/config/locales/en.yml index 5e60f17b..3d941335 100644 --- a/vendor/built_in_modules/announcement/config/locales/en.yml +++ b/vendor/built_in_modules/announcement/config/locales/en.yml @@ -92,7 +92,7 @@ en: update_success: Bulletin Category Updated update_failed: Bulletin Category Failed disable_change_to_false: Toggle to archive - disable_change_to_true: Pu back from archive + disable_change_to_true: Put back from archive # admin: # action: Action # add_language: Add language diff --git a/vendor/built_in_modules/announcement/config/locales/zh_tw.yml b/vendor/built_in_modules/announcement/config/locales/zh_tw.yml index 6aa1d15b..55931284 100644 --- a/vendor/built_in_modules/announcement/config/locales/zh_tw.yml +++ b/vendor/built_in_modules/announcement/config/locales/zh_tw.yml @@ -181,8 +181,6 @@ zh_tw: delete: 刪除 update_success: 分類更新成功 update_failed: 分類更新失敗 - disable_change_to_false: 設為停用 - disable_change_to_true: 重新啓用 # Chinese (Taiwan) translations for Ruby on Rails # by tsechingho (http://github.com/tsechingho) diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletin_categorys_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletin_categorys_controller.rb index e3ac7476..1b54c799 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletin_categorys_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletin_categorys_controller.rb @@ -4,7 +4,9 @@ class Panel::News::BackEnd::NewsBulletinCategorysController < OrbitBackendContro def index - @news_bulletin_categorys = NewsBulletinCategory.all + @news_bulletin_categorys = get_disable_object_by_user(NewsBulletinCategory) + #TODO 需要做 manager ,admin 才可以 all. 其他 available就好 + @news_bulletin_category = NewsBulletinCategory.new(:display => 'List') @url = panel_news_back_end_news_bulletin_categorys_path @@ -108,13 +110,21 @@ class Panel::News::BackEnd::NewsBulletinCategorysController < OrbitBackendContro # DELETE /news_bulletins/1 # DELETE /news_bulletins/1.xml def destroy - @news_bulletin_category = NewsBulletinCategory.find(params[:id]) - @news_bulletin_category.destroy + @news_bulletin_category = NewsBulletinCategory.find(params[:id]).first + @news_bulletin_category.disable = @news_bulletin_category.disable ? false : true + + if @news_bulletin_category.save! + respond_to do |format| + flash[:notice] = t("bulletin_category.update_success") + # flash[:error] += @bulletin_category.disable ? t("bulletin_category.disable_change_to_true") : t("bulletin_category.disable_change_to_false") + format.html { redirect_to(panel_announcement_back_end_news_bulletin_categorys_url) } + # format.xml { head :ok } + format.js + end + else + flash[:error] = t("bulletin_category.update_failed") + format.html { render :action => "index" } - respond_to do |format| - format.html { redirect_to(panel_news_back_end_news_bulletin_categorys_url) } - # format.xml { head :ok } - format.js end end end diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb index b8fa7cc8..7e28f717 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb @@ -5,7 +5,8 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController # before_filter :for_admin_only,:only => [:] # before_filter :for_app_manager,:only => [:index,:show,] before_filter :for_app_sub_manager,:except => [:index,:show,:get_sorted_and_filtered_news_bulletins] - + before_filter :get_categorys ,:only => [ :new,:edit,:update] + def index # @news_bulletins = NewsBulletin.all # @news_bulletins = NewsBulletin.desc("postdate desc") @@ -38,6 +39,7 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController # @news_bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered_news_bulletins : NewsBulletin.all.page(params[:page]).per(10) @news_bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered("news_bulletin") : get_viewable("news_bulletin") @news_bulletin_categories = NewsBulletinCategory.all + #TODO 需要做 manager ,admin 才可以 all. 其他 available就好 @news_bulletin_link = NewsBulletinLink.new @link_url = panel_news_back_end_news_bulletins_path @@ -82,15 +84,11 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController # @news_bulletin.news_bulletin_files.build # @news_bulletin.news_bulletin_files.new - if get_categorys.empty? - flash[:alert] = t("announcement.error.no_avilb_cate_for_posting") - redirect_to :action => :index - else + get_tags respond_to do |format| format.html # new.html.erb format.xml { render :xml => @news_bulletin } - end end end @@ -104,7 +102,6 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController @link_url = panel_news_back_end_news_bulletin_path(@news_bulletin) - get_categorys get_tags end end @@ -264,7 +261,7 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController format.xml { head :ok } else get_tags - get_categorys + format.html { render :action => "edit" } format.xml { render :xml => @news_bulletin.errors, :status => :unprocessable_entity } end @@ -303,6 +300,8 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController @news_bulletin = NewsBulletin.find(params[:id]) @type = params[:type] @news_bulletin_categories = NewsBulletinCategory.all + #TODO 需要做 manager ,admin 才可以 all. 其他 available就好 + get_tags end @@ -320,11 +319,16 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController @news_bulletin_categorys = [] @unit_list_for_anc = UnitListForAnc.all if(is_manager? || is_admin?) - @news_bulletin_categorys = (id ? NewsBulletinCategory.find(id).to_a : NewsBulletinCategory.excludes('disabled' => true)) + @news_bulletin_categorys = (id ? NewsBulletinCategory.find(id).to_a : NewsBulletinCategory.all) elsif is_sub_manager? - @news_bulletin_categorys = NewsBulletinCategory.authed_for_user(current_user,'submit') + @news_bulletin_categorys = NewsBulletinCategory.all.authed_for_user(current_user,'submit') end + if @news_bulletin_categorys.empty? && params[:action] != "index" + flash[:alert] = t("news.error.no_avilb_cate_for_posting") + redirect_to :action => :index + end end + def get_tags module_app = ModuleApp.first(:conditions => {:key => 'news'}) diff --git a/vendor/built_in_modules/news/app/models/news_bulletin_category.rb b/vendor/built_in_modules/news/app/models/news_bulletin_category.rb index c1f60e91..79443f82 100644 --- a/vendor/built_in_modules/news/app/models/news_bulletin_category.rb +++ b/vendor/built_in_modules/news/app/models/news_bulletin_category.rb @@ -4,7 +4,8 @@ class NewsBulletinCategory include Mongoid::Document include Mongoid::Timestamps include OrbitCoreLib::ObjectAuthable - + include OrbitCoreLib::ObjectDisable + ObjectAuthTitlesOptions = %W{submit_new fact_check} AfterObjectAuthUrl = '/panel/news/back_end/news_bulletin_categorys' # include Mongoid::MultiParameterAttributes @@ -16,8 +17,7 @@ class NewsBulletinCategory field :display has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy - - has_many :news_bulletins,:dependent => :destroy + has_many :news_bulletins def pp_object i18n_variable[I18n.locale] diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletin_categorys/_news_bulletin_category.html.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletin_categorys/_news_bulletin_category.html.erb index f96f8fb4..4c231c31 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletin_categorys/_news_bulletin_category.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletin_categorys/_news_bulletin_category.html.erb @@ -6,7 +6,7 @@