Class: Commontator::CommentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/commontator/comments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /1/comments

Raises:

  • (SecurityTransgression)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/commontator/comments_controller.rb', line 23

def create
  @comment = Comment.new(params[:comment])
  @comment.thread = @thread
  @comment.creator = @user
  
  raise SecurityTransgression unless @comment.can_be_created_by?(@user)
  
  if @comment.save
    @thread.subscribe(@user) if @thread.config.auto_subscribe_on_comment
    @thread.mark_as_unread_except_for(@user)
    SubscriptionsMailer.comment_created_email(@comment, @commontable_url)
    @thread.comment_created_callback(@user, @comment)
  else
    @errors = @comment.errors
  end

  respond_to do |format|
    format.html { redirect_to @thread }
    format.js
  end
end

#deleteObject

PUT /comments/1/delete

Raises:

  • (SecurityTransgression)


69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/commontator/comments_controller.rb', line 69

def delete
  raise SecurityTransgression unless @comment.can_be_deleted_by?(@user)

  @comment.delete(@user)
  @thread.comment_deleted_callback(@user, @comment)

  respond_to do |format|
    format.html { redirect_to @thread }
    format.js { render :delete }
  end
end

#downvoteObject

PUT /comments/1/downvote

Raises:

  • (SecurityTransgression)


106
107
108
109
110
111
112
113
114
115
# File 'app/controllers/commontator/comments_controller.rb', line 106

def downvote
  raise SecurityTransgression unless @comment.can_be_voted_on_by?(@user)
  
  @comment.downvote_from @user

  respond_to do |format|
    format.html { redirect_to @thread }
    format.js { render :vote }
  end
end

#editObject

GET /comments/1/edit

Raises:

  • (SecurityTransgression)


46
47
48
49
50
51
52
53
# File 'app/controllers/commontator/comments_controller.rb', line 46

def edit
  raise SecurityTransgression unless @comment.can_be_edited_by?(@user)

  respond_to do |format|
    #format.html
    format.js
  end
end

#newObject

GET /1/comments/new

Raises:

  • (SecurityTransgression)


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/commontator/comments_controller.rb', line 8

def new
  @comment = Comment.new
  @comment.thread = @thread
  @comment.creator = @user

  raise SecurityTransgression unless @comment.can_be_created_by?(@user)

  respond_to do |format|
    #format.html
    format.js
  end
 
end

#undeleteObject

PUT /comments/1/undelete

Raises:

  • (SecurityTransgression)


82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/commontator/comments_controller.rb', line 82

def undelete
  raise SecurityTransgression unless @comment.can_be_deleted_by?(@user)

  @comment.undelete

  respond_to do |format|
    format.html { redirect_to @thread }
    format.js { render :delete }
  end
end

#unvoteObject

PUT /comments/1/unvote

Raises:

  • (SecurityTransgression)


118
119
120
121
122
123
124
125
126
127
# File 'app/controllers/commontator/comments_controller.rb', line 118

def unvote
  raise SecurityTransgression unless @comment.can_be_voted_on_by?(@user)
  
  @comment.unvote :voter => @user

  respond_to do |format|
    format.html { redirect_to @thread }
    format.js { render :vote }
  end
end

#updateObject

PUT /comments/1

Raises:

  • (SecurityTransgression)


56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/commontator/comments_controller.rb', line 56

def update
  raise SecurityTransgression unless @comment.can_be_edited_by?(@user)
  
  @thread.comment_edited_callback(@user, @comment) \
    if @comment.update_attributes(params[:comment])

  respond_to do |format|
    format.html { redirect_to @thread }
    format.js
  end
end

#upvoteObject

PUT /comments/1/upvote

Raises:

  • (SecurityTransgression)


94
95
96
97
98
99
100
101
102
103
# File 'app/controllers/commontator/comments_controller.rb', line 94

def upvote
  raise SecurityTransgression unless @comment.can_be_voted_on_by?(@user)
  
  @comment.upvote_from @user

  respond_to do |format|
    format.html { redirect_to @thread }
    format.js { render :vote }
  end
end