diff --git a/lib/orbit_core_lib.rb b/lib/orbit_core_lib.rb index 5c32e507..8aea2b8c 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 238cbb6c..68671003 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 8bc390eb..630779d1 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 4d93cc13..dea2fc17 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 9cb29038..40664262 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 d77927e5..7e1195e9 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 177773d1..b8ab3f2c 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 817fc7bd..fdcb0058 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 27d310ba..a2733a8b 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 e1b4174c..5005f617 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