From 1bb369aa7d2dfdd275a53c66de72323d61ed4bdf Mon Sep 17 00:00:00 2001 From: nilsding Date: Mon, 12 Jan 2015 22:44:13 +0100 Subject: [PATCH] implemented basic functionality of YE OLDE BANHAMMER! --- Rakefile | 24 ++++- app/assets/stylesheets/scss/user.scss | 4 + app/controllers/application_controller.rb | 12 +++ app/helpers/user_helper.rb | 2 +- app/views/shared/_questionbox.html.haml | 91 ++++++++++--------- app/views/user/_profile_info.html.haml | 4 + .../20150112210754_add_banned_to_users.rb | 5 + 7 files changed, 96 insertions(+), 46 deletions(-) create mode 100644 db/migrate/20150112210754_add_banned_to_users.rb diff --git a/Rakefile b/Rakefile index 9c92daf4..8c169681 100644 --- a/Rakefile +++ b/Rakefile @@ -72,7 +72,7 @@ namespace :justask do user.save! puts "#{user.screen_name} no longer an admin." end - + desc "Gives moderator status to an user." task :mod, [:screen_name] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? @@ -90,7 +90,27 @@ namespace :justask do fail "user #{args[:screen_name]} not found" if user.nil? user.moderator = false 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 desc "Gives supporter status to an user." diff --git a/app/assets/stylesheets/scss/user.scss b/app/assets/stylesheets/scss/user.scss index 14c314fe..55101e25 100644 --- a/app/assets/stylesheets/scss/user.scss +++ b/app/assets/stylesheets/scss/user.scss @@ -120,4 +120,8 @@ .panel-badge-warning { background-color: #FF9800; +} + +.user--banned { + text-decoration: line-through !important; } \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f02cdaa6..42840939 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,18 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception 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 diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb index babb3f22..4e3e599d 100644 --- a/app/helpers/user_helper.rb +++ b/app/helpers/user_helper.rb @@ -4,7 +4,7 @@ module UserHelper def user_screen_name(user, anonymous=false, url=true) return APP_CONFIG['anonymous_name'] if user.nil? || anonymous 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 end end diff --git a/app/views/shared/_questionbox.html.haml b/app/views/shared/_questionbox.html.haml index 89bceb2d..34c79e0a 100644 --- a/app/views/shared/_questionbox.html.haml +++ b/app/views/shared/_questionbox.html.haml @@ -6,47 +6,52 @@ - else = @user.motivation_header .panel-body - - if user_signed_in? or @user.privacy_allow_anonymous_questions? - #question-box - .row - .col-xs-12 - %textarea.form-control{:name => "qb-question", :placeholder => "Type your question here…"} - .row{:style => "padding-top: 5px; padding-left: 5px; padding-right: 5px;"} - .col-xs-6 - - if user_signed_in? - - if @user.privacy_allow_anonymous_questions? - %input{:name => "qb-anonymous", :type => "checkbox"}/ - Hide your name - %br/ - - else - %input{:name => "qb-anonymous", :type => "hidden", :value => "false"}/ - .col-xs-6 - %p.pull-right - %input{name: 'qb-to', type: 'hidden', :value => @user.id}/ - %button.btn.btn-primary{name: 'qb-ask', :type => "button", data: {loading_text: 'Asking...', promote: user_signed_in? ? "false" : "true" }} Ask - - unless user_signed_in? - - if @user.privacy_allow_anonymous_questions? - #question-box-promote.row{:style => "display: none;"} + - 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? + #question-box .row - .col-xs-12.text-center - %strong Your question has been sent. - .row - .col-sm-1 - .col-sm-5 - %button#create-account.btn.btn-block.btn-primary Create an account - .col-sm-5 - %button#new-question.btn.btn-block.btn-default Ask another question - .col-sm-1 - .row - .col-sm-1 - .col-xs-12.col-sm-10 - %small - Join - = APP_CONFIG['site_name'] - today! You'll be able to follow and ask people you know and a lot more. - .col-sm-1 - - else - %p - This user does not want to get asked by strangers. Why don't you - = succeed "?" do - %a{:href => "{{ url_for('register') }}"} sign up \ No newline at end of file + .col-xs-12 + %textarea.form-control{:name => "qb-question", :placeholder => "Type your question here…"} + .row{:style => "padding-top: 5px; padding-left: 5px; padding-right: 5px;"} + .col-xs-6 + - if user_signed_in? + - if @user.privacy_allow_anonymous_questions? + %input{:name => "qb-anonymous", :type => "checkbox"}/ + Hide your name + %br/ + - else + %input{:name => "qb-anonymous", :type => "hidden", :value => "false"}/ + .col-xs-6 + %p.pull-right + %input{name: 'qb-to', type: 'hidden', :value => @user.id}/ + %button.btn.btn-primary{name: 'qb-ask', :type => "button", data: {loading_text: 'Asking...', promote: user_signed_in? ? "false" : "true" }} Ask + - unless user_signed_in? + - if @user.privacy_allow_anonymous_questions? + #question-box-promote.row{:style => "display: none;"} + .row + .col-xs-12.text-center + %strong Your question has been sent. + .row + .col-sm-1 + .col-sm-5 + %button#create-account.btn.btn-block.btn-primary Create an account + .col-sm-5 + %button#new-question.btn.btn-block.btn-default Ask another question + .col-sm-1 + .row + .col-sm-1 + .col-xs-12.col-sm-10 + %small + Join + = APP_CONFIG['site_name'] + today! You'll be able to follow and ask people you know and a lot more. + .col-sm-1 + - else + %p + This user does not want to get asked by strangers. Why don't you + = succeed "?" do + %a{:href => "{{ url_for('register') }}"} sign up \ No newline at end of file diff --git a/app/views/user/_profile_info.html.haml b/app/views/user/_profile_info.html.haml index 01b60fb2..dc310f11 100644 --- a/app/views/user/_profile_info.html.haml +++ b/app/views/user/_profile_info.html.haml @@ -12,6 +12,10 @@ .profile--panel-badge.panel-badge-warning %i.fa.fa-star Supporter + - if @user.banned? + .profile--panel-badge.panel-badge-default + %i.fa.fa-ban + Banned - if @user.following? current_user .profile--panel-badge.panel-badge-default Follows you diff --git a/db/migrate/20150112210754_add_banned_to_users.rb b/db/migrate/20150112210754_add_banned_to_users.rb new file mode 100644 index 00000000..6b7c65b7 --- /dev/null +++ b/db/migrate/20150112210754_add_banned_to_users.rb @@ -0,0 +1,5 @@ +class AddBannedToUsers < ActiveRecord::Migration + def change + add_column :users, :banned, :boolean, default: false + end +end