Skip to content
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

Merged
merged 7 commits into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Member

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).

Copy link
Member Author

@grvsachdeva grvsachdeva Feb 12, 2018

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.

else
flash[:notice] = "Comment already marked as spam."
redirect_to '/dashboard'
end
Copy link
Member

Choose a reason for hiding this comment

The 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:

if status is as desired
  flash the "already" msg
else
  set status as desired
  flash msg about what you did there
end

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]
Expand Down
7 changes: 7 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,11 @@ def answer_comment_notify(current_user)
notify_users(uids, current_user)
notify_tag_followers(already + uids)
end

def comment_spam
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool! Let's name this just def spam to match node.rb, and add a corresponding def publish method?

plots2/app/models/node.rb

Lines 151 to 161 in fa16a69

def publish
self.status = 1
save
self
end
def spam
self.status = 0
save
self
end

How does that sound? Then we can unit test this and functional test the above. This is looking great!!!

Copy link
Member Author

@grvsachdeva grvsachdeva Feb 15, 2018

Choose a reason for hiding this comment

The 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