From faabedad5590b03ca5201bc626f320d820d77078 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 17 Sep 2013 20:44:00 +0800 Subject: [PATCH] Do not show announcement in json and rss if no title in I18n.locale --- .../back_end/bulletins_controller.rb | 27 ++++++++++--------- .../bulletins/get_bulletins.rss.builder | 14 +++++----- 2 files changed, 23 insertions(+), 18 deletions(-) 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 cd8fb2f23..f0d8f496b 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 @@ -332,18 +332,21 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController respond_to do |format| format.json { custom_bulletins = @bulletins.inject([]) do |data, bulletin| - deadline = bulletin.deadline.nil? ? t(:no_deadline) : display_date_time(bulletin.deadline) - image_url = "#{'/' unless bulletin.image.url.start_with?('/')}#{bulletin.image.url}" - data << { - title: bulletin.title, - link: "#{request.protocol}#{request.host_with_port}#{panel_announcement_front_end_bulletin_path(bulletin, category_id: bulletin.bulletin_category.id, locale: I18n.locale)}", - image: "#{request.protocol}#{request.host_with_port}#{image_url}", - category: bulletin.bulletin_category.title, - content: bulletin.text, - postdate: display_date_time(bulletin.postdate), - deadline: deadline, - tag: bulletin.sorted_tags.map{|tag| tag.name} - } + unless bulletin.title_translations[I18n.locale.to_s].blank? + deadline = bulletin.deadline.nil? ? t(:no_deadline) : display_date_time(bulletin.deadline) + image_url = "#{'/' unless bulletin.image.url.start_with?('/')}#{bulletin.image.url}" + data << { + title: bulletin.title, + link: "#{request.protocol}#{request.host_with_port}#{panel_announcement_front_end_bulletin_path(bulletin, category_id: bulletin.bulletin_category.id, locale: I18n.locale)}", + image: "#{request.protocol}#{request.host_with_port}#{image_url}", + category: bulletin.bulletin_category.title, + content: bulletin.text, + postdate: display_date_time(bulletin.postdate), + deadline: deadline, + tag: bulletin.sorted_tags.map{|tag| tag.name} + } + end + data end render json: JSON.pretty_generate(custom_bulletins) } diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/get_bulletins.rss.builder b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/get_bulletins.rss.builder index aa7c1e5be..ca9795632 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/get_bulletins.rss.builder +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/get_bulletins.rss.builder @@ -9,12 +9,14 @@ xml.rss :version => "2.0" do xml.link "#{request.protocol}#{request.host_with_port}#{get_bulletins_panel_announcement_back_end_bulletins_path(bulletin_category_id: @category.try(:id))}.rss" @bulletins.each do |bulletin| - xml.item do - xml.title bulletin.title - xml.pubDate bulletin.postdate.to_s(:rfc822) - xml.description bulletin.text - xml.link "#{request.protocol}#{request.host_with_port}#{panel_announcement_front_end_bulletin_path(bulletin, category_id: bulletin.bulletin_category.id, locale: I18n.locale)}" - xml.guid "#{request.protocol}#{request.host_with_port}#{panel_announcement_front_end_bulletin_path(bulletin)}" + unless bulletin.title_translations[I18n.locale.to_s].blank? + xml.item do + xml.title bulletin.title + xml.pubDate bulletin.postdate.to_s(:rfc822) + xml.description bulletin.text + xml.link "#{request.protocol}#{request.host_with_port}#{panel_announcement_front_end_bulletin_path(bulletin, category_id: bulletin.bulletin_category.id, locale: I18n.locale)}" + xml.guid "#{request.protocol}#{request.host_with_port}#{panel_announcement_front_end_bulletin_path(bulletin)}" + end end end end