Skip to content

Commit e4faf27

Browse files
committed
Entities: Reviewed TODO notes
1 parent cbd817d commit e4faf27

File tree

7 files changed

+42
-9
lines changed

7 files changed

+42
-9
lines changed

app/Access/Mfa/MfaSession.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class MfaSession
1111
*/
1212
public function isRequiredForUser(User $user): bool
1313
{
14-
// TODO - Test both these cases
1514
return $user->mfaValues()->exists() || $this->userRoleEnforcesMfa($user);
1615
}
1716

app/Entities/Models/Entity.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ public function matchesOrContains(self $entity): bool
214214
*/
215215
public function activity(): MorphMany
216216
{
217-
// TODO - Ensure this is scoped to entity type properly.
218-
// Add test if not.
219217
return $this->morphMany(Activity::class, 'loggable')
220218
->orderBy('created_at', 'desc');
221219
}

app/Entities/Queries/ChapterQueries.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public function usingSlugs(string $bookSlug, string $chapterSlug): Builder
6161

6262
public function visibleForList(): Builder
6363
{
64-
// TODO - Review this is working as expected
6564
return $this->start()
6665
->scopes('visible')
6766
->select(array_merge(static::$listAttributes, ['book_slug' => function ($builder) {

app/Entities/Queries/PageQueries.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ public function visibleTemplates(bool $includeContents = false): Builder
120120

121121
protected function mergeBookSlugForSelect(array $columns): array
122122
{
123-
// TODO - Review this is working as expected
124123
return array_merge($columns, ['book_slug' => function ($builder) {
125124
$builder->select('slug')
126125
->from('entities as books')

app/Entities/Tools/TrashCan.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ protected function destroyPage(Page $page): int
220220
// But does that present visibility/permission issues if they used to retain their old
221221
// unused ID?
222222
// If so, might be better to leave them as-is like before, but ensure the maintenance
223-
// cleanup command/action can find these "orged" images and delete them.
223+
// cleanup command/action can find these "orphaned" images and delete them.
224+
// But that would leave potential attachment to new pages on increment reset scenarios.
225+
// Need to review permission scenarios for null field values relative to storage options.
224226

225227
$page->forceDelete();
226228

@@ -401,11 +403,11 @@ protected function destroyCommonRelations(Entity $entity)
401403
$entity->referencesTo()->delete();
402404
$entity->referencesFrom()->delete();
403405

404-
// TODO - Update
405-
406406
if ($entity instanceof HasCoverInterface && $entity->coverInfo()->exists()) {
407407
$imageService = app()->make(ImageService::class);
408408
$imageService->destroy($entity->coverInfo()->getImage());
409409
}
410+
411+
$entity->relatedData()->delete();
410412
}
411413
}

tests/Auth/MfaConfigurationTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use BookStack\Activity\ActivityType;
77
use BookStack\Users\Models\Role;
88
use BookStack\Users\Models\User;
9+
use Illuminate\Support\Facades\Hash;
910
use PragmaRX\Google2FA\Google2FA;
1011
use Tests\TestCase;
1112

@@ -166,6 +167,36 @@ public function test_remove_mfa_method()
166167
$this->assertEquals(0, $admin->mfaValues()->count());
167168
}
168169

170+
public function test_mfa_required_if_set_on_role()
171+
{
172+
$user = $this->users->viewer();
173+
$user->password = Hash::make('password');
174+
$user->save();
175+
/** @var Role $role */
176+
$role = $user->roles()->first();
177+
$role->mfa_enforced = true;
178+
$role->save();
179+
180+
$resp = $this->post('/login', ['email' => $user->email, 'password' => 'password']);
181+
$this->assertFalse(auth()->check());
182+
$resp->assertRedirect('/mfa/verify');
183+
}
184+
185+
public function test_mfa_required_if_mfa_option_configured()
186+
{
187+
$user = $this->users->viewer();
188+
$user->password = Hash::make('password');
189+
$user->save();
190+
$user->mfaValues()->create([
191+
'method' => MfaValue::METHOD_TOTP,
192+
'value' => 'test',
193+
]);
194+
195+
$resp = $this->post('/login', ['email' => $user->email, 'password' => 'password']);
196+
$this->assertFalse(auth()->check());
197+
$resp->assertRedirect('/mfa/verify');
198+
}
199+
169200
public function test_totp_setup_url_shows_correct_user_when_setup_forced_upon_login()
170201
{
171202
$admin = $this->users->admin();

tests/Settings/RecycleBinTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ public function test_recycle_bin_empty()
8484

8585
$this->assertTrue(Deletion::query()->count() === 0);
8686
$this->assertDatabaseMissing('entities', ['id' => $book->id, 'type' => 'book']);
87-
$this->assertDatabaseMissing('entities', ['id' => $page->id, 'type' => 'page']);
87+
$this->assertDatabaseMissing('entity_container_data', ['entity_id' => $book->id, 'entity_type' => 'book']);
8888
$this->assertDatabaseMissing('entities', ['id' => $book->pages->first()->id, 'type' => 'page']);
89+
$this->assertDatabaseMissing('entity_page_data', ['page_id' => $book->pages->first()->id]);
8990
$this->assertDatabaseMissing('entities', ['id' => $book->chapters->first()->id, 'type' => 'chapter']);
91+
$this->assertDatabaseMissing('entity_container_data', ['entity_id' => $book->chapters->first()->id, 'entity_type' => 'chapter']);
9092

9193
$itemCount = 2 + $book->pages->count() + $book->chapters->count();
9294
$redirectReq = $this->get('/settings/recycle-bin');
@@ -125,8 +127,11 @@ public function test_permanent_delete()
125127
$this->assertTrue(Deletion::query()->count() === 0);
126128

127129
$this->assertDatabaseMissing('entities', ['id' => $book->id, 'type' => 'book']);
130+
$this->assertDatabaseMissing('entity_container_data', ['entity_id' => $book->id, 'entity_type' => 'book']);
128131
$this->assertDatabaseMissing('entities', ['id' => $book->pages->first()->id, 'type' => 'page']);
132+
$this->assertDatabaseMissing('entity_page_data', ['page_id' => $book->pages->first()->id]);
129133
$this->assertDatabaseMissing('entities', ['id' => $book->chapters->first()->id, 'type' => 'chapter']);
134+
$this->assertDatabaseMissing('entity_container_data', ['entity_id' => $book->chapters->first()->id, 'entity_type' => 'chapter']);
130135

131136
$itemCount = 1 + $book->pages->count() + $book->chapters->count();
132137
$redirectReq = $this->get('/settings/recycle-bin');

0 commit comments

Comments
 (0)