From 22b77573a519937c35607fde01fc7ffe65570403 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Sun, 12 Jan 2014 23:17:09 -0600 Subject: [PATCH] prevent new users from downvoting don't show downvote arrows for logged-out and new users color comments from new users in green like in the user tree, and banned users in gray --- app/assets/stylesheets/application.css | 30 +++++++++++++++++++------- app/controllers/comments_controller.rb | 7 +++++- app/controllers/stories_controller.rb | 4 ++++ app/models/user.rb | 13 +++++++++-- app/views/comments/_comment.html.erb | 25 +++++++++++++++------ app/views/stories/_listdetail.html.erb | 4 ++-- app/views/users/tree.html.erb | 6 +++--- 7 files changed, 66 insertions(+), 23 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 56a6b86..e01936e 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -391,8 +391,8 @@ div.voters div.score { text-align: center; } -div.voters a.upvoter, -div.voters a.downvoter { +div.voters .upvoter, +div.voters .downvoter { border-color: transparent transparent #bbb transparent; border-style: solid; border-width: 6px; @@ -405,16 +405,16 @@ div.voters a.downvoter { display: block; } -div.voters a.upvoter:hover, -li.upvoted div.voters a.upvoter { +div.voters .upvoter:hover, +li.upvoted div.voters .upvoter { border-bottom-color: #ac130d; } -div.voters a.upvoter { +div.voters .upvoter { border-bottom-width: 11px; } -div.voters a.downvoter { +div.voters .downvoter { border-color: #bbb transparent transparent transparent; border-width: 5px; margin-top: 4px; @@ -422,11 +422,15 @@ div.voters a.downvoter { margin-bottom: -5px; border-top-width: 9px; } -div.voters a.downvoter:hover, -li.downvoted div.voters a.downvoter { +div.voters .downvoter:hover, +li.downvoted div.voters .downvoter { border-top-color: gray; } +div.voters .downvoter.downvoter_stub { + border-color: transparent; +} + li.story, li.comment { clear: both; @@ -503,6 +507,16 @@ li .byline a { color: #888; text-decoration: none; } +.new_user, +li .byline a.new_user { + color: green; +} +.banned_user, +li .byline a.banned_user { + color: gray; + text-decoration: line-through; +} + li.story.expired { opacity: 0.6; diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index f6b389a..12af3c0 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -8,7 +8,8 @@ class CommentsController < ApplicationController before_filter :find_user_from_rss_token, :only => [ :index ] def create - if !(story = Story.where(:short_id => params[:story_id]).first) || story.is_gone? + if !(story = Story.where(:short_id => params[:story_id]).first) || + story.is_gone? return render :text => "can't find story", :status => 400 end @@ -174,6 +175,10 @@ class CommentsController < ApplicationController return render :text => "invalid reason", :status => 400 end + if !@user.can_downvote? + return render :text => "not permitted to downvote", :status => 400 + end + Vote.vote_thusly_on_story_or_comment_for_user_because(-1, comment.story_id, comment.id, @user.id, params[:reason]) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 325fde2..6a5d434 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -238,6 +238,10 @@ class StoriesController < ApplicationController return render :text => "invalid reason", :status => 400 end + if !@user.can_downvote? + return render :text => "not permitted to downvote", :status => 400 + end + Vote.vote_thusly_on_story_or_comment_for_user_because(-1, story.id, nil, @user.id, params[:reason]) diff --git a/app/models/user.rb b/app/models/user.rb index a0c23c7..28c8285 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -92,8 +92,9 @@ class User < ActiveRecord::Base true end - def is_banned? - banned_at? + def can_downvote? + # TODO: maybe change this to require a certain level of karma + !is_new? end def check_session_token @@ -125,6 +126,14 @@ class User < ActiveRecord::Base PasswordReset.password_reset_link(self, ip).deliver end + def is_banned? + banned_at? + end + + def is_new? + Time.now - self.created_at <= 7.days + end + def linkified_about # most users are probably mentioning "@username" to mean a twitter url, not # a link to a profile on this site diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index a31a931..5fec451 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -8,11 +8,17 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ? <%= comment.score <= -7 ? "negative_7" : "" %>"> <% if !comment.is_gone? %>
- -
- <%= comment.score %> -
- + <% if @user %> + + <% else %> + <%= link_to "", login_url, :class => "upvoter" %> + <% end %> +
<%= comment.score %>
+ <% if @user && @user.can_downvote? %> + + <% else %> + + <% end %>
<% end %>
@@ -22,8 +28,13 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ? previewed just now <% else %> - <%= comment.user.username - %> + + class="banned_user" + <% elsif comment.user.is_new? %> + class="new_user" + <% end %> + ><%= comment.user.username %> <%= comment.has_been_edited?? "edited" : "" %> <%= raw(time_ago_in_words_label(comment.has_been_edited? ? diff --git a/app/views/stories/_listdetail.html.erb b/app/views/stories/_listdetail.html.erb index 9580ffd..f8817ea 100644 --- a/app/views/stories/_listdetail.html.erb +++ b/app/views/stories/_listdetail.html.erb @@ -8,10 +8,10 @@ class="story <%= story.vote == 1 ? "upvoted" : (story.vote == -1 ? <%= link_to "", login_url, :class => "upvoter" %> <% end %>
<%= story.upvotes - story.downvotes %>
- <% if @user %> + <% if @user && @user.can_downvote? %> <% else %> - <%= link_to "", login_url, :class => "downvoter" %> + <% end %>
diff --git a/app/views/users/tree.html.erb b/app/views/users/tree.html.erb index 1d04269..214e01f 100644 --- a/app/views/users/tree.html.erb +++ b/app/views/users/tree.html.erb @@ -11,9 +11,9 @@
  • - style="color: gray; text-decoration: line-through;" - <% elsif Time.now - user.created_at < 7.days %> - style="color: green;" + class="banned_user" + <% elsif user.is_new? %> + class="new_user" <% end %> ><%= user.username %> (<%= user.karma %>) <% if user.is_admin? %>