-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comment spam moderation Part 2 #2305
Changes from 1 commit
853e130
1bdc48a
fbeb3a9
63f08d7
1203988
d72ced4
ee93fb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,23 @@ def mark_spam | |
end | ||
end | ||
|
||
def mark_comment_spam | ||
@comment = Comment.find params[:id] | ||
if current_user && (current_user.role == 'moderator' || current_user.role == 'admin') | ||
if @comment.status == 0 | ||
@comment.comment_spam | ||
flash[:notice] = "Comment has been marked as spam." | ||
redirect_to '/dashboard' | ||
else | ||
flash[:notice] = "Comment already marked as spam." | ||
redirect_to '/dashboard' | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to make one last suggestion. The idea is to first check if the status is as desired, in which case you move on, or else you set it as desired. I think it'll look as follows:
This is what you did in the publish_comment method, and it is clearer IMO. |
||
else | ||
flash[:error] = 'Only moderators can moderate comments.' | ||
redirect_to '/dashboard' | ||
end | ||
end | ||
|
||
def publish | ||
if current_user && (current_user.role == 'moderator' || current_user.role == 'admin') | ||
@node = Node.find params[:id] | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -142,4 +142,11 @@ def answer_comment_notify(current_user) | |||||||||||||||||||||||
notify_users(uids, current_user) | ||||||||||||||||||||||||
notify_tag_followers(already + uids) | ||||||||||||||||||||||||
end | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
def comment_spam | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh cool! Let's name this just Lines 151 to 161 in fa16a69
How does that sound? Then we can unit test this and functional test the above. This is looking great!!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks.I will do the changes. |
||||||||||||||||||||||||
self.status = 2 | ||||||||||||||||||||||||
save | ||||||||||||||||||||||||
self | ||||||||||||||||||||||||
end | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, since the user is redirected in any case, the redirect statement can be placed at the end of the action (just after line 140).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @seafr, yes you are absolutely right, actually, it's just a basic function to show @jywarren and get approval that I am going correctly with the issue and to ask if the status code used is fine or not.But still thanks for highlighting, I will definitely correct it in next commit.