From cc53e1762b2c3adaa1b03f546e15dc9ea0116518 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Mon, 23 Jun 2014 19:32:07 -0700 Subject: [PATCH] A podmin can now disable a spam account from the interface. --- app/controllers/admins_controller.rb | 6 ++++++ app/views/people/_profile_sidebar.html.haml | 4 ++++ config/routes.rb | 1 + spec/controllers/admins_controller_spec.rb | 11 +++++++++++ 4 files changed, 22 insertions(+) diff --git a/app/controllers/admins_controller.rb b/app/controllers/admins_controller.rb index 61569f33d..9a605699f 100644 --- a/app/controllers/admins_controller.rb +++ b/app/controllers/admins_controller.rb @@ -9,6 +9,12 @@ class AdminsController < ApplicationController @users = (@users || User).where(params[:user]) if params[:user].present? @users ||= [] end + + def remove_spammer + user = User.find(params[:user_id]) + user.close_account! + redirect_to root_url, notice:"this account will be deleted in a few moments" + end def admin_inviter inviter = InvitationCode.default_inviter_or(current_user) diff --git a/app/views/people/_profile_sidebar.html.haml b/app/views/people/_profile_sidebar.html.haml index 1cb71e448..a3ac1bc5f 100644 --- a/app/views/people/_profile_sidebar.html.haml +++ b/app/views/people/_profile_sidebar.html.haml @@ -90,3 +90,7 @@ %br %br + + + - if current_user.admin? && person.owner.present? + = link_to 'Disable Account', remove_spammer_path(user_id:person.owner.id), method: :delete, data:{confirm:'Are you sure you want to disable this account? It will delete all data associated.'} \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index dc659bbbb..cb7e67b06 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -128,6 +128,7 @@ Diaspora::Application.routes.draw do get :admin_inviter get :weekly_user_stats get :correlations + delete :remove_spammer get :stats, :as => 'pod_stats' get "add_invites/:invite_code_id" => 'admins#add_invites', :as => 'add_invites' end diff --git a/spec/controllers/admins_controller_spec.rb b/spec/controllers/admins_controller_spec.rb index 1ec8d2b41..efac914d4 100644 --- a/spec/controllers/admins_controller_spec.rb +++ b/spec/controllers/admins_controller_spec.rb @@ -102,6 +102,17 @@ describe AdminsController do end end end + + describe '#remove_spammer' do + it 'it queues a job to disable the given account' do + + other_user = FactoryGirl.create :user + + User.stub(:find).and_return(other_user) + delete :remove_spammer, user_id: other_user.id + other_user.should_receive(:close_account) + end + end describe '#stats' do before do