From ca2c056a079cff92922ff24a322c9ac2cb55d679 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 11 Jul 2012 17:17:44 +0800 Subject: [PATCH] fix for not displaying bulletin at fronted when it's parent category is disable --- lib/orbit_core_lib.rb | 30 +++++++++++++++++++ .../front_end/bulletins_controller.rb | 8 +++-- .../app/models/announcement_tag.rb | 4 +++ .../announcement/app/models/bulletin.rb | 17 ++++++++++- .../announcement/app/models/bulletin_tag.rb | 5 +++- .../back_end/news_bulletins_controller.rb | 2 +- .../front_end/news_bulletins_controller.rb | 9 ++++-- .../news/widget/news_bulletins_controller.rb | 4 +-- .../news/app/models/news_bulletin.rb | 4 ++- .../news/app/models/news_tag.rb | 4 +++ 10 files changed, 77 insertions(+), 10 deletions(-) diff --git a/lib/orbit_core_lib.rb b/lib/orbit_core_lib.rb index 5c32e507f..8aea2b8ca 100644 --- a/lib/orbit_core_lib.rb +++ b/lib/orbit_core_lib.rb @@ -1,4 +1,34 @@ module OrbitCoreLib + module BelongsToCategoryMayDisable + def self.included(base) + base.instance_eval("belongs_to :#{base::BelongsToCategory.to_s}") + base.instance_eval(" + scope :currently_available_by_category, lambda { |category| + check_data = category.to_a.collect{|cate| cate.id} + any_in(#{ base::BelongsToCategory.to_s}_id: check_data) + } + ") + base.instance_eval("scope :admin_manager_all,find(:all)") + # base.instance_eval("scope :all,where(disable: false)") + base.instance_eval(" + scope :all, lambda { + category = base::BelongsToCategory.to_s.classify.constantize.all + check_data = category.to_a.collect{|cate| cate.id} + any_in(#{ base::BelongsToCategory.to_s}_id: check_data) + } + ") + base.class_eval(" + def disable? + #{base::BelongsToCategory.to_s}.disable? + end + ") + end + + + # end + + + end module ObjectDisable def self.included(base) diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb index 238cbb6c9..686710039 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb @@ -29,8 +29,12 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController preview_content else @bulletin = Bulletin.can_display.where(_id: params[:id]).first - impressionist(@bulletin) - get_categorys + unless @bulletin.disable? + impressionist(@bulletin) + get_categorys + else + render :nothing => true, :status => 403 + end end end diff --git a/vendor/built_in_modules/announcement/app/models/announcement_tag.rb b/vendor/built_in_modules/announcement/app/models/announcement_tag.rb index 8bc390ebd..630779d15 100644 --- a/vendor/built_in_modules/announcement/app/models/announcement_tag.rb +++ b/vendor/built_in_modules/announcement/app/models/announcement_tag.rb @@ -8,4 +8,8 @@ class AnnouncementTag < Tag self.bulletins.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort) end + def bulletins + Bulletin.all.any_in(:_id => bulletin_ids) + end + end \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index 4d93cc13e..dea2fc173 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -5,6 +5,10 @@ class Bulletin include Mongoid::Timestamps include Mongoid::MultiParameterAttributes include Impressionist::Impressionable + + BelongsToCategory = :bulletin_category + include OrbitCoreLib::BelongsToCategoryMayDisable + # include NccuSearch scope :searchable,where(:is_checked=>true,:is_hidden=>false,:is_pending=>false) @@ -39,7 +43,7 @@ class Bulletin mount_uploader :image, ImageUploader - belongs_to :bulletin_category + # belongs_to :unit_list_for_anc # embeds_many :bulletin_links, :cascade_callbacks => true @@ -59,6 +63,17 @@ class Bulletin after_save :save_bulletin_files + +# scope :currently_available, lambda { |category, limit| +# # limit ||= 5 +# # { +# # debugger +# # a=1 +# :where => {:bulletin_category_id => bulletin_category_id, :disable => false}#, +# # :limit => limit +# # } +# } + def publish_month published_at.strftime("%B %Y") end diff --git a/vendor/built_in_modules/announcement/app/models/bulletin_tag.rb b/vendor/built_in_modules/announcement/app/models/bulletin_tag.rb index 9cb29038b..406642620 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin_tag.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin_tag.rb @@ -5,7 +5,10 @@ class AnnouncementTag < Tag def get_visible_bulletins(sort = :name) date_now = Time.now - self.bulletins.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort) + self.bulletins.all.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort) end + def bulletins + Bulletin.all.any_in(:_id => bulletin_ids) + end end \ No newline at end of file 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 d77927e51..7e1195e91 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 @@ -264,7 +264,7 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController respond_to do |format| if @news_bulletin.update_attributes(params[:news_bulletin]) # format.html { redirect_to(panel_news_back_end_news_bulletin_url(@news_bulletin), :notice => t('news_bulletin.update_news_bulletin_success')) } - format.html { redirect_to(panel_news_back_end_news_bulletins_url, :notice => t('news_bulletin.update_news_bulletin_success')) } + format.html { redirect_to(panel_news_back_end_news_bulletins_url, :notice => t('news_bulletin.update_success')) } format.js { render 'toggle_enable' } format.xml { head :ok } else diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb index 177773d17..b8ab3f2c1 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb @@ -49,8 +49,13 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController preview_content else @news_bulletin = NewsBulletin.can_display.where(_id: params[:id]).first - impressionist(@news_bulletin) - get_categorys + unless @news_bulletin.disable? + impressionist(@news_bulletin) + get_categorys + else + render :nothing => true, :status => 403 + end + end end diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/widget/news_bulletins_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/widget/news_bulletins_controller.rb index 817fc7bd6..fdcb00587 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/widget/news_bulletins_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/widget/news_bulletins_controller.rb @@ -51,11 +51,11 @@ class Panel::News::Widget::NewsBulletinsController < OrbitWidgetController def home_banner if !params[:category_id].blank? - @news_bulletins = NewsBulletin.can_display.where(:news_bulletin_category_id => params[:category_id]).widget_datas.limit(9) + @news_bulletins = NewsBulletin.all.can_display.where(:news_bulletin_category_id => params[:category_id]).widget_datas.limit(9) elsif !params[:tag_id].blank? @news_bulletins = NewsTag.find(params[:tag_id]).news_bulletins.can_display.widget_datas.limit(9) rescue nil else - @news_bulletins = NewsBulletin.can_display.widget_datas.limit(9) + @news_bulletins = NewsBulletin.all.can_display.widget_datas.limit(9) end get_categorys diff --git a/vendor/built_in_modules/news/app/models/news_bulletin.rb b/vendor/built_in_modules/news/app/models/news_bulletin.rb index 27d310ba7..a2733a8b0 100644 --- a/vendor/built_in_modules/news/app/models/news_bulletin.rb +++ b/vendor/built_in_modules/news/app/models/news_bulletin.rb @@ -5,6 +5,9 @@ class NewsBulletin include Mongoid::Timestamps include Mongoid::MultiParameterAttributes include Impressionist::Impressionable + + BelongsToCategory = :news_bulletin_category + include OrbitCoreLib::BelongsToCategoryMayDisable # include Tire::Model::Search # include Tire::Model::Callbacks # include Redis::Objects @@ -43,7 +46,6 @@ class NewsBulletin mount_uploader :image, ImageUploader - belongs_to :news_bulletin_category belongs_to :unit_list_for_anc # embeds_many :news_bulletin_links, :cascade_callbacks => true diff --git a/vendor/built_in_modules/news/app/models/news_tag.rb b/vendor/built_in_modules/news/app/models/news_tag.rb index e1b4174c7..5005f6179 100644 --- a/vendor/built_in_modules/news/app/models/news_tag.rb +++ b/vendor/built_in_modules/news/app/models/news_tag.rb @@ -8,4 +8,8 @@ class NewsTag < Tag self.news_bulletins.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort) end + def news_bulletins + NewsBulletin.all.any_in(:_id => news_bulletin_ids) + end + end \ No newline at end of file