diff options
author | Alex Legler <alex@a3li.li> | 2011-03-18 13:00:28 +0100 |
---|---|---|
committer | Alex Legler <alex@a3li.li> | 2011-03-18 13:00:28 +0100 |
commit | 3a7b74c9541ed1706022a203341f955318a24472 (patch) | |
tree | 0540b991d046d764419fa7342eff2165a0b47f4d | |
parent | GLSA model: fix last_release_revision SQL (diff) | |
download | glsamaker-3a7b74c9541ed1706022a203341f955318a24472.tar.gz glsamaker-3a7b74c9541ed1706022a203341f955318a24472.tar.bz2 glsamaker-3a7b74c9541ed1706022a203341f955318a24472.zip |
glsa_controller: Add release and download actions
The .txt show view is also now self-contained, no need for prepare_show_view stuff any more.
-rw-r--r-- | app/controllers/glsa_controller.rb | 108 | ||||
-rw-r--r-- | app/views/glsa/prepare_release.html.erb | 6 | ||||
-rw-r--r-- | app/views/glsa/release.html.erb | 30 | ||||
-rw-r--r-- | app/views/glsa/show.txt.erb | 3 |
4 files changed, 119 insertions, 28 deletions
diff --git a/app/controllers/glsa_controller.rb b/app/controllers/glsa_controller.rb index e0e54d1..11a5cb2 100644 --- a/app/controllers/glsa_controller.rb +++ b/app/controllers/glsa_controller.rb @@ -65,19 +65,6 @@ class GlsaController < ApplicationController end end - def prepare_show_view(what) - if what == :txt - @packages = @rev.packages_by_atom - logger.debug @packages.inspect - - @packages_count = 0 - - @tf = Text::Format.new - end - end - - private :prepare_show_view - def show @glsa = Glsa.find(params[:id]) return unless check_object_access(@glsa) @@ -94,11 +81,29 @@ class GlsaController < ApplicationController respond_to do |wants| wants.html { render } wants.xml { } - wants.txt { - prepare_show_view :txt - render - } + wants.txt { render } + end + end + + def download + @glsa = Glsa.find(params[:id]) + return unless check_object_access(@glsa) + @rev = params[:rev_id].nil? ? @glsa.last_revision : @glsa.revisions.find_by_revid(params[:rev_id]) + + if @rev == nil + flash[:error] = "Invalid revision ID" + redirect_to :action => "show" + return + end + + text = nil + respond_to do |wants| + wants.xml { text = render_to_string(:action => :show, :format => 'xml')} + wants.txt { text = render_to_string(:action => :show, :format => 'txt')} + wants.html { render :text => "Cannot download HTML format. Pick .xml or .txt"; return } end + + send_data(text, :filename => "glsa-#{@glsa.glsa_id}.#{params[:format]}") end def edit @@ -244,7 +249,53 @@ class GlsaController < ApplicationController @rev = @glsa.last_revision @comments_override = (current_user.is_el_jefe? and params[:override_approvals].to_i == 1) || false - logger.debug @comments_override.inspect + end + + def release + @glsa = Glsa.find(params[:id]) + return unless check_object_access(@glsa) + + if @glsa.status == 'request' + flash[:error] = 'You cannot release a request. Draft the advisory first.' + redirect_to :action => "show", :id => @glsa + return + end + + if @glsa.restricted + flash[:error] = 'You cannot release a confidential draft. Make it public first.' + redirect_to :action => "show", :id => @glsa + return + end + + @rev = @glsa.last_revision + begin + if current_user.is_el_jefe? + @glsa.release! + else + @glsa.release + end + + @glsa.invalidate_last_revision_cache + + if params[:email] == '1' + of = @template_format + @template_format = 'txt' + Glsamaker::Mail.send_text( + render_to_string({:template => 'glsa/show.txt.erb', :format => :txt, :layout => false}), + "[ GLSA #{@glsa.glsa_id} ] #{@rev.title}", + current_user, + false + ) + @template_format = of + end + rescue GLSAReleaseError => e + flash[:error] = "Internal error: #{e.message}. Cannot release advisory." + redirect_to :action => "show", :id => @glsa + end + + # ugly hack, but necessary to switch back to html + @real_format = 'html' + render(:format => :html, :layout => 'application') end def diff @@ -337,14 +388,21 @@ class GlsaController < ApplicationController @glsa = Glsa.find(params[:id].to_i) unless @glsa.nil? - comment = params[:newcomment] + comment_data = params[:newcomment] + comment = nil - if comment['text'].strip != '' - comment = @glsa.comments.build(comment) + if comment_data['text'].strip != '' + comment = @glsa.comments.build(comment_data) comment.user = current_user - comment.save - end - + if comment.save + Glsamaker::Mail.comment_notification(@glsa, comment, current_user) + + if @glsa.is_approved? and @glsa.approvals.count == @glsa.rejections.count + 2 + Glsamaker::Mail.approval_notification(@glsa) + end + end + end + begin @comment_number = @glsa.comments.count render :partial => "comment", :object => comment @@ -431,7 +489,7 @@ class GlsaController < ApplicationController {:indent => 2, :maxcols => 80} ) - Glsamaker::Diff.diff(new_text, old_text, format, context_lines) + Glsamaker::Diff.diff(old_text, new_text, format, context_lines) end end diff --git a/app/views/glsa/prepare_release.html.erb b/app/views/glsa/prepare_release.html.erb index 9ca96d2..70337f1 100644 --- a/app/views/glsa/prepare_release.html.erb +++ b/app/views/glsa/prepare_release.html.erb @@ -85,6 +85,7 @@ <p> All checks passed. You can release this draft now. </p> + <% form_tag(:action => "release", :id => @glsa.id) do %> <table> <tr> <td><%= check_box_tag 'email' %></td> @@ -92,10 +93,9 @@ </tr> </table> <div class='box-actions'> - <% form_tag(:action => "release", :id => @glsa.id) do %> - <%= submit_tag 'Release >', :class => 'largetext' %> - <% end %> + <%= submit_tag 'Release >', :class => 'largetext' %> </div> + <% end %> <% else %> <p> At least one check failed. Please see the red boxes above.<br /> diff --git a/app/views/glsa/release.html.erb b/app/views/glsa/release.html.erb new file mode 100644 index 0000000..6be0f12 --- /dev/null +++ b/app/views/glsa/release.html.erb @@ -0,0 +1,30 @@ +<h1>GLSA released</h1> + +<div class="box w40em"> + <h2>Release information</h2> + + <table> + <tr> + <td>Official ID</td> + <td><strong>GLSA <%= @glsa.glsa_id %></strong></td> + </tr> + <tr> + <td>Title</td> + <td><strong><%= h @rev.title %></strong></td> + </tr> + </table> +</div> + +<div class="box w40em"> + <h2>Next steps</h2> + + <p> + Now, download the advisory XML and publish it in CVS.<br /> + Then you can send the advisory email. + </p> + + <div class='box-actions'> + <button onclick="document.location = '<%= url_for :action => :download, :format => 'xml', :id => @glsa %>'">Download XML</button> + <button onclick="document.location = '<%= url_for :action => :show, :format => 'txt', :id => @glsa %>'">Show Text</button> + </div> +</div>
\ No newline at end of file diff --git a/app/views/glsa/show.txt.erb b/app/views/glsa/show.txt.erb index 8fc5905..56a1605 100644 --- a/app/views/glsa/show.txt.erb +++ b/app/views/glsa/show.txt.erb @@ -1,3 +1,6 @@ +<%- @packages = @rev.packages_by_atom + @packages_count = 0 + @tf = Text::Format.new -%> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Gentoo Linux Security Advisory GLSA <%= @glsa.glsa_id %> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |