diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 32dae9812..a68e056f2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -154,11 +154,15 @@ class ApplicationController < ActionController::Base render_error_page(status, error) end + def role_only!(role) + raise User::PrivilegeError if !CurrentUser.send("is_#{role}?") + raise User::PrivilegeError if !request.get? && CurrentUser.user.is_banned? + raise User::PrivilegeError if !request.get? && IpBan.is_banned?(CurrentUser.ip_addr) + end + User::Roles.each do |role| define_method("#{role}_only") do - if !CurrentUser.user.send("is_#{role}?") || CurrentUser.user.is_banned? || IpBan.is_banned?(CurrentUser.ip_addr) - raise User::PrivilegeError - end + role_only!(role) end end