Lock account #5564
This commit is contained in:
parent
b4ab31d6f9
commit
3bb5e78893
6 changed files with 47 additions and 6 deletions
|
|
@ -2,15 +2,22 @@ module Admin
|
||||||
class UsersController < AdminController
|
class UsersController < AdminController
|
||||||
|
|
||||||
def close_account
|
def close_account
|
||||||
u = User.find(close_account_params)
|
u = User.find(params[:id])
|
||||||
u.close_account!
|
u.close_account!
|
||||||
redirect_to user_search_path, notice: t('admins.user_search.account_closing_scheduled', name: u.username)
|
redirect_to user_search_path, notice: t("admins.user_search.account_closing_scheduled", name: u.username)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def lock_account
|
||||||
|
u = User.find(params[:id])
|
||||||
def close_account_params
|
u.lock_access!
|
||||||
params.require(:id)
|
redirect_to user_search_path, notice: t("admins.user_search.account_locking_scheduled", name: u.username)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unlock_account
|
||||||
|
u = User.find(params[:id])
|
||||||
|
u.unlock_access!
|
||||||
|
redirect_to user_search_path, notice: t("admins.user_search.account_unlocking_scheduled", name: u.username)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -480,6 +480,10 @@ class User < ActiveRecord::Base
|
||||||
AccountDeletion.create(:person => self.person)
|
AccountDeletion.create(:person => self.person)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def closed_account?
|
||||||
|
self.person.closed_account
|
||||||
|
end
|
||||||
|
|
||||||
def clear_account!
|
def clear_account!
|
||||||
clearable_fields.each do |field|
|
clearable_fields.each do |field|
|
||||||
self[field] = nil
|
self[field] = nil
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,12 @@
|
||||||
- unless user.person.closed_account
|
- unless user.person.closed_account
|
||||||
%li= link_to t('admins.user_search.close_account'), admin_close_account_path(user), method: :post, data: { confirm: t('admins.user_search.are_you_sure') }, class: 'btn btn-danger btn-mini'
|
%li= link_to t('admins.user_search.close_account'), admin_close_account_path(user), method: :post, data: { confirm: t('admins.user_search.are_you_sure') }, class: 'btn btn-danger btn-mini'
|
||||||
|
|
||||||
|
- unless user.closed_account?
|
||||||
|
- unless user.access_locked?
|
||||||
|
%li= link_to t('admins.user_search.lock_account'), admin_lock_account_path(user), method: :post, data: { confirm: t('admins.user_search.are_you_sure_lock_account') }, class: 'btn btn-danger btn-mini'
|
||||||
|
- else
|
||||||
|
%li= link_to t('admins.user_search.unlock_account'), admin_unlock_account_path(user), method: :post, data: { confirm: t('admins.user_search.are_you_sure_unlock_account') }, class: 'btn btn-danger btn-mini'
|
||||||
|
|
||||||
%div.row
|
%div.row
|
||||||
%div.span5
|
%div.span5
|
||||||
%dl.dl-horizontal
|
%dl.dl-horizontal
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,12 @@ en:
|
||||||
add_invites: "Add invites"
|
add_invites: "Add invites"
|
||||||
close_account: "Close account"
|
close_account: "Close account"
|
||||||
are_you_sure: "Are you sure you want to close this account?"
|
are_you_sure: "Are you sure you want to close this account?"
|
||||||
|
are_you_sure_lock_account: "Are you sure you want to lock this account?"
|
||||||
|
are_you_sure_unlock_account: "Are you sure you want to unlock this account?"
|
||||||
account_closing_scheduled: "The account of %{name} is scheduled to be closed. It will be processed in a few moments..."
|
account_closing_scheduled: "The account of %{name} is scheduled to be closed. It will be processed in a few moments..."
|
||||||
|
account_locking_scheduled: "The account of %{name} is scheduled to be locked. It will be processed in a few moments..."
|
||||||
|
account_unlocking_scheduled: "The account of %{name} is scheduled to be unlocked. It will be processed in a few moments..."
|
||||||
|
email_to: "Email to Invite"
|
||||||
email_to: "Email to invite"
|
email_to: "Email to invite"
|
||||||
under_13: "Show users that are under 13 (COPPA)"
|
under_13: "Show users that are under 13 (COPPA)"
|
||||||
users:
|
users:
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,8 @@ Diaspora::Application.routes.draw do
|
||||||
|
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
post 'users/:id/close_account' => 'users#close_account', :as => 'close_account'
|
post 'users/:id/close_account' => 'users#close_account', :as => 'close_account'
|
||||||
|
post 'users/:id/lock_account' => 'users#lock_account', :as => 'lock_account'
|
||||||
|
post 'users/:id/unlock_account' => 'users#unlock_account', :as => 'unlock_account'
|
||||||
end
|
end
|
||||||
|
|
||||||
resource :profile, :only => [:edit, :update]
|
resource :profile, :only => [:edit, :update]
|
||||||
|
|
|
||||||
|
|
@ -19,4 +19,21 @@ describe Admin::UsersController, :type => :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#lock_account' do
|
||||||
|
it 'it locks the given account' do
|
||||||
|
other_user = FactoryGirl.create :user
|
||||||
|
other_user.lock_access!
|
||||||
|
expect(other_user.reload.access_locked?).to be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#unlock_account' do
|
||||||
|
it 'it unlocks the given account' do
|
||||||
|
other_user = FactoryGirl.create :user
|
||||||
|
other_user.lock_access!
|
||||||
|
other_user.unlock_access!
|
||||||
|
expect(other_user.reload.access_locked?).to be_falsey
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue