Enable restoring users and re-sending invitations

This commit is contained in:
Hillel Coren 2015-02-11 14:39:00 +02:00
parent 276b23da95
commit 2c6cce1707
5 changed files with 92 additions and 27 deletions

View File

@ -85,7 +85,11 @@ class AccountController extends \BaseController
{ {
Session::put("show_trash:{$entityType}", $visible == 'true'); Session::put("show_trash:{$entityType}", $visible == 'true');
return Redirect::to("{$entityType}s"); if ($entityType == 'user') {
return Redirect::to('company/'.ACCOUNT_ADVANCED_SETTINGS.'/'.ACCOUNT_USER_MANAGEMENT);
} else {
return Redirect::to("{$entityType}s");
}
} }
public function getSearchData() public function getSearchData()

View File

@ -31,26 +31,43 @@ class UserController extends BaseController
public function getDatatable() public function getDatatable()
{ {
$query = DB::table('users') $query = DB::table('users')
->where('users.account_id', '=', Auth::user()->account_id) ->where('users.account_id', '=', Auth::user()->account_id);
->where('users.deleted_at', '=', null)
->where('users.public_id', '>', 0) if (!Session::get('show_trash:user')) {
->select('users.public_id', 'users.first_name', 'users.last_name', 'users.email', 'users.confirmed', 'users.public_id'); $query->where('users.deleted_at', '=', null);
}
$query->where('users.public_id', '>', 0)
->select('users.public_id', 'users.first_name', 'users.last_name', 'users.email', 'users.confirmed', 'users.public_id', 'users.deleted_at');
return Datatable::query($query) return Datatable::query($query)
->addColumn('first_name', function ($model) { return link_to('users/'.$model->public_id.'/edit', $model->first_name.' '.$model->last_name); }) ->addColumn('first_name', function ($model) { return link_to('users/'.$model->public_id.'/edit', $model->first_name.' '.$model->last_name); })
->addColumn('email', function ($model) { return $model->email; }) ->addColumn('email', function ($model) { return $model->email; })
->addColumn('confirmed', function ($model) { return $model->confirmed ? trans('texts.active') : trans('texts.pending'); }) ->addColumn('confirmed', function ($model) { return $model->deleted_at ? trans('texts.deleted') : ($model->confirmed ? trans('texts.active') : trans('texts.pending')); })
->addColumn('dropdown', function ($model) { ->addColumn('dropdown', function ($model) {
return '<div class="btn-group tr-action" style="visibility:hidden;"> $actions = '<div class="btn-group tr-action" style="visibility:hidden;">
<button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown"> <button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown">
'.trans('texts.select').' <span class="caret"></span> '.trans('texts.select').' <span class="caret"></span>
</button> </button>
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">';
<li><a href="'.URL::to('users/'.$model->public_id).'/edit">'.uctrans('texts.edit_user').'</a></li>
<li class="divider"></li> if ($model->deleted_at) {
<li><a href="javascript:deleteUser('.$model->public_id.')">'.uctrans('texts.delete_user').'</a></li> $actions .= '<li><a href="'.URL::to('restore_user/'.$model->public_id).'">'.uctrans('texts.restore_user').'</a></li>';
</ul> } else {
$actions .= '<li><a href="'.URL::to('users/'.$model->public_id).'/edit">'.uctrans('texts.edit_user').'</a></li>';
if (!$model->confirmed) {
$actions .= '<li><a href="'.URL::to('send_confirmation/'.$model->public_id).'">'.uctrans('texts.send_invite').'</a></li>';
}
$actions .= '<li class="divider"></li>
<li><a href="javascript:deleteUser('.$model->public_id.')">'.uctrans('texts.delete_user').'</a></li>';
}
$actions .= '</ul>
</div>'; </div>';
return $actions;
}) })
->orderColumns(['first_name', 'email', 'confirmed']) ->orderColumns(['first_name', 'email', 'confirmed'])
->make(); ->make();
@ -147,6 +164,19 @@ class UserController extends BaseController
return Redirect::to('company/advanced_settings/user_management'); return Redirect::to('company/advanced_settings/user_management');
} }
public function restoreUser($userPublicId)
{
$user = User::where('account_id', '=', Auth::user()->account_id)
->where('public_id', '=', $userPublicId)
->withTrashed()->firstOrFail();
$user->restore();
Session::flash('message', trans('texts.restored_user'));
return Redirect::to('company/advanced_settings/user_management');
}
/** /**
* Stores new account * Stores new account
* *
@ -208,6 +238,17 @@ class UserController extends BaseController
return Redirect::to('company/advanced_settings/user_management'); return Redirect::to('company/advanced_settings/user_management');
} }
public function sendConfirmation($userPublicId)
{
$user = User::where('account_id', '=', Auth::user()->account_id)
->where('public_id', '=', $userPublicId)->firstOrFail();
$this->userMailer->sendConfirmation($user, Auth::user());
Session::flash('message', trans('texts.sent_invite'));
return Redirect::to('company/advanced_settings/user_management');
}
/** /**
* Displays the login form * Displays the login form
* *

View File

@ -303,7 +303,7 @@ return array(
'email_taken' => 'The email address is already registered', 'email_taken' => 'The email address is already registered',
'working' => 'Working', 'working' => 'Working',
'success' => 'Success', 'success' => 'Success',
'success_message' => 'You have succesfully registered. Please visit the link in the account confirmation email to verify your email address.', 'success_message' => 'You have successfully registered. Please visit the link in the account confirmation email to verify your email address.',
'erase_data' => 'This will permanently erase your data.', 'erase_data' => 'This will permanently erase your data.',
'password' => 'Password', 'password' => 'Password',
@ -499,5 +499,9 @@ return array(
'edit_payment' => 'Edit Payment', 'edit_payment' => 'Edit Payment',
'updated_payment' => 'Successfully updated payment', 'updated_payment' => 'Successfully updated payment',
'deleted' => 'Deleted',
'restore_user' => 'Restore User',
'restored_user' => 'Successfully restored user',
'show_deleted_users' => 'Show deleted users',
); );

View File

@ -88,6 +88,8 @@ Route::group(array('before' => 'auth'), function() {
Route::get('api/users', array('as'=>'api.users', 'uses'=>'UserController@getDatatable')); Route::get('api/users', array('as'=>'api.users', 'uses'=>'UserController@getDatatable'));
Route::resource('users', 'UserController'); Route::resource('users', 'UserController');
Route::post('users/delete', 'UserController@delete'); Route::post('users/delete', 'UserController@delete');
Route::get('send_confirmation/{user_id}', 'UserController@sendConfirmation');
Route::get('restore_user/{user_id}', 'UserController@restoreUser');
Route::get('api/products', array('as'=>'api.products', 'uses'=>'ProductController@getDatatable')); Route::get('api/products', array('as'=>'api.products', 'uses'=>'ProductController@getDatatable'));
Route::resource('products', 'ProductController'); Route::resource('products', 'ProductController');

View File

@ -1,12 +1,14 @@
@extends('accounts.nav') @extends('accounts.nav')
@section('content') @section('content')
@parent @parent
@include('accounts.nav_advanced') @include('accounts.nav_advanced')
{{ Former::open('users/delete')->addClass('user-form') }} {{ Former::open('users/delete')->addClass('user-form') }}
{{ Former::legend('user_management') }} {{ Former::legend('user_management') }}
<div style="display:none"> <div style="display:none">
{{ Former::text('userPublicId') }} {{ Former::text('userPublicId') }}
</div> </div>
@ -14,34 +16,46 @@
@if (Utils::isPro()) @if (Utils::isPro())
{{ Button::success_link(URL::to('users/create'), trans("texts.add_user"), array('class' => 'pull-right'))->append_with_icon('plus-sign') }} {{ Button::success_link(URL::to('users/create'), trans("texts.add_user"), array('class' => 'pull-right'))->append_with_icon('plus-sign') }}
@endif @endif
{{ Datatable::table()
<label for="trashed" style="font-weight:normal; margin-left: 10px;">
<input id="trashed" type="checkbox" onclick="setTrashVisible()"
{{ Session::get('show_trash:user') ? 'checked' : ''}}/> {{ trans('texts.show_deleted_users')}}
</label>
{{ Datatable::table()
->addColumn( ->addColumn(
trans('texts.name'), trans('texts.name'),
trans('texts.email'), trans('texts.email'),
trans('texts.user_state'), trans('texts.user_state'),
trans('texts.action')) trans('texts.action'))
->setUrl(url('api/users/')) ->setUrl(url('api/users/'))
->setOptions('sPaginationType', 'bootstrap') ->setOptions('sPaginationType', 'bootstrap')
->setOptions('bFilter', false) ->setOptions('bFilter', false)
->setOptions('bAutoWidth', false) ->setOptions('bAutoWidth', false)
->setOptions('aoColumns', [[ "sWidth"=> "20%" ], [ "sWidth"=> "45%" ], ["sWidth"=> "20%"], ["sWidth"=> "15%" ]]) ->setOptions('aoColumns', [[ "sWidth"=> "20%" ], [ "sWidth"=> "45%" ], ["sWidth"=> "20%"], ["sWidth"=> "15%" ]])
->setOptions('aoColumnDefs', [['bSortable'=>false, 'aTargets'=>[3]]]) ->setOptions('aoColumnDefs', [['bSortable'=>false, 'aTargets'=>[3]]])
->render('datatable') }} ->render('datatable') }}
<script> <script>
window.onDatatableReady = function() { window.onDatatableReady = function() {
$('tbody tr').mouseover(function() { $('tbody tr').mouseover(function() {
$(this).closest('tr').find('.tr-action').css('visibility','visible'); $(this).closest('tr').find('.tr-action').css('visibility','visible');
}).mouseout(function() { }).mouseout(function() {
$dropdown = $(this).closest('tr').find('.tr-action'); $dropdown = $(this).closest('tr').find('.tr-action');
if (!$dropdown.hasClass('open')) { if (!$dropdown.hasClass('open')) {
$dropdown.css('visibility','hidden'); $dropdown.css('visibility','hidden');
} }
}); });
} }
function setTrashVisible() {
var checked = $('#trashed').is(':checked');
window.location = '{{ URL::to('view_archive/user') }}' + (checked ? '/true' : '/false');
}
function deleteUser(id) { function deleteUser(id) {
if (!confirm('Are you sure?')) { if (!confirm('Are you sure?')) {
@ -49,8 +63,8 @@
} }
$('#userPublicId').val(id); $('#userPublicId').val(id);
$('form.user-form').submit(); $('form.user-form').submit();
} }
</script> </script>
@stop @stop