diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 19b6d6a05..36a81839d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -133,9 +133,9 @@ protected end end - %w(member banned builder gold platinum janitor moderator admin).each do |level| - define_method("#{level}_only") do - if !CurrentUser.user.is_banned_or_ip_banned? && CurrentUser.user.__send__("is_#{level}?") + User::Roles.each do |role| + define_method("#{role}_only") do + if !CurrentUser.user.is_banned_or_ip_banned? && CurrentUser.user.__send__("is_#{role}?") true else access_denied() diff --git a/app/controllers/post_votes_controller.rb b/app/controllers/post_votes_controller.rb index e4c8071fa..b94cf8bb1 100644 --- a/app/controllers/post_votes_controller.rb +++ b/app/controllers/post_votes_controller.rb @@ -14,10 +14,4 @@ class PostVotesController < ApplicationController rescue PostVote::Error => x @error = x end - -protected - - def voter_only - CurrentUser.is_voter? - end end diff --git a/app/models/user.rb b/app/models/user.rb index c3df8269a..a1eb4b248 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,6 +16,16 @@ class User < ActiveRecord::Base ADMIN = 50 end + # Used for `before_filter :_only`. Must have a corresponding `is_?` method. + Roles = Levels.constants.map(&:downcase) + [ + :anonymous, + :banned, + :approver, + :voter, + :super_voter, + :verified, + ] + BOOLEAN_ATTRIBUTES = %w( is_banned has_mail @@ -384,6 +394,10 @@ class User < ActiveRecord::Base true end + def is_blocked? + is_banned? + end + def is_builder? level >= Levels::BUILDER end