aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Legler <alex@a3li.li>2011-08-19 01:30:45 +0200
committerAlex Legler <alex@a3li.li>2011-08-19 01:30:45 +0200
commit821858cbce1244097344294d6c0847f92be701f6 (patch)
tree9aa4304e4af4cdfda8947f9a073c58ee2eb5e4df
parentFix bug popup (diff)
downloadglsamaker-821858cbce1244097344294d6c0847f92be701f6.tar.gz
glsamaker-821858cbce1244097344294d6c0847f92be701f6.tar.bz2
glsamaker-821858cbce1244097344294d6c0847f92be701f6.zip
RESTifying Part 1: Comments get their own controller, add glsas resource
Comments live as sub-resources of glsas now
-rw-r--r--app/assets/javascripts/glsamaker.js2
-rw-r--r--app/controllers/comments_controller.rb60
-rw-r--r--app/controllers/glsa_controller.rb39
-rw-r--r--app/helpers/comments_helper.rb2
-rw-r--r--app/views/comments/create.js.erb6
-rw-r--r--app/views/comments/destroy.html.erb2
-rw-r--r--app/views/comments/new.html.erb23
-rw-r--r--app/views/comments/show.html.erb2
-rw-r--r--app/views/glsa/_comment.html.erb12
-rw-r--r--app/views/glsa/addcomment.html.erb31
-rw-r--r--app/views/glsa/show.html.erb4
-rw-r--r--config/routes.rb18
-rw-r--r--test/functional/comments_controller_test.rb24
-rw-r--r--test/unit/helpers/comments_helper_test.rb4
14 files changed, 145 insertions, 84 deletions
diff --git a/app/assets/javascripts/glsamaker.js b/app/assets/javascripts/glsamaker.js
index 175419d..fe3132d 100644
--- a/app/assets/javascripts/glsamaker.js
+++ b/app/assets/javascripts/glsamaker.js
@@ -27,7 +27,7 @@ function addBugDialog(glsaid) {
}
function addCommentDialog(glsaid) {
- Modalbox.show("/glsa/"+glsaid+"/addcomment", {title: "Add comments", width: 600});
+ Modalbox.show("/glsas/"+glsaid+"/comments/new", {title: "Add comment", width: 600});
}
function backgroundDialog() {
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb
new file mode 100644
index 0000000..70e47a4
--- /dev/null
+++ b/app/controllers/comments_controller.rb
@@ -0,0 +1,60 @@
+# ===GLSAMaker v2
+# Copyright (C) 2011 Alex Legler <a3li@gentoo.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# For more information, see the LICENSE file.
+
+# CommentController handles comments made for GLSAs
+class CommentsController < ApplicationController
+ layout false
+
+ def new
+ begin
+ @glsa = Glsa.find(Integer(params[:glsa_id]))
+ @comment = Comment.new
+ rescue Exception => e
+ @glsa = nil
+ end
+ end
+
+ def create
+ @glsa = Glsa.find(params[:glsa_id].to_i)
+
+ unless @glsa.nil?
+ comment_data = params[:newcomment]
+ comment = nil
+
+ if comment_data['text'].strip != ''
+ comment = @glsa.comments.build(comment_data)
+ comment.user = current_user
+ 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
+ @comment_text = render_to_string :partial => "/glsa/comment", :object => comment
+ rescue Exception => e
+ @error = "Error: #{e.message}"
+ end
+ else
+ @error = "Error: Cannot find GLSA"
+ end
+ end
+
+ def show
+ end
+
+ def destroy
+ end
+
+end
diff --git a/app/controllers/glsa_controller.rb b/app/controllers/glsa_controller.rb
index 22d03db..039fde0 100644
--- a/app/controllers/glsa_controller.rb
+++ b/app/controllers/glsa_controller.rb
@@ -372,45 +372,6 @@ class GlsaController < ApplicationController
def comment
end
- def addcomment
- begin
- @glsa_id = Integer(params[:id])
- rescue Exception => e
- @glsa_id = nil
- end
- render :layout => false
- end
-
- def addcommentsave
- @glsa = Glsa.find(params[:id].to_i)
-
- unless @glsa.nil?
- comment_data = params[:newcomment]
- comment = nil
-
- if comment_data['text'].strip != ''
- comment = @glsa.comments.build(comment_data)
- comment.user = current_user
- 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
- rescue Exception => e
- render :text => "Error: #{e.message}", :status => 500
- end
- else
- render :text => "fail", :status => 500
- end
- end
-
def import_references
begin
if params[:go].to_s == '1'
diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb
new file mode 100644
index 0000000..0ec9ca5
--- /dev/null
+++ b/app/helpers/comments_helper.rb
@@ -0,0 +1,2 @@
+module CommentsHelper
+end
diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb
new file mode 100644
index 0000000..9b5ca8d
--- /dev/null
+++ b/app/views/comments/create.js.erb
@@ -0,0 +1,6 @@
+<% if @error == nil %>
+Element.insert('commentslist', { bottom: '<%= escape_javascript(@comment_text).html_safe %>'});
+Modalbox.hide();
+<% else %>
+alert('<%= escape_javascript(@error).html_safe %>');
+<% end %> \ No newline at end of file
diff --git a/app/views/comments/destroy.html.erb b/app/views/comments/destroy.html.erb
new file mode 100644
index 0000000..9dcdf77
--- /dev/null
+++ b/app/views/comments/destroy.html.erb
@@ -0,0 +1,2 @@
+<h1>Comment#destroy</h1>
+<p>Find me in app/views/comment/destroy.html.erb</p>
diff --git a/app/views/comments/new.html.erb b/app/views/comments/new.html.erb
new file mode 100644
index 0000000..75240b2
--- /dev/null
+++ b/app/views/comments/new.html.erb
@@ -0,0 +1,23 @@
+<% if @glsa.nil? %>
+<p>No or invalid GLSA ID specified.</p>
+<% else %>
+<%= form_tag(glsa_comments_path(@glsa, @comment), :remote => true) do -%>
+<p><label for="addcomment"><img src="/assets/icons/comment.png" alt="bug" />
+ Please enter your comment:</label></p>
+
+ <%= fields_for :newcomment do |f| %>
+ <p>
+ <%= f.text_area :text, :class => "nice", :rows => 2 %>
+ </p>
+
+ <div align="right">
+ Rating:
+ <%= f.radio_button :rating, "approval" %><label for="newcomment_rating_approval"><img src="/assets/icons/unaffected.png" alt="Approval" title="Approval" /></label>&nbsp;
+ <%= f.radio_button :rating, "rejection" %><label for="newcomment_rating_rejection"><img src="/assets/icons/affected.png" alt="Rejection" title="Rejection" /></label>&nbsp;
+ <%= f.radio_button :rating, "neutral", :checked => true %><label for="newcomment_rating_neutral"><img src="/assets/icons/reference.png" alt="Neutral" title="Neutral" /></label>
+ </div>
+ <% end %>
+
+ <p style="text-align: right;"><input type="submit" class="button" value="Add comment" id="addcommentsubmit" /></p>
+<% end -%>
+<% end %> \ No newline at end of file
diff --git a/app/views/comments/show.html.erb b/app/views/comments/show.html.erb
new file mode 100644
index 0000000..b66469d
--- /dev/null
+++ b/app/views/comments/show.html.erb
@@ -0,0 +1,2 @@
+<h1>Comment#show</h1>
+<p>Find me in app/views/comment/show.html.erb</p>
diff --git a/app/views/glsa/_comment.html.erb b/app/views/glsa/_comment.html.erb
index b755fc1..c8c722a 100644
--- a/app/views/glsa/_comment.html.erb
+++ b/app/views/glsa/_comment.html.erb
@@ -1,22 +1,20 @@
<li>
<input type="hidden" name="commentread-<%= comment.id %>" id="commentread-<%= comment.id %>" value="<%= comment.read ? "true" : "false" %>" />
<span style="float: right;">
- <%= link_to_function (comment.read ? '<img src="/images/icons/flag-green.png" alt="Done." />' : '<img src="/images/icons/flag.png" alt="Todo" />'),
+ <%= link_to_function(comment.read ? image_tag("icons/flag-green.png", :title => 'done') : image_tag("icons/flag.png", :title => 'todo'),
"toggleCommentRead(#{comment.id})",
:title => 'Toggle read status',
- :id => "commentflag-#{comment.id}" %>
-
- </a>
+ :id => "commentflag-#{comment.id}") %>
</span>
<div style="float: left;">
<%= case comment.rating
when "approval"
- '<img src="/images/icons/unaffected.png" alt="Approval" title="Approval" />'
+ image_tag('icons/unaffected.png', :title => 'Approval')
when "rejection"
- '<img src="/images/icons/affected.png" alt="Rejection" title="Rejection" />'
+ image_tag('icons/affected.png', :title => 'Rejection')
else
- '<img src="/images/icons/reference.png" alt="Neutral" title="Neutral" />'
+ image_tag('icons/reference.png', :title => 'Neutral')
end -%>
<small style="color: grey; vertical-align: text-bottom;"><%= @comment_number ||= 1 %></small>
</div>
diff --git a/app/views/glsa/addcomment.html.erb b/app/views/glsa/addcomment.html.erb
deleted file mode 100644
index eb925ae..0000000
--- a/app/views/glsa/addcomment.html.erb
+++ /dev/null
@@ -1,31 +0,0 @@
-<% if @glsa_id.nil? %>
-<p>Need a GLSA id.</p>
-<% else %>
-<% form_remote_tag (
- :url => addcommentsave_url(:id => @glsa_id.to_s),
- :update => {:success => 'commentslist'},
- :position => :bottom,
- :before => '$("addcommentsubmit").value="Loading...";',
- :after => '$("addcommentsubmit").value="Add comment";',
- :success => 'Modalbox.hide();',
- :failure => 'alert(request.responseText);') do -%>
-<p><label for="addcomment"><img src="/images/icons/comment.png" alt="bug" />
- Please enter your comment:</label></p>
-
- <% fields_for :newcomment do |f| %>
- <p>
- <%= f.text_area :text, :class => "nice", :rows => 2 %>
- </p>
-
- <div align="right">
- Rating:
- <%= f.radio_button :rating, "approval" %><img src="/images/icons/unaffected.png" alt="Approval" title="Approval" /> &nbsp;
- <%= f.radio_button :rating, "rejection" %><img src="/images/icons/affected.png" alt="Rejection" title="Rejection" /> &nbsp;
- <%= f.radio_button :rating, "neutral", :checked => true %><img src="/images/icons/reference.png" alt="Neutral" title="Neutral" />
- </div>
- <% end %>
-
-<p style="text-align: right;"><input type="submit" class="button" value="Add comment" id="addcommentsubmit" /></p>
-<% end -%>
-
-<% end %> \ No newline at end of file
diff --git a/app/views/glsa/show.html.erb b/app/views/glsa/show.html.erb
index d547727..55c5a9f 100644
--- a/app/views/glsa/show.html.erb
+++ b/app/views/glsa/show.html.erb
@@ -118,4 +118,6 @@
<li><%= link_to r.title, r.url -%></li>
<% end %>
</ul>
-</p> \ No newline at end of file
+</p>
+
+<br style="break: both;" /> \ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 632fb9e..e626567 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,12 +1,12 @@
Glsamaker::Application.routes.draw do
-
+
match 'bug/:id' => 'bug#bug', :as => :bug
match 'bug/:id/history' => 'bug#history', :as => :bughistory
match 'tools/bug/:id/:what' => 'tools#bugzie', :as => :bugzie
-
- match 'glsa/:id/addcomment' => 'glsa#addcomment', :as => :addcomment
+
match 'glsa/:id/addcomment/save' => 'glsa#addcommentsave', :as => :addcommentsave
-
+ match 'glsa/:id/addcomment' => 'glsa#addcomment', :as => :addcomment
+
match 'glsa/requests' => 'glsa#requests', :as => :requests
match 'glsa/drafts' => 'glsa#drafts', :as => :drafts
match 'glsa/archive' => 'glsa#archive', :as => :sent
@@ -18,7 +18,15 @@ Glsamaker::Application.routes.draw do
match 'cve/list.:format' => 'cve#list', :as => :cve
- match 'admin' => 'admin#index'
+ match 'admin' => 'admin#index'
+
+ resources :glsas, :controller => 'glsa' do
+ resources :comments
+
+ get 'requests', :on => :collection
+ get 'drafts' , :on => :collection
+ get 'archive' , :on => :collection
+ end
# The priority is based upon order of creation:
# first created -> highest priority.
diff --git a/test/functional/comments_controller_test.rb b/test/functional/comments_controller_test.rb
new file mode 100644
index 0000000..fd4d589
--- /dev/null
+++ b/test/functional/comments_controller_test.rb
@@ -0,0 +1,24 @@
+require 'test_helper'
+
+class CommentsControllerTest < ActionController::TestCase
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should get create" do
+ get :create
+ assert_response :success
+ end
+
+ test "should get show" do
+ get :show
+ assert_response :success
+ end
+
+ test "should get destroy" do
+ get :destroy
+ assert_response :success
+ end
+
+end
diff --git a/test/unit/helpers/comments_helper_test.rb b/test/unit/helpers/comments_helper_test.rb
new file mode 100644
index 0000000..2518c16
--- /dev/null
+++ b/test/unit/helpers/comments_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class CommentsHelperTest < ActionView::TestCase
+end