implemented basic functionality of YE OLDE BANHAMMER!

This commit is contained in:
nilsding 2015-01-12 22:44:13 +01:00
parent 3574993746
commit 1bb369aa7d
7 changed files with 96 additions and 46 deletions

View File

@ -90,7 +90,27 @@ namespace :justask do
fail "user #{args[:screen_name]} not found" if user.nil? fail "user #{args[:screen_name]} not found" if user.nil?
user.moderator = false user.moderator = false
user.save! user.save!
puts "#{user.screen_name} no longer an moderator." puts "#{user.screen_name} is no longer an moderator."
end
desc "Hits an user with the banhammer."
task :ban, [:screen_name] => :environment do |t, args|
fail "screen name required" if args[:screen_name].nil?
user = User.find_by_screen_name(args[:screen_name])
fail "user #{args[:screen_name]} not found" if user.nil?
user.banned = true
user.save!
puts "#{user.screen_name} got hit by\033[5m YE OLDE BANHAMMER\033[0m!!1!"
end
desc "Removes banned status from an user."
task :unban, [:screen_name] => :environment do |t, args|
fail "screen name required" if args[:screen_name].nil?
user = User.find_by_screen_name(args[:screen_name])
fail "user #{args[:screen_name]} not found" if user.nil?
user.banned = false
user.save!
puts "#{user.screen_name} is no longer banned."
end end
desc "Gives supporter status to an user." desc "Gives supporter status to an user."

View File

@ -121,3 +121,7 @@
.panel-badge-warning { .panel-badge-warning {
background-color: #FF9800; background-color: #FF9800;
} }
.user--banned {
text-decoration: line-through !important;
}

View File

@ -4,6 +4,18 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller? before_filter :configure_permitted_parameters, if: :devise_controller?
before_filter :banned?
# check if user got hit by the banhammer of doom
def banned?
if current_user.present? && current_user.banned?
name = current_user.screen_name
# obligatory '2001: A Space Odyssey' reference
flash[:notice] = "I'm sorry, #{name}, I'm afraid I can't do that."
sign_out current_user
redirect_to new_user_session_path
end
end
include ApplicationHelper include ApplicationHelper

View File

@ -4,7 +4,7 @@ module UserHelper
def user_screen_name(user, anonymous=false, url=true) def user_screen_name(user, anonymous=false, url=true)
return APP_CONFIG['anonymous_name'] if user.nil? || anonymous return APP_CONFIG['anonymous_name'] if user.nil? || anonymous
name = user.display_name.blank? ? user.screen_name : user.display_name name = user.display_name.blank? ? user.screen_name : user.display_name
return link_to(name, show_user_profile_path(user.screen_name)) if url return link_to(name, show_user_profile_path(user.screen_name), class: "#{"user--banned" if user.banned?}") if url
name name
end end
end end

View File

@ -6,6 +6,11 @@
- else - else
= @user.motivation_header = @user.motivation_header
.panel-body .panel-body
- if @user.banned?
.row
.col-xs-12.text-center
%strong This user got hit with ye olde banhammer.
- else
- if user_signed_in? or @user.privacy_allow_anonymous_questions? - if user_signed_in? or @user.privacy_allow_anonymous_questions?
#question-box #question-box
.row .row

View File

@ -12,6 +12,10 @@
.profile--panel-badge.panel-badge-warning .profile--panel-badge.panel-badge-warning
%i.fa.fa-star %i.fa.fa-star
Supporter Supporter
- if @user.banned?
.profile--panel-badge.panel-badge-default
%i.fa.fa-ban
Banned
- if @user.following? current_user - if @user.following? current_user
.profile--panel-badge.panel-badge-default .profile--panel-badge.panel-badge-default
Follows you Follows you

View File

@ -0,0 +1,5 @@
class AddBannedToUsers < ActiveRecord::Migration
def change
add_column :users, :banned, :boolean, default: false
end
end