mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-02 07:20:05 +00:00
parent
8f9923c7c1
commit
5f5b6ff0be
3 changed files with 36 additions and 0 deletions
|
@ -3,7 +3,9 @@
|
||||||
namespace BookStack\Actions;
|
namespace BookStack\Actions;
|
||||||
|
|
||||||
use BookStack\Entities\Models\Entity;
|
use BookStack\Entities\Models\Entity;
|
||||||
|
use BookStack\Facades\Theme;
|
||||||
use BookStack\Interfaces\Loggable;
|
use BookStack\Interfaces\Loggable;
|
||||||
|
use BookStack\Theming\ThemeEvents;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
@ -27,8 +29,10 @@ class ActivityLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
$activity->save();
|
$activity->save();
|
||||||
|
|
||||||
$this->setNotification($type);
|
$this->setNotification($type);
|
||||||
$this->dispatchWebhooks($type, $detail);
|
$this->dispatchWebhooks($type, $detail);
|
||||||
|
Theme::dispatch(ThemeEvents::ACTIVITY_LOGGED, $type, $detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,6 +15,19 @@ namespace BookStack\Theming;
|
||||||
*/
|
*/
|
||||||
class ThemeEvents
|
class ThemeEvents
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Activity logged event.
|
||||||
|
* Runs right after an activity is logged by bookstack.
|
||||||
|
* These are the activities that can be seen in the audit log area of BookStack.
|
||||||
|
* Activity types can be seen listed in the \BookStack\Actions\ActivityType class.
|
||||||
|
* The provided $detail can be a string or a loggable type of model. You should check
|
||||||
|
* the type before making use of this parameter.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string|\BookStack\Interfaces\Loggable $detail
|
||||||
|
*/
|
||||||
|
const ACTIVITY_LOGGED = 'activity_logged';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Application boot-up.
|
* Application boot-up.
|
||||||
* After main services are registered.
|
* After main services are registered.
|
||||||
|
|
|
@ -6,6 +6,7 @@ use BookStack\Actions\ActivityType;
|
||||||
use BookStack\Actions\DispatchWebhookJob;
|
use BookStack\Actions\DispatchWebhookJob;
|
||||||
use BookStack\Actions\Webhook;
|
use BookStack\Actions\Webhook;
|
||||||
use BookStack\Auth\User;
|
use BookStack\Auth\User;
|
||||||
|
use BookStack\Entities\Models\Book;
|
||||||
use BookStack\Entities\Models\Page;
|
use BookStack\Entities\Models\Page;
|
||||||
use BookStack\Entities\Tools\PageContent;
|
use BookStack\Entities\Tools\PageContent;
|
||||||
use BookStack\Facades\Theme;
|
use BookStack\Facades\Theme;
|
||||||
|
@ -196,6 +197,24 @@ class ThemeTest extends TestCase
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_event_activity_logged()
|
||||||
|
{
|
||||||
|
$book = Book::query()->first();
|
||||||
|
$args = [];
|
||||||
|
$callback = function (...$eventArgs) use (&$args) {
|
||||||
|
$args = $eventArgs;
|
||||||
|
};
|
||||||
|
|
||||||
|
Theme::listen(ThemeEvents::ACTIVITY_LOGGED, $callback);
|
||||||
|
$this->asEditor()->put($book->getUrl(), ['name' => 'My cool update book!']);
|
||||||
|
|
||||||
|
$this->assertCount(2, $args);
|
||||||
|
$this->assertEquals(ActivityType::BOOK_UPDATE, $args[0]);
|
||||||
|
$this->assertTrue($args[1] instanceof Book);
|
||||||
|
$this->assertEquals($book->id, $args[1]->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function test_add_social_driver()
|
public function test_add_social_driver()
|
||||||
{
|
{
|
||||||
Theme::addSocialDriver('catnet', [
|
Theme::addSocialDriver('catnet', [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue