Added revision activity types to system and audit log

Closes #3628
This commit is contained in:
Dan Brown 2022-08-09 13:25:18 +01:00
parent 7fa934e7f2
commit 6e0a7344fa
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
6 changed files with 22 additions and 2 deletions

View File

@ -29,6 +29,9 @@ class ActivityType
const COMMENTED_ON = 'commented_on';
const PERMISSIONS_UPDATE = 'permissions_update';
const REVISION_RESTORE = 'revision_restore';
const REVISION_DELETE = 'revision_delete';
const SETTINGS_UPDATE = 'settings_update';
const MAINTENANCE_ACTION_RUN = 'maintenance_action_run';

View File

@ -3,6 +3,7 @@
namespace BookStack\Entities\Models;
use BookStack\Auth\User;
use BookStack\Interfaces\Loggable;
use BookStack\Model;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -27,7 +28,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
* @property Page $page
* @property-read ?User $createdBy
*/
class PageRevision extends Model
class PageRevision extends Model implements Loggable
{
protected $fillable = ['name', 'text', 'summary'];
protected $hidden = ['html', 'markdown', 'restricted', 'text'];
@ -83,4 +84,9 @@ class PageRevision extends Model
{
return $type === 'revision';
}
public function logDescriptor(): string
{
return "Revision #{$this->revision_number} (ID: {$this->id}) for page ID {$this->page_id}";
}
}

View File

@ -337,6 +337,7 @@ class PageRepo
$this->savePageRevision($page, $summary);
Activity::add(ActivityType::PAGE_RESTORE, $page);
Activity::add(ActivityType::REVISION_RESTORE, $revision);
return $page;
}

View File

@ -5,7 +5,7 @@ namespace BookStack\Facades;
use Illuminate\Support\Facades\Facade;
/**
* @see \BookStack\Actions\ActivityLogger
* @mixin \BookStack\Actions\ActivityLogger
*/
class Activity extends Facade
{

View File

@ -2,9 +2,11 @@
namespace BookStack\Http\Controllers;
use BookStack\Actions\ActivityType;
use BookStack\Entities\Repos\PageRepo;
use BookStack\Entities\Tools\PageContent;
use BookStack\Exceptions\NotFoundException;
use BookStack\Facades\Activity;
use Ssddanbrown\HtmlDiff\Diff;
class PageRevisionController extends Controller
@ -132,6 +134,7 @@ class PageRevisionController extends Controller
}
$revision->delete();
Activity::add(ActivityType::REVISION_DELETE, $revision);
$this->showSuccessNotification(trans('entities.revision_delete_success'));
return redirect($page->getUrl('/revisions'));

View File

@ -2,6 +2,7 @@
namespace Tests\Entity;
use BookStack\Actions\ActivityType;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Repos\PageRepo;
use Tests\TestCase;
@ -117,6 +118,9 @@ class PageRevisionTest extends TestCase
'type' => 'version',
'summary' => "Restored from #{$revToRestore->id}; My first update",
]);
$detail = "Revision #{$revToRestore->revision_number} (ID: {$revToRestore->id}) for page ID {$revToRestore->page_id}";
$this->assertActivityExists(ActivityType::REVISION_RESTORE, null, $detail);
}
public function test_page_revision_count_increments_on_update()
@ -164,6 +168,9 @@ class PageRevisionTest extends TestCase
$this->assertTrue($beforeRevisionCount === ($afterRevisionCount + 1));
$detail = "Revision #{$revision->revision_number} (ID: {$revision->id}) for page ID {$revision->page_id}";
$this->assertActivityExists(ActivityType::REVISION_DELETE, null, $detail);
// Try to delete the latest revision
$beforeRevisionCount = $page->revisions->count();
$resp = $this->asEditor()->delete($page->currentRevision->getUrl('/delete/'));