mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
Updated activities table format
Renamed some columns to be more generic and applicable. Removed now redundant book_id column. Allowed nullable entity morph columns for non-entity activity. Ran tests and made required changes.
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
use BookStack\Actions\Activity;
|
||||
use BookStack\Actions\ActivityService;
|
||||
use BookStack\Actions\ActivityType;
|
||||
use BookStack\Auth\UserRepo;
|
||||
use BookStack\Entities\Managers\TrashCan;
|
||||
use BookStack\Entities\Page;
|
||||
@ -10,6 +11,14 @@ use Carbon\Carbon;
|
||||
|
||||
class AuditLogTest extends TestCase
|
||||
{
|
||||
/** @var ActivityService */
|
||||
protected $activityService;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->activityService = app(ActivityService::class);
|
||||
}
|
||||
|
||||
public function test_only_accessible_with_right_permissions()
|
||||
{
|
||||
@ -34,7 +43,7 @@ class AuditLogTest extends TestCase
|
||||
$admin = $this->getAdmin();
|
||||
$this->actingAs($admin);
|
||||
$page = Page::query()->first();
|
||||
app(ActivityService::class)->add($page, 'page_create', $page->book->id);
|
||||
$this->activityService->addForEntity($page, ActivityType::PAGE_CREATE);
|
||||
$activity = Activity::query()->orderBy('id', 'desc')->first();
|
||||
|
||||
$resp = $this->get('settings/audit');
|
||||
@ -49,7 +58,7 @@ class AuditLogTest extends TestCase
|
||||
$this->actingAs( $this->getAdmin());
|
||||
$page = Page::query()->first();
|
||||
$pageName = $page->name;
|
||||
app(ActivityService::class)->add($page, 'page_create', $page->book->id);
|
||||
$this->activityService->addForEntity($page, ActivityType::PAGE_CREATE);
|
||||
|
||||
app(PageRepo::class)->destroy($page);
|
||||
app(TrashCan::class)->empty();
|
||||
@ -64,7 +73,7 @@ class AuditLogTest extends TestCase
|
||||
$viewer = $this->getViewer();
|
||||
$this->actingAs($viewer);
|
||||
$page = Page::query()->first();
|
||||
app(ActivityService::class)->add($page, 'page_create', $page->book->id);
|
||||
$this->activityService->addForEntity($page, ActivityType::PAGE_CREATE);
|
||||
|
||||
$this->actingAs($this->getAdmin());
|
||||
app(UserRepo::class)->destroy($viewer);
|
||||
@ -77,7 +86,7 @@ class AuditLogTest extends TestCase
|
||||
{
|
||||
$this->actingAs($this->getAdmin());
|
||||
$page = Page::query()->first();
|
||||
app(ActivityService::class)->add($page, 'page_create', $page->book->id);
|
||||
$this->activityService->addForEntity($page, ActivityType::PAGE_CREATE);
|
||||
|
||||
$resp = $this->get('settings/audit');
|
||||
$resp->assertSeeText($page->name);
|
||||
@ -90,7 +99,7 @@ class AuditLogTest extends TestCase
|
||||
{
|
||||
$this->actingAs($this->getAdmin());
|
||||
$page = Page::query()->first();
|
||||
app(ActivityService::class)->add($page, 'page_create', $page->book->id);
|
||||
$this->activityService->addForEntity($page, ActivityType::PAGE_CREATE);
|
||||
|
||||
$yesterday = (Carbon::now()->subDay()->format('Y-m-d'));
|
||||
$tomorrow = (Carbon::now()->addDay()->format('Y-m-d'));
|
||||
|
@ -41,7 +41,7 @@ class CommandsTest extends TestCase
|
||||
\Activity::addForEntity($page, ActivityType::PAGE_UPDATE);
|
||||
|
||||
$this->assertDatabaseHas('activities', [
|
||||
'key' => 'page_update',
|
||||
'type' => 'page_update',
|
||||
'entity_id' => $page->id,
|
||||
'user_id' => $this->getEditor()->id
|
||||
]);
|
||||
@ -51,7 +51,7 @@ class CommandsTest extends TestCase
|
||||
|
||||
|
||||
$this->assertDatabaseMissing('activities', [
|
||||
'key' => 'page_update'
|
||||
'type' => 'page_update'
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ class SortTest extends TestCase
|
||||
$movePageResp = $this->actingAs($this->getEditor())->put($page->getUrl('/move'), [
|
||||
'entity_selection' => 'book:' . $newBook->id
|
||||
]);
|
||||
$page = Page::find($page->id);
|
||||
$page->refresh();
|
||||
|
||||
$movePageResp->assertRedirect($page->getUrl());
|
||||
$this->assertTrue($page->book->id == $newBook->id, 'Page parent is now the new book');
|
||||
|
@ -136,7 +136,7 @@ class RecycleBinTest extends TestCase
|
||||
$deletion = $page->deletions()->firstOrFail();
|
||||
|
||||
$this->assertDatabaseHas('activities', [
|
||||
'key' => 'page_delete',
|
||||
'type' => 'page_delete',
|
||||
'entity_id' => $page->id,
|
||||
'entity_type' => $page->getMorphClass(),
|
||||
]);
|
||||
@ -144,16 +144,16 @@ class RecycleBinTest extends TestCase
|
||||
$this->asAdmin()->delete("/settings/recycle-bin/{$deletion->id}");
|
||||
|
||||
$this->assertDatabaseMissing('activities', [
|
||||
'key' => 'page_delete',
|
||||
'type' => 'page_delete',
|
||||
'entity_id' => $page->id,
|
||||
'entity_type' => $page->getMorphClass(),
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('activities', [
|
||||
'key' => 'page_delete',
|
||||
'entity_id' => 0,
|
||||
'entity_type' => '',
|
||||
'extra' => $page->name,
|
||||
'type' => 'page_delete',
|
||||
'entity_id' => null,
|
||||
'entity_type' => null,
|
||||
'detail' => $page->name,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -53,9 +53,9 @@ abstract class TestCase extends BaseTestCase
|
||||
* Assert that an activity entry exists of the given key.
|
||||
* Checks the activity belongs to the given entity if provided.
|
||||
*/
|
||||
protected function assertActivityExists(string $key, Entity $entity = null)
|
||||
protected function assertActivityExists(string $type, Entity $entity = null)
|
||||
{
|
||||
$detailsToCheck = ['key' => $key];
|
||||
$detailsToCheck = ['type' => $type];
|
||||
|
||||
if ($entity) {
|
||||
$detailsToCheck['entity_type'] = $entity->getMorphClass();
|
||||
|
Reference in New Issue
Block a user