diff --git a/app/controllers/post_votes_controller.rb b/app/controllers/post_votes_controller.rb index 4cf3c05c6..88d81ecad 100644 --- a/app/controllers/post_votes_controller.rb +++ b/app/controllers/post_votes_controller.rb @@ -1,5 +1,5 @@ class PostVotesController < ApplicationController - before_filter :gold_only + before_filter :voter_only def create @post = Post.find(params[:post_id]) @@ -7,4 +7,10 @@ class PostVotesController < ApplicationController rescue PostVote::Error => x @error = x end + +protected + + def voter_only + CurrentUser.is_voter? + end end diff --git a/app/logical/anonymous_user.rb b/app/logical/anonymous_user.rb index a95e1c963..602da6f22 100644 --- a/app/logical/anonymous_user.rb +++ b/app/logical/anonymous_user.rb @@ -241,6 +241,14 @@ class AnonymousUser false end + def is_voter? + false + end + + def is_super_voter? + false + end + %w(member banned gold builder platinum janitor moderator admin).each do |name| define_method("is_#{name}?") do false diff --git a/app/models/user.rb b/app/models/user.rb index f719a8aa3..010fb75c3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -401,6 +401,10 @@ class User < ActiveRecord::Base level >= Levels::ADMIN end + def is_voter? + is_gold? || is_super_voter? + end + def create_mod_action if level_changed? ModAction.create(:description => %{"#{name}":/users/#{id} level changed #{level_string_was} -> #{level_string}}) diff --git a/app/views/comments/partials/index/_header.html.erb b/app/views/comments/partials/index/_header.html.erb index 472ec8a02..0e0e1ce02 100644 --- a/app/views/comments/partials/index/_header.html.erb +++ b/app/views/comments/partials/index/_header.html.erb @@ -16,7 +16,7 @@ Score <%= post.score %> - <% if CurrentUser.is_gold? %> + <% if CurrentUser.is_voter? %> (vote <%= link_to("up", post_votes_path(:score => "up", :post_id => post.id), :remote => true, :method => :post) %>/<%= link_to("down", post_votes_path(:score => "down", :post_id => post.id), :remote => true, :method => :post) %>) <% end %> diff --git a/app/views/posts/partials/show/_information.html.erb b/app/views/posts/partials/show/_information.html.erb index 26a280754..1749f5c92 100644 --- a/app/views/posts/partials/show/_information.html.erb +++ b/app/views/posts/partials/show/_information.html.erb @@ -16,7 +16,7 @@
  • Source: <%= post_source_tag(post) %>
  • Rating: <%= post.pretty_rating %>
  • -
  • Score: <%= post.score %> <% if CurrentUser.is_gold? %>(vote <%= link_to "up", post_votes_path(:post_id => post.id, :score => "up"), :remote => true, :method => :post %>/<%= link_to "down", post_votes_path(:post_id => post.id, :score => "down"), :remote => true, :method => :post %><%= link_to "undo vote", unvote_post_path(post), :remote => true, :method => :put, :id => "unvote-link-for-post-#{post.id}", :class => "unvote-post-link" %>)<% end %>
  • +
  • Score: <%= post.score %> <% if CurrentUser.is_voter? %>(vote <%= link_to "up", post_votes_path(:post_id => post.id, :score => "up"), :remote => true, :method => :post %>/<%= link_to "down", post_votes_path(:post_id => post.id, :score => "down"), :remote => true, :method => :post %><%= link_to "undo vote", unvote_post_path(post), :remote => true, :method => :put, :id => "unvote-link-for-post-#{post.id}", :class => "unvote-post-link" %>)<% end %>
  • Favorites: <%= post.fav_count %> <% if CurrentUser.is_gold? %> <%= link_to "Show »".html_safe, "#", :id => "show-favlist-link" %> diff --git a/script/fixes/040_fix_post_scores.rb b/script/fixes/040_fix_post_scores.rb new file mode 100644 index 000000000..6291dd18d --- /dev/null +++ b/script/fixes/040_fix_post_scores.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')) + +ActiveRecord::Base.connection.execute("set statement_timeout = 0") + +CurrentUser.user = User.admins.first +CurrentUser.ip_addr = "127.0.0.1" + +PostVote.find_each do |vote| + vote.destroy unless User.find(vote.user_id).is_gold? +end