Skip to content

Commit

Permalink
Added admin ability to unsuspend locked accounts #changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Jul 16, 2014
1 parent e94087d commit 8900044
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 0 deletions.
45 changes: 45 additions & 0 deletions app/controllers/admin/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,49 @@ public function getDatatable()
->make();
}

/**
* Unsuspend the given user.
*
* @param int $id
* @return Redirect
*/
public function getUnsuspend($id = null)
{
try {
// Get user information
$user = Sentry::getUserProvider()->findById($id);

// Check if we are not trying to unsuspend ourselves
if ($user->id === Sentry::getId()) {
// Prepare the error message
$error = Lang::get('admin/users/message.error.unsuspend');

// Redirect to the user management page
return Redirect::route('users')->with('error', $error);
}

// Do we have permission to unsuspend this user?
if ($user->isSuperUser() and ! Sentry::getUser()->isSuperUser()) {
// Redirect to the user management page
return Redirect::route('users')->with('error', 'Insufficient permissions!');
}

// Unsuspend the user
$throttle = Sentry::findThrottlerByUserId($id);
$throttle->unsuspend();

// Prepare the success message
$success = Lang::get('admin/users/message.success.unsuspend');

// Redirect to the user management page
return Redirect::route('users')->with('success', $success);
} catch (UserNotFoundException $e) {
// Prepare the error message
$error = Lang::get('admin/users/message.user_not_found', compact('id' ));

// Redirect to the user management page
return Redirect::route('users')->with('error', $error);
}
}

}
1 change: 1 addition & 0 deletions app/lang/en/admin/users/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'create' => 'There was an issue creating the user. Please try again.',
'update' => 'There was an issue updating the user. Please try again.',
'delete' => 'There was an issue deleting the user. Please try again.',
'unsuspend' => 'There was an issue unsuspending the user. Please try again.'
),

);
14 changes: 14 additions & 0 deletions app/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,18 @@ public function manager()
return $this->belongsTo('User','manager_id')->withTrashed();
}

public function accountStatus()
{
$throttle = Sentry::findThrottlerByUserId($this->id);

if ($throttle->isBanned()) {
return 'banned';
} elseif ($throttle->isSuspended()) {
return 'suspended';
} else {
return '';
}

}

}
2 changes: 2 additions & 0 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
Route::get('{userId}/delete', array('as' => 'delete/user', 'uses' => 'Controllers\Admin\UsersController@getDelete'));
Route::get('{userId}/restore', array('as' => 'restore/user', 'uses' => 'Controllers\Admin\UsersController@getRestore'));
Route::get('{userId}/view', array('as' => 'view/user', 'uses' => 'Controllers\Admin\UsersController@getView'));
Route::get('{userId}/unsuspend', array('as' => 'unsuspend/user', 'uses' => 'Controllers\Admin\UsersController@getUnsuspend'));


Route::get('datatable', array('as'=>'api.users', 'uses'=>'Controllers\Admin\UsersController@getDatatable'));
});
Expand Down
8 changes: 8 additions & 0 deletions app/views/backend/users/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<th class="col-md-1">@lang('general.assets')</th>
<th class="col-md-1">@lang('general.licenses')</th>
<th class="col-md-1">@lang('admin/users/table.activated')</th>
<th></th>
<th class="col-md-2 actions">@lang('table.actions')</th>
</tr>
</thead>
Expand All @@ -64,6 +65,13 @@
<td>{{ $user->isActivated() ? '<i class="icon-ok"></i>' : ''}}</td>
<td>


@if ($user->accountStatus()=='suspended')
<a href="{{ route('unsuspend/user', $user->id) }}" class="btn btn-warning"><span class="icon-time icon-white"></span></a>
@endif
</td>
<td>

@if ( ! is_null($user->deleted_at))
<a href="{{ route('restore/user', $user->id) }}" class="btn btn-warning"><i class="icon-share-alt icon-white"></i></a>
@else
Expand Down
1 change: 1 addition & 0 deletions app/views/backend/users/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<td>{{{ $log->added_on }}}</td>
<td>{{{ $log->action_type }}}</td>
<td>

@if ((isset($log->assetlog->name)) && ($log->assetlog->deleted_at==''))
<a href="{{ route('view/hardware', $log->asset_id) }}">{{{ $log->assetlog->asset_tag }}}</a>
@elseif ((isset($log->assetlog->name)) && ($log->assetlog->deleted_at!=''))
Expand Down

0 comments on commit 8900044

Please sign in to comment.