Merge pull request #5643 from aka001/5564_lock_account

Lock account #5564
This commit is contained in:
Jonne Haß 2015-02-19 03:42:45 +01:00
commit a19b91083e
7 changed files with 48 additions and 6 deletions

View file

@ -173,6 +173,7 @@ diaspora.yml file**. The existing settings from 0.4.x and before will not work a
* Make help sections linkable [#5667](https://github.com/diaspora/diaspora/pull/5667)
* Add invitation link to contacts page [#5655](https://github.com/diaspora/diaspora/pull/5655)
* Add year to notifications page [#5676](https://github.com/diaspora/diaspora/pull/5676)
* Give admins the ability to lock & unlock accounts [#5643](https://github.com/diaspora/diaspora/pull/5643)
# 0.4.1.2

View file

@ -2,15 +2,22 @@ module Admin
class UsersController < AdminController
def close_account
u = User.find(close_account_params)
u = User.find(params[:id])
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
private
def close_account_params
params.require(:id)
def lock_account
u = User.find(params[:id])
u.lock_access!
redirect_to user_search_path, notice: t("admins.user_search.account_locking_scheduled", name: u.username)
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

View file

@ -480,6 +480,10 @@ class User < ActiveRecord::Base
AccountDeletion.create(:person => self.person)
end
def closed_account?
self.person.closed_account
end
def clear_account!
clearable_fields.each do |field|
self[field] = nil

View file

@ -24,6 +24,12 @@
- 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'
- 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.span5
%dl.dl-horizontal

View file

@ -115,7 +115,12 @@ en:
add_invites: "Add invites"
close_account: "Close 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_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"
under_13: "Show users that are under 13 (COPPA)"
users:

View file

@ -143,6 +143,8 @@ Diaspora::Application.routes.draw do
namespace :admin do
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
resource :profile, :only => [:edit, :update]

View file

@ -19,4 +19,21 @@ describe Admin::UsersController, :type => :controller do
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