spam_controller.rb
1.36 KB
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
class SpamController < MyProfileController
protect :moderate_comments, :profile
def index
if request.post?
begin
# FIXME duplicated logic
#
# This logic more or less replicates what is already in
# ContentViewerController#view_page,
# ContentViewerController#remove_comment and
# ContentViewerController#mark_comment_as_spam
if params[:remove_comment]
profile.comments_received.find(params[:remove_comment]).destroy
end
if params[:remove_task]
Task.to(profile).find_by_id(params[:remove_task]).destroy
end
if params[:mark_comment_as_ham]
profile.comments_received.find(params[:mark_comment_as_ham]).ham!
end
if params[:mark_task_as_ham] && (t = Task.to(profile).find_by_id(params[:mark_task_as_ham]))
t.ham!
end
if request.xhr?
json_response(true)
else
redirect_to :action => :index
end
rescue
json_response(false)
end
return
end
@comment_spam = profile.comments_received.spam.paginate({:page => params[:comments_page]})
@task_spam = Task.to(profile).spam.paginate({:page => params[:tasks_page]})
end
protected
def json_response(status)
render :text => {'ok' => status }.to_json, :content_type => 'application/json'
end
end