blob: aa56e6ac65a25851ddf5a48a5b277c652e39bff9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# ===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].permit([:text, :rating])
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
else
@error = comment.errors
render
return
end
else
@error = "Error: Comment text is empty."
render
return
end
begin
@comment_number = @glsa.comments.count
@css_class = @comment_number.odd? ? 'odd-bright' : ''
@comment_text = render_to_string :partial => "/glsa/comment", :object => comment
rescue Exception => e
log_error e
@error = "Error: #{e.message}"
end
else
@error = "Error: Cannot find GLSA"
end
respond_to do |format|
format.html { render :status => 500 }
format.js
end
end
def show
end
def destroy
end
end
|