mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-10-22 07:52:19 +03:00
DB: Addressed test issues for user ID changes
Reverted change for activities table so that a record is retained of past activity, and added a check where the ID may be displayed to ensure it does not mislead and accidentially reference other, newer users.
This commit is contained in:
@@ -198,7 +198,6 @@ class UserRepo
|
|||||||
protected function nullifyUserNonDependantRelations(User $user): void
|
protected function nullifyUserNonDependantRelations(User $user): void
|
||||||
{
|
{
|
||||||
$toNullify = [
|
$toNullify = [
|
||||||
'activities' => ['user_id'],
|
|
||||||
'attachments' => ['created_by', 'updated_by'],
|
'attachments' => ['created_by', 'updated_by'],
|
||||||
'comments' => ['created_by', 'updated_by'],
|
'comments' => ['created_by', 'updated_by'],
|
||||||
'deletions' => ['deleted_by'],
|
'deletions' => ['deleted_by'],
|
||||||
|
@@ -6,7 +6,6 @@ use Illuminate\Support\Facades\Schema;
|
|||||||
|
|
||||||
return new class extends Migration {
|
return new class extends Migration {
|
||||||
protected static array $toNullify = [
|
protected static array $toNullify = [
|
||||||
'activities' => ['user_id'],
|
|
||||||
'attachments' => ['created_by', 'updated_by'],
|
'attachments' => ['created_by', 'updated_by'],
|
||||||
'comments' => ['created_by', 'updated_by'],
|
'comments' => ['created_by', 'updated_by'],
|
||||||
'deletions' => ['deleted_by'],
|
'deletions' => ['deleted_by'],
|
||||||
@@ -55,9 +54,6 @@ return new class extends Migration {
|
|||||||
DB::table($tableName)->whereNotIn($columnName, $idSelectQuery)->delete();
|
DB::table($tableName)->whereNotIn($columnName, $idSelectQuery)->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - Ensure each is fully handled in user delete
|
|
||||||
// Start by writing tests for each of these columns
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -88,7 +88,11 @@
|
|||||||
@foreach($activities as $activity)
|
@foreach($activities as $activity)
|
||||||
<div class="item-list-row flex-container-row items-center wrap py-xxs">
|
<div class="item-list-row flex-container-row items-center wrap py-xxs">
|
||||||
<div class="flex-2 px-m py-xxs flex-container-row items-center min-width-m">
|
<div class="flex-2 px-m py-xxs flex-container-row items-center min-width-m">
|
||||||
@include('settings.parts.table-user', ['user' => $activity->user, 'user_id' => $activity->user_id])
|
@if($activity->user && $activity->user->created_at <= $activity->created_at)
|
||||||
|
@include('settings.parts.table-user', ['user' => $activity->user])
|
||||||
|
@else
|
||||||
|
[ID: {{ $activity->user_id }}] {{ trans('common.deleted_user') }}
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-2 px-m py-xxs min-width-m"><strong
|
<div class="flex-2 px-m py-xxs min-width-m"><strong
|
||||||
class="mr-xs hide-over-m">{{ trans('settings.audit_table_event') }}
|
class="mr-xs hide-over-m">{{ trans('settings.audit_table_event') }}
|
||||||
|
@@ -1,12 +1,7 @@
|
|||||||
{{--
|
{{--
|
||||||
$user - User mode to display, Can be null.
|
$user - User to display.
|
||||||
$user_id - Id of user to show. Must be provided.
|
|
||||||
--}}
|
--}}
|
||||||
@if($user)
|
<a href="{{ $user->getEditUrl() }}" class="flex-container-row inline gap-s items-center">
|
||||||
<a href="{{ $user->getEditUrl() }}" class="flex-container-row inline gap-s items-center">
|
<div class="flex-none"><img width="40" height="40" class="avatar block" src="{{ $user->getAvatar(40)}}" alt="{{ $user->name }}"></div>
|
||||||
<div class="flex-none"><img width="40" height="40" class="avatar block" src="{{ $user->getAvatar(40)}}" alt="{{ $user->name }}"></div>
|
<div class="flex">{{ $user->name }}</div>
|
||||||
<div class="flex">{{ $user->name }}</div>
|
</a>
|
||||||
</a>
|
|
||||||
@else
|
|
||||||
[ID: {{ $user_id }}] {{ trans('common.deleted_user') }}
|
|
||||||
@endif
|
|
@@ -33,7 +33,14 @@
|
|||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-2 px-m py-xs flex-container-row items-center min-width-m">
|
<div class="flex-2 px-m py-xs flex-container-row items-center min-width-m">
|
||||||
<div><strong class="hide-over-l">{{ trans('settings.recycle_bin_deleted_by') }}:<br></strong>@include('settings.parts.table-user', ['user' => $deletion->deleter, 'user_id' => $deletion->deleted_by])</div>
|
<div>
|
||||||
|
<strong class="hide-over-l">{{ trans('settings.recycle_bin_deleted_by') }}:<br></strong>
|
||||||
|
@if($deletion->deleter)
|
||||||
|
@include('settings.parts.table-user', ['user' => $deletion->deleter, 'user_id' => $deletion->deleted_by])
|
||||||
|
@else
|
||||||
|
{{ trans('common.deleted_user') }}
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex px-m py-xs min-width-s"><strong class="hide-over-l">{{ trans('settings.recycle_bin_deleted_at') }}:<br></strong>{{ $deletion->created_at }}</div>
|
<div class="flex px-m py-xs min-width-s"><strong class="hide-over-l">{{ trans('settings.recycle_bin_deleted_at') }}:<br></strong>{{ $deletion->created_at }}</div>
|
||||||
<div class="flex px-m py-xs text-m-right min-width-s">
|
<div class="flex px-m py-xs text-m-right min-width-s">
|
||||||
|
@@ -83,6 +83,22 @@ class AuditLogTest extends TestCase
|
|||||||
$resp->assertSeeText("[ID: {$viewer->id}] Deleted User");
|
$resp->assertSeeText("[ID: {$viewer->id}] Deleted User");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_deleted_user_shows_if_user_created_date_is_later_than_activity()
|
||||||
|
{
|
||||||
|
$viewer = $this->users->viewer();
|
||||||
|
$this->actingAs($viewer);
|
||||||
|
$page = $this->entities->page();
|
||||||
|
$this->activityService->add(ActivityType::PAGE_CREATE, $page);
|
||||||
|
$viewer->created_at = Carbon::now()->addDay();
|
||||||
|
$viewer->save();
|
||||||
|
|
||||||
|
$this->actingAs($this->users->admin());
|
||||||
|
|
||||||
|
$resp = $this->get('settings/audit');
|
||||||
|
$resp->assertSeeText("[ID: {$viewer->id}] Deleted User");
|
||||||
|
$resp->assertDontSee($viewer->name);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_filters_by_key()
|
public function test_filters_by_key()
|
||||||
{
|
{
|
||||||
$this->actingAs($this->users->admin());
|
$this->actingAs($this->users->admin());
|
||||||
|
@@ -221,7 +221,6 @@ class UserManagementTest extends TestCase
|
|||||||
$watch = Watch::factory()->create(['user_id' => $user->id]);
|
$watch = Watch::factory()->create(['user_id' => $user->id]);
|
||||||
|
|
||||||
$userColumnsByTable = [
|
$userColumnsByTable = [
|
||||||
'activities' => ['user_id'],
|
|
||||||
'api_tokens' => ['user_id'],
|
'api_tokens' => ['user_id'],
|
||||||
'attachments' => ['created_by', 'updated_by'],
|
'attachments' => ['created_by', 'updated_by'],
|
||||||
'comments' => ['created_by', 'updated_by'],
|
'comments' => ['created_by', 'updated_by'],
|
||||||
@@ -259,7 +258,6 @@ class UserManagementTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check models exist where should be retained
|
// Check models exist where should be retained
|
||||||
$this->assertDatabaseHas('activities', ['id' => $activity->id, 'user_id' => null]);
|
|
||||||
$this->assertDatabaseHas('attachments', ['id' => $attachment->id, 'created_by' => null, 'updated_by' => null]);
|
$this->assertDatabaseHas('attachments', ['id' => $attachment->id, 'created_by' => null, 'updated_by' => null]);
|
||||||
$this->assertDatabaseHas('comments', ['id' => $comment->id, 'created_by' => null, 'updated_by' => null]);
|
$this->assertDatabaseHas('comments', ['id' => $comment->id, 'created_by' => null, 'updated_by' => null]);
|
||||||
$this->assertDatabaseHas('deletions', ['id' => $deletion->id, 'deleted_by' => null]);
|
$this->assertDatabaseHas('deletions', ['id' => $deletion->id, 'deleted_by' => null]);
|
||||||
@@ -276,6 +274,9 @@ class UserManagementTest extends TestCase
|
|||||||
$this->assertDatabaseMissing('social_accounts', ['id' => $socialAccount->id]);
|
$this->assertDatabaseMissing('social_accounts', ['id' => $socialAccount->id]);
|
||||||
$this->assertDatabaseMissing('user_invites', ['token' => 'abc123']);
|
$this->assertDatabaseMissing('user_invites', ['token' => 'abc123']);
|
||||||
$this->assertDatabaseMissing('watches', ['id' => $watch->id]);
|
$this->assertDatabaseMissing('watches', ['id' => $watch->id]);
|
||||||
|
|
||||||
|
// Ensure activity remains using the old ID (Special case for auditing changes)
|
||||||
|
$this->assertDatabaseHas('activities', ['id' => $activity->id, 'user_id' => $user->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_delete_removes_user_preferences()
|
public function test_delete_removes_user_preferences()
|
||||||
|
Reference in New Issue
Block a user