From 3d38adcb94df3a1387893b548637be3a06706f24 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 20 Jun 2012 18:07:07 +0400 Subject: [PATCH] [issue #428] Added Atom feed to advisories. --- app/controllers/advisories_controller.rb | 6 +++++- app/models/advisory.rb | 1 + app/views/advisories/_feed_partial.haml | 8 ++++++++ app/views/advisories/_packages_info.html.haml | 2 +- app/views/advisories/index.atom.builder | 14 ++++++++++++++ app/views/advisories/index.html.haml | 4 ++++ config/locales/models/advisory.en.yml | 2 ++ config/locales/models/advisory.ru.yml | 2 ++ 8 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 app/views/advisories/_feed_partial.haml create mode 100644 app/views/advisories/index.atom.builder diff --git a/app/controllers/advisories_controller.rb b/app/controllers/advisories_controller.rb index 6a8f6b3a2..69e73cc96 100644 --- a/app/controllers/advisories_controller.rb +++ b/app/controllers/advisories_controller.rb @@ -6,7 +6,11 @@ class AdvisoriesController < ApplicationController authorize_resource def index - @advisories = @advisories.scoped(:include => :projects).paginate(:page => params[:page]) + @advisories = @advisories.scoped(:include => :platforms).paginate(:page => params[:page]) + respond_to do |format| + format.html + format.atom + end end def show diff --git a/app/models/advisory.rb b/app/models/advisory.rb index e41b1c665..2dc3a3110 100644 --- a/app/models/advisory.rb +++ b/app/models/advisory.rb @@ -12,6 +12,7 @@ class Advisory < ActiveRecord::Base TYPES = {'security' => 'SA', 'bugfix' => 'A'} scope :by_project, lambda {|p| where('project_id' => p.try(:id) || p)} + default_scope order('created_at DESC') def to_param advisory_id diff --git a/app/views/advisories/_feed_partial.haml b/app/views/advisories/_feed_partial.haml new file mode 100644 index 000000000..421dbd53d --- /dev/null +++ b/app/views/advisories/_feed_partial.haml @@ -0,0 +1,8 @@ +%h3= t("activerecord.attributes.advisory.description") +%p= simple_format advisory.description + +%h3= t("activerecord.attributes.advisory.references") +%p + - advisory.references.gsub(/\r| /, '').split("\n").each do |ref| + = construct_ref_link(ref) + %br diff --git a/app/views/advisories/_packages_info.html.haml b/app/views/advisories/_packages_info.html.haml index 245ba3f13..1ff955701 100644 --- a/app/views/advisories/_packages_info.html.haml +++ b/app/views/advisories/_packages_info.html.haml @@ -1,5 +1,5 @@ .packages_info_container - %h3= t('layout.advisories.affected_versions') + %h3= t('layout.advisories.affected_in') %ul.platforms - @packages_info.each_pair do |platform, projects| %li diff --git a/app/views/advisories/index.atom.builder b/app/views/advisories/index.atom.builder new file mode 100644 index 000000000..1a27b5c32 --- /dev/null +++ b/app/views/advisories/index.atom.builder @@ -0,0 +1,14 @@ +atom_feed do |feed| + feed.title(t("layout.advisories.atom_title")) + feed.updated(@advisories.first.created_at) if @advisories.length > 0 + + @advisories.each do |advisory| + feed.entry(advisory, :url => advisory_url(advisory)) do |entry| + content = raw(render(:inline => true, :partial => 'feed_partial', :locals => { :advisory => advisory })) + + entry.title("#{t("activerecord.models.advisory")} #{advisory.advisory_id}") + entry.content(content, :type => 'html') + + end + end +end diff --git a/app/views/advisories/index.html.haml b/app/views/advisories/index.html.haml index 431a3e919..3e73c2095 100644 --- a/app/views/advisories/index.html.haml +++ b/app/views/advisories/index.html.haml @@ -1,4 +1,8 @@ - set_meta_tags :title => t('layout.advisories.list_header') - render :partial => 'submenu' +%h3.fix + = t("layout.advisories.list_header") + = link_to image_tag("rss.ico", :width => '15px', :height => '15px', :class => 'atom_icon'), + APP_CONFIG['anonymous_access'] ? advisories_path(:format => 'atom') : advisories_path(:format => 'atom', :token => current_user.authentication_token) = render :partial => 'list', :object => @advisories = will_paginate @advisories diff --git a/config/locales/models/advisory.en.yml b/config/locales/models/advisory.en.yml index dd9ee79b5..dcd4b133d 100644 --- a/config/locales/models/advisory.en.yml +++ b/config/locales/models/advisory.en.yml @@ -1,10 +1,12 @@ en: layout: advisories: + atom_header: Advisories list_header: Advisories form_header: New advisory project_name: Project affected_versions: Affected versions + affected_in: Affected in ref_comment: Add links one by row no_: No new: New diff --git a/config/locales/models/advisory.ru.yml b/config/locales/models/advisory.ru.yml index f0914a12d..749b5622e 100644 --- a/config/locales/models/advisory.ru.yml +++ b/config/locales/models/advisory.ru.yml @@ -1,10 +1,12 @@ ru: layout: advisories: + atom_title: Бюллетени list_header: Бюллетени form_header: Новый бюллетень project_name: Проект affected_versions: Применен в версиях + affected_in: Применен в ref_comment: Вставляйте ссылки по одной на строку no_: Нет new: Новый