Commit 969129f4 authored by Viral Solani's avatar Viral Solani

- add a feature to permanently delete user and add test case for that

- test cases for activate and re-activate user
- resolve issues and minor refactoring
parent 64b10c91
......@@ -213,9 +213,9 @@ trait UserAttribute
/**
* @return string
*/
public function getDeletePermanentlyButtonAttribute()
public function getDeletePermanentlyButtonAttribute($class)
{
return '<a href="'.route('admin.access.user.delete-permanently', $this).'" name="delete_user_perm"><i class="fa fa-trash" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.delete_permanently').'"></i></a> ';
return '<a class="'.$class.'" href="'.route('admin.access.user.delete-permanently', $this).'" name="delete_user_perm"><i class="fa fa-trash" data-toggle="tooltip" data-placement="top" title="'.trans('buttons.backend.access.users.delete_permanently').'"></i></a> ';
}
/**
......@@ -383,7 +383,10 @@ trait UserAttribute
public function getActionButtonsAttribute()
{
if ($this->trashed()) {
return '<div class="btn-group action-btn">'.$this->getRestoreButtonAttribute('btn btn-default btn-flat').'</div>';
return '<div class="btn-group action-btn">
'.$this->getRestoreButtonAttribute('btn btn-default btn-flat').'
'.$this->getDeletePermanentlyButtonAttribute('btn btn-default btn-flat').'
</div>';
}
// Check if role have all permission
......
......@@ -211,11 +211,11 @@ class UserRepository extends BaseRepository
}
/**
* @param Model $user
* @param $user
*
* @throws GeneralException
*/
public function forceDelete(Model $user)
public function forceDelete($user)
{
if (is_null($user->deleted_at)) {
throw new GeneralException(trans('exceptions.backend.access.users.delete_first'));
......@@ -233,13 +233,13 @@ class UserRepository extends BaseRepository
}
/**
* @param Model $user
* @param $user
*
* @throws GeneralException
*
* @return bool
*/
public function restore(Model $user)
public function restore($user)
{
if (is_null($user->deleted_at)) {
throw new GeneralException(trans('exceptions.backend.access.users.cant_restore'));
......@@ -255,14 +255,14 @@ class UserRepository extends BaseRepository
}
/**
* @param Model $user
* @param $user
* @param $status
*
* @throws GeneralException
*
* @return bool
*/
public function mark(Model $user, $status)
public function mark($user, $status)
{
if (access()->id() == $user->id && $status == 0) {
throw new GeneralException(trans('exceptions.backend.access.users.cant_deactivate_self'));
......@@ -281,13 +281,6 @@ class UserRepository extends BaseRepository
}
if ($user->save()) {
// Send email to the user
$options = [
'data' => $user,
'email_template_type' => 3,
];
createNotification('', $user->id, 2, $options);
return true;
}
......
......@@ -2,16 +2,21 @@
namespace Tests\Feature\Backend;
use App\Events\Backend\Access\User\UserCreated;
use App\Events\Backend\Access\User\UserDeleted;
use App\Events\Backend\Access\User\UserUpdated;
use App\Models\Access\Permission\Permission;
use Carbon\Carbon;
use Tests\TestCase;
use App\Models\Access\Role\Role;
use App\Models\Access\User\User;
use App\Notifications\Frontend\Auth\UserNeedsConfirmation;
use Illuminate\Support\Facades\Event;
use App\Models\Access\Permission\Permission;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
use App\Events\Backend\Access\User\UserCreated;
use App\Events\Backend\Access\User\UserDeleted;
use App\Events\Backend\Access\User\UserUpdated;
use App\Events\Backend\Access\User\UserRestored;
use App\Events\Backend\Access\User\UserDeactivated;
use App\Events\Backend\Access\User\UserReactivated;
use App\Events\Backend\Access\User\UserPermanentlyDeleted;
use App\Notifications\Frontend\Auth\UserNeedsConfirmation;
class ManageUsersTest extends TestCase
{
......@@ -298,6 +303,56 @@ class ManageUsersTest extends TestCase
$this->assertDatabaseHas(config('access.users_table'), ['id' => $this->admin->id, 'deleted_at' => null]);
}
// change password
// export / import feature
/** @test */
public function a_user_can_restore_a_deleted_user()
{
Event::fake();
$this->user->deleted_at = Carbon::now();
$this->user->save();
$this->actingAs($this->admin)
->get(route('admin.access.user.restore', $this->user))
->assertSessionHas(['flash_success' => trans('alerts.backend.users.restored')]);
Event::assertDispatched(UserRestored::class);
}
/** @test */
public function a_user_can_permanently_delete_user()
{
Event::fake();
$this->user->deleted_at = Carbon::now();
$this->user->save();
$this->actingAs($this->admin)
->get(route('admin.access.user.delete-permanently', $this->user))
->assertSessionHas(['flash_success' => trans('alerts.backend.users.deleted_permanently')]);
Event::assertDispatched(UserPermanentlyDeleted::class);
}
/** @test */
public function a_user_can_mark_user_as_inactive_and_active()
{
Event::fake();
$this->actingAs($this->admin)
->get(route('admin.access.user.mark', [$this->user, 0]))
->assertSessionHas(['flash_success' => trans('alerts.backend.users.updated')]);
$this->assertDatabaseHas(config('access.users_table'), ['id' => $this->user->id, 'status' => 0]);
$this->actingAs($this->admin)
->get(route('admin.access.user.mark', [$this->user, 1]))
->assertSessionHas(['flash_success' => trans('alerts.backend.users.updated')]);
$this->assertDatabaseHas(config('access.users_table'), ['id' => $this->user->id, 'status' => 1]);
Event::assertDispatched(UserDeactivated::class);
Event::assertDispatched(UserReactivated::class);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment