Skip to content

Commit 8900044

Browse files
committed
Added admin ability to unsuspend locked accounts #changelog
1 parent e94087d commit 8900044

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

app/controllers/admin/UsersController.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,49 @@ public function getDatatable()
484484
->make();
485485
}
486486

487+
/**
488+
* Unsuspend the given user.
489+
*
490+
* @param int $id
491+
* @return Redirect
492+
*/
493+
public function getUnsuspend($id = null)
494+
{
495+
try {
496+
// Get user information
497+
$user = Sentry::getUserProvider()->findById($id);
498+
499+
// Check if we are not trying to unsuspend ourselves
500+
if ($user->id === Sentry::getId()) {
501+
// Prepare the error message
502+
$error = Lang::get('admin/users/message.error.unsuspend');
503+
504+
// Redirect to the user management page
505+
return Redirect::route('users')->with('error', $error);
506+
}
507+
508+
// Do we have permission to unsuspend this user?
509+
if ($user->isSuperUser() and ! Sentry::getUser()->isSuperUser()) {
510+
// Redirect to the user management page
511+
return Redirect::route('users')->with('error', 'Insufficient permissions!');
512+
}
513+
514+
// Unsuspend the user
515+
$throttle = Sentry::findThrottlerByUserId($id);
516+
$throttle->unsuspend();
517+
518+
// Prepare the success message
519+
$success = Lang::get('admin/users/message.success.unsuspend');
520+
521+
// Redirect to the user management page
522+
return Redirect::route('users')->with('success', $success);
523+
} catch (UserNotFoundException $e) {
524+
// Prepare the error message
525+
$error = Lang::get('admin/users/message.user_not_found', compact('id' ));
526+
527+
// Redirect to the user management page
528+
return Redirect::route('users')->with('error', $error);
529+
}
530+
}
531+
487532
}

app/lang/en/admin/users/message.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'create' => 'There was an issue creating the user. Please try again.',
2424
'update' => 'There was an issue updating the user. Please try again.',
2525
'delete' => 'There was an issue deleting the user. Please try again.',
26+
'unsuspend' => 'There was an issue unsuspending the user. Please try again.'
2627
),
2728

2829
);

app/models/User.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,18 @@ public function manager()
7474
return $this->belongsTo('User','manager_id')->withTrashed();
7575
}
7676

77+
public function accountStatus()
78+
{
79+
$throttle = Sentry::findThrottlerByUserId($this->id);
80+
81+
if ($throttle->isBanned()) {
82+
return 'banned';
83+
} elseif ($throttle->isSuspended()) {
84+
return 'suspended';
85+
} else {
86+
return '';
87+
}
88+
89+
}
90+
7791
}

app/routes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@
157157
Route::get('{userId}/delete', array('as' => 'delete/user', 'uses' => 'Controllers\Admin\UsersController@getDelete'));
158158
Route::get('{userId}/restore', array('as' => 'restore/user', 'uses' => 'Controllers\Admin\UsersController@getRestore'));
159159
Route::get('{userId}/view', array('as' => 'view/user', 'uses' => 'Controllers\Admin\UsersController@getView'));
160+
Route::get('{userId}/unsuspend', array('as' => 'unsuspend/user', 'uses' => 'Controllers\Admin\UsersController@getUnsuspend'));
161+
160162

161163
Route::get('datatable', array('as'=>'api.users', 'uses'=>'Controllers\Admin\UsersController@getDatatable'));
162164
});

app/views/backend/users/index.blade.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<th class="col-md-1">@lang('general.assets')</th>
4343
<th class="col-md-1">@lang('general.licenses')</th>
4444
<th class="col-md-1">@lang('admin/users/table.activated')</th>
45+
<th></th>
4546
<th class="col-md-2 actions">@lang('table.actions')</th>
4647
</tr>
4748
</thead>
@@ -64,6 +65,13 @@
6465
<td>{{ $user->isActivated() ? '<i class="icon-ok"></i>' : ''}}</td>
6566
<td>
6667

68+
69+
@if ($user->accountStatus()=='suspended')
70+
<a href="{{ route('unsuspend/user', $user->id) }}" class="btn btn-warning"><span class="icon-time icon-white"></span></a>
71+
@endif
72+
</td>
73+
<td>
74+
6775
@if ( ! is_null($user->deleted_at))
6876
<a href="{{ route('restore/user', $user->id) }}" class="btn btn-warning"><i class="icon-share-alt icon-white"></i></a>
6977
@else

app/views/backend/users/view.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
<td>{{{ $log->added_on }}}</td>
142142
<td>{{{ $log->action_type }}}</td>
143143
<td>
144+
144145
@if ((isset($log->assetlog->name)) && ($log->assetlog->deleted_at==''))
145146
<a href="{{ route('view/hardware', $log->asset_id) }}">{{{ $log->assetlog->asset_tag }}}</a>
146147
@elseif ((isset($log->assetlog->name)) && ($log->assetlog->deleted_at!=''))

0 commit comments

Comments
 (0)