diff --git a/app/Actions/Activity.php b/app/Actions/Activity.php index 035a9cc75..42cc95613 100644 --- a/app/Actions/Activity.php +++ b/app/Actions/Activity.php @@ -5,16 +5,17 @@ namespace BookStack\Actions; use BookStack\Auth\User; use BookStack\Entities\Entity; use BookStack\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Support\Str; /** - * @property string $key + * @property string $type * @property User $user * @property Entity $entity - * @property string $extra + * @property string $detail * @property string $entity_type * @property int $entity_id * @property int $user_id - * @property int $book_id */ class Activity extends Model { @@ -32,20 +33,28 @@ class Activity extends Model /** * Get the user this activity relates to. - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ - public function user() + public function user(): BelongsTo { return $this->belongsTo(User::class); } /** - * Returns text from the language files, Looks up by using the - * activity key. + * Returns text from the language files, Looks up by using the activity key. */ - public function getText() + public function getText(): string { - return trans('activities.' . $this->key); + return trans('activities.' . $this->type); + } + + /** + * Check if this activity is intended to be for an entity. + */ + public function isForEntity(): bool + { + return Str::startsWith($this->type, [ + 'page_', 'chapter_', 'book_', 'bookshelf_' + ]); } /** @@ -53,6 +62,6 @@ class Activity extends Model */ public function isSimilarTo(Activity $activityB): bool { - return [$this->key, $this->entity_type, $this->entity_id] === [$activityB->key, $activityB->entity_type, $activityB->entity_id]; + return [$this->type, $this->entity_type, $this->entity_id] === [$activityB->type, $activityB->entity_type, $activityB->entity_id]; } } diff --git a/app/Actions/ActivityService.php b/app/Actions/ActivityService.php index 4e5b1f365..0b3b0f0bc 100644 --- a/app/Actions/ActivityService.php +++ b/app/Actions/ActivityService.php @@ -2,58 +2,59 @@ use BookStack\Auth\Permissions\PermissionService; use BookStack\Auth\User; +use BookStack\Entities\Chapter; use BookStack\Entities\Entity; +use BookStack\Entities\Page; +use BookStack\Interfaces\Loggable; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\Relation; -use Illuminate\Support\Collection; use Illuminate\Support\Facades\Log; class ActivityService { protected $activity; - protected $user; protected $permissionService; - /** - * ActivityService constructor. - */ public function __construct(Activity $activity, PermissionService $permissionService) { $this->activity = $activity; $this->permissionService = $permissionService; - $this->user = user(); } /** - * Add activity data to database. + * Add activity data to database for an entity. */ - public function add(Entity $entity, string $activityKey, ?int $bookId = null) + public function addForEntity(Entity $entity, string $type) { - $activity = $this->newActivityForUser($activityKey, $bookId); + $activity = $this->newActivityForUser($type); $entity->activity()->save($activity); - $this->setNotification($activityKey); + $this->setNotification($type); } /** - * Adds a activity history with a message, without binding to a entity. + * Add a generic activity event to the database. + * @param string|Loggable $detail */ - public function addMessage(string $activityKey, string $message, ?int $bookId = null) + public function add(string $type, $detail = '') { - $this->newActivityForUser($activityKey, $bookId)->forceFill([ - 'extra' => $message - ])->save(); + if ($detail instanceof Loggable) { + $detail = $detail->logDescriptor(); + } - $this->setNotification($activityKey); + $activity = $this->newActivityForUser($type); + $activity->detail = $detail; + $activity->save(); + $this->setNotification($type); } /** * Get a new activity instance for the current user. */ - protected function newActivityForUser(string $key, ?int $bookId = null): Activity + protected function newActivityForUser(string $type): Activity { return $this->activity->newInstance()->forceFill([ - 'key' => strtolower($key), - 'user_id' => $this->user->id, - 'book_id' => $bookId ?? 0, + 'type' => strtolower($type), + 'user_id' => user()->id, ]); } @@ -62,15 +63,13 @@ class ActivityService * and instead uses the 'extra' field with the entities name. * Used when an entity is deleted. */ - public function removeEntity(Entity $entity): Collection + public function removeEntity(Entity $entity) { - $activities = $entity->activity()->get(); $entity->activity()->update([ - 'extra' => $entity->name, - 'entity_id' => 0, - 'entity_type' => '', + 'detail' => $entity->name, + 'entity_id' => null, + 'entity_type' => null, ]); - return $activities; } /** @@ -95,16 +94,27 @@ class ActivityService */ public function entityActivity(Entity $entity, int $count = 20, int $page = 1): array { + /** @var [string => int[]] $queryIds */ + $queryIds = [$entity->getMorphClass() => [$entity->id]]; + if ($entity->isA('book')) { - $query = $this->activity->newQuery()->where('book_id', '=', $entity->id); - } else { - $query = $this->activity->newQuery()->where('entity_type', '=', $entity->getMorphClass()) - ->where('entity_id', '=', $entity->id); + $queryIds[(new Chapter)->getMorphClass()] = $entity->chapters()->visible()->pluck('id'); + } + if ($entity->isA('book') || $entity->isA('chapter')) { + $queryIds[(new Page)->getMorphClass()] = $entity->pages()->visible()->pluck('id'); } - $activity = $this->permissionService - ->filterRestrictedEntityRelations($query, 'activities', 'entity_id', 'entity_type') - ->orderBy('created_at', 'desc') + $query = $this->activity->newQuery(); + $query->where(function (Builder $query) use ($queryIds) { + foreach ($queryIds as $morphClass => $idArr) { + $query->orWhere(function (Builder $innerQuery) use ($morphClass, $idArr) { + $innerQuery->where('entity_type', '=', $morphClass) + ->whereIn('entity_id', $idArr); + }); + } + }); + + $activity = $query->orderBy('created_at', 'desc') ->with(['entity' => function (Relation $query) { $query->withTrashed(); }, 'user.avatar']) @@ -155,9 +165,9 @@ class ActivityService /** * Flashes a notification message to the session if an appropriate message is available. */ - protected function setNotification(string $activityKey) + protected function setNotification(string $type) { - $notificationTextKey = 'activities.' . $activityKey . '_notification'; + $notificationTextKey = 'activities.' . $type . '_notification'; if (trans()->has($notificationTextKey)) { $message = trans($notificationTextKey); session()->flash('success', $message); diff --git a/app/Actions/ActivityType.php b/app/Actions/ActivityType.php new file mode 100644 index 000000000..216f61249 --- /dev/null +++ b/app/Actions/ActivityType.php @@ -0,0 +1,51 @@ +parent_id = $parent_id; $entity->comments()->save($comment); + ActivityService::addForEntity($entity, ActivityType::COMMENTED_ON); return $comment; } diff --git a/app/Api/ApiToken.php b/app/Api/ApiToken.php index 523c3b8b8..91c407fd8 100644 --- a/app/Api/ApiToken.php +++ b/app/Api/ApiToken.php @@ -1,11 +1,22 @@ addYears(100)->format('Y-m-d'); } + + /** + * @inheritdoc + */ + public function logDescriptor(): string + { + return "({$this->id}) {$this->name}; User: {$this->user->logDescriptor()}"; + } } diff --git a/app/Auth/Access/RegistrationService.php b/app/Auth/Access/RegistrationService.php index ecc92c117..2aff6c37d 100644 --- a/app/Auth/Access/RegistrationService.php +++ b/app/Auth/Access/RegistrationService.php @@ -1,9 +1,11 @@ socialAccounts()->save($socialAccount); } + Activity::add(ActivityType::AUTH_REGISTER, $socialAccount ?? $newUser); + // Start email confirmation flow if required if ($this->emailConfirmationService->confirmationRequired() && !$emailConfirmed) { $newUser->save(); diff --git a/app/Auth/Access/Saml2Service.php b/app/Auth/Access/Saml2Service.php index 89ddd0011..0316ff976 100644 --- a/app/Auth/Access/Saml2Service.php +++ b/app/Auth/Access/Saml2Service.php @@ -1,9 +1,11 @@ login($user); + Activity::add(ActivityType::AUTH_LOGIN, "saml2; {$user->logDescriptor()}"); return $user; } } diff --git a/app/Auth/Access/SocialAuthService.php b/app/Auth/Access/SocialAuthService.php index 657aae3f3..b0383a938 100644 --- a/app/Auth/Access/SocialAuthService.php +++ b/app/Auth/Access/SocialAuthService.php @@ -1,10 +1,12 @@ login($socialAccount->user); + Activity::add(ActivityType::AUTH_LOGIN, $socialAccount); return redirect()->intended('/'); } diff --git a/app/Auth/Permissions/PermissionsRepo.php b/app/Auth/Permissions/PermissionsRepo.php index ce61093cc..f54612a43 100644 --- a/app/Auth/Permissions/PermissionsRepo.php +++ b/app/Auth/Permissions/PermissionsRepo.php @@ -1,10 +1,11 @@ assignRolePermissions($role, $permissions); $this->permissionService->buildJointPermissionForRole($role); + Activity::add(ActivityType::ROLE_CREATE, $role); return $role; } @@ -88,12 +90,13 @@ class PermissionsRepo $role->fill($roleData); $role->save(); $this->permissionService->buildJointPermissionForRole($role); + Activity::add(ActivityType::ROLE_UPDATE, $role); } /** * Assign an list of permission names to an role. */ - public function assignRolePermissions(Role $role, array $permissionNameArray = []) + protected function assignRolePermissions(Role $role, array $permissionNameArray = []) { $permissions = []; $permissionNameArray = array_values($permissionNameArray); @@ -137,6 +140,7 @@ class PermissionsRepo } $this->permissionService->deleteJointPermissionsForRole($role); + Activity::add(ActivityType::ROLE_DELETE, $role); $role->delete(); } } diff --git a/app/Auth/Role.php b/app/Auth/Role.php index 13ec6df16..255158afb 100644 --- a/app/Auth/Role.php +++ b/app/Auth/Role.php @@ -2,6 +2,7 @@ use BookStack\Auth\Permissions\JointPermission; use BookStack\Auth\Permissions\RolePermission; +use BookStack\Interfaces\Loggable; use BookStack\Model; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -14,7 +15,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; * @property string $external_auth_id * @property string $system_name */ -class Role extends Model +class Role extends Model implements Loggable { protected $fillable = ['display_name', 'description', 'external_auth_id']; @@ -104,4 +105,12 @@ class Role extends Model { return static::query()->where('system_name', '!=', 'admin')->get(); } + + /** + * @inheritdoc + */ + public function logDescriptor(): string + { + return "({$this->id}) {$this->display_name}"; + } } diff --git a/app/Auth/SocialAccount.php b/app/Auth/SocialAccount.php index 804dbe629..1c83980cb 100644 --- a/app/Auth/SocialAccount.php +++ b/app/Auth/SocialAccount.php @@ -1,8 +1,15 @@ belongsTo(User::class); } + + /** + * @inheritDoc + */ + public function logDescriptor(): string + { + return "{$this->driver}; {$this->user->logDescriptor()}"; + } } diff --git a/app/Auth/User.php b/app/Auth/User.php index f65ef5316..5feb269e2 100644 --- a/app/Auth/User.php +++ b/app/Auth/User.php @@ -1,6 +1,8 @@ hasMany(ApiToken::class); } + /** + * Get the latest activity instance for this user. + */ + public function latestActivity(): HasOne + { + return $this->hasOne(Activity::class)->latest(); + } + /** * Get the url for editing this user. */ @@ -274,4 +285,12 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon { $this->notify(new ResetPassword($token)); } + + /** + * @inheritdoc + */ + public function logDescriptor(): string + { + return "({$this->id}) {$this->name}"; + } } diff --git a/app/Auth/UserRepo.php b/app/Auth/UserRepo.php index fdb8c0923..5ae2ed2a2 100644 --- a/app/Auth/UserRepo.php +++ b/app/Auth/UserRepo.php @@ -10,6 +10,7 @@ use BookStack\Exceptions\UserUpdateException; use BookStack\Uploads\Image; use Exception; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Pagination\LengthAwarePaginator; use Images; use Log; @@ -56,13 +57,19 @@ class UserRepo /** * Get all the users with their permissions in a paginated format. - * @param int $count - * @param $sortData - * @return Builder|static */ - public function getAllUsersPaginatedAndSorted($count, $sortData) + public function getAllUsersPaginatedAndSorted(int $count, array $sortData): LengthAwarePaginator { - $query = $this->user->with('roles', 'avatar')->orderBy($sortData['sort'], $sortData['order']); + $sort = $sortData['sort']; + if ($sort === 'latest_activity') { + $sort = \BookStack\Actions\Activity::query()->select('created_at') + ->whereColumn('activities.user_id', 'users.id') + ->latest() + ->take(1); + } + + $query = $this->user->with(['roles', 'avatar', 'latestActivity']) + ->orderBy($sort, $sortData['order']); if ($sortData['search']) { $term = '%' . $sortData['search'] . '%'; diff --git a/app/Entities/BookChild.php b/app/Entities/BookChild.php index 6eac4375d..042b56e28 100644 --- a/app/Entities/BookChild.php +++ b/app/Entities/BookChild.php @@ -45,9 +45,6 @@ class BookChild extends Entity $this->save(); $this->refresh(); - // Update related activity - $this->activity()->update(['book_id' => $newBookId]); - // Update all child pages if a chapter if ($this instanceof Chapter) { foreach ($this->pages as $page) { diff --git a/app/Entities/Deletion.php b/app/Entities/Deletion.php index 576862caa..dab44d4ad 100644 --- a/app/Entities/Deletion.php +++ b/app/Entities/Deletion.php @@ -1,11 +1,12 @@ deletable()->first(); + return "Deletion ({$this->id}) for {$deletable->getType()} ({$deletable->id}) {$deletable->name}"; + } } diff --git a/app/Entities/Repos/BaseRepo.php b/app/Entities/Repos/BaseRepo.php index 7c25e4981..a9d599eb2 100644 --- a/app/Entities/Repos/BaseRepo.php +++ b/app/Entities/Repos/BaseRepo.php @@ -2,11 +2,12 @@ namespace BookStack\Entities\Repos; +use BookStack\Actions\ActivityType; use BookStack\Actions\TagRepo; -use BookStack\Entities\Book; use BookStack\Entities\Entity; use BookStack\Entities\HasCoverImage; use BookStack\Exceptions\ImageUploadException; +use BookStack\Facades\Activity; use BookStack\Uploads\ImageRepo; use Illuminate\Http\UploadedFile; use Illuminate\Support\Collection; @@ -18,10 +19,6 @@ class BaseRepo protected $imageRepo; - /** - * BaseRepo constructor. - * @param $tagRepo - */ public function __construct(TagRepo $tagRepo, ImageRepo $imageRepo) { $this->tagRepo = $tagRepo; @@ -115,5 +112,6 @@ class BaseRepo $entity->save(); $entity->rebuildPermissions(); + Activity::addForEntity($entity, ActivityType::PERMISSIONS_UPDATE); } } diff --git a/app/Entities/Repos/BookRepo.php b/app/Entities/Repos/BookRepo.php index b0ea7cb87..008a9080c 100644 --- a/app/Entities/Repos/BookRepo.php +++ b/app/Entities/Repos/BookRepo.php @@ -1,11 +1,13 @@ baseRepo->create($book, $input); + Activity::addForEntity($book, ActivityType::BOOK_CREATE); return $book; } @@ -100,6 +103,7 @@ class BookRepo public function update(Book $book, array $input): Book { $this->baseRepo->update($book, $input); + Activity::addForEntity($book, ActivityType::BOOK_UPDATE); return $book; } @@ -129,6 +133,8 @@ class BookRepo { $trashCan = new TrashCan(); $trashCan->softDestroyBook($book); + Activity::addForEntity($book, ActivityType::BOOK_DELETE); + $trashCan->autoClearOld(); } } diff --git a/app/Entities/Repos/BookshelfRepo.php b/app/Entities/Repos/BookshelfRepo.php index 49fb75f4c..7cd333ff3 100644 --- a/app/Entities/Repos/BookshelfRepo.php +++ b/app/Entities/Repos/BookshelfRepo.php @@ -1,10 +1,12 @@ baseRepo->create($shelf, $input); $this->updateBooks($shelf, $bookIds); + Activity::addForEntity($shelf, ActivityType::BOOKSHELF_CREATE); return $shelf; } /** - * Create a new shelf in the system. + * Update an existing shelf in the system using the given input. */ public function update(Bookshelf $shelf, array $input, ?array $bookIds): Bookshelf { @@ -101,6 +104,7 @@ class BookshelfRepo $this->updateBooks($shelf, $bookIds); } + Activity::addForEntity($shelf, ActivityType::BOOKSHELF_UPDATE); return $shelf; } @@ -175,6 +179,7 @@ class BookshelfRepo { $trashCan = new TrashCan(); $trashCan->softDestroyShelf($shelf); + Activity::addForEntity($shelf, ActivityType::BOOKSHELF_DELETE); $trashCan->autoClearOld(); } } diff --git a/app/Entities/Repos/ChapterRepo.php b/app/Entities/Repos/ChapterRepo.php index 60599eac8..312cb69e5 100644 --- a/app/Entities/Repos/ChapterRepo.php +++ b/app/Entities/Repos/ChapterRepo.php @@ -1,11 +1,13 @@ book_id = $parentBook->id; $chapter->priority = (new BookContents($parentBook))->getLastPriority() + 1; $this->baseRepo->create($chapter, $input); + Activity::addForEntity($chapter, ActivityType::CHAPTER_CREATE); return $chapter; } @@ -55,6 +58,7 @@ class ChapterRepo public function update(Chapter $chapter, array $input): Chapter { $this->baseRepo->update($chapter, $input); + Activity::addForEntity($chapter, ActivityType::CHAPTER_UPDATE); return $chapter; } @@ -74,6 +78,7 @@ class ChapterRepo { $trashCan = new TrashCan(); $trashCan->softDestroyChapter($chapter); + Activity::addForEntity($chapter, ActivityType::CHAPTER_DELETE); $trashCan->autoClearOld(); } @@ -93,6 +98,7 @@ class ChapterRepo throw new MoveOperationException('Chapters can only be moved into books'); } + /** @var Book $parent */ $parent = Book::visible()->where('id', '=', $entityId)->first(); if ($parent === null) { throw new MoveOperationException('Book to move chapter into not found'); @@ -100,6 +106,8 @@ class ChapterRepo $chapter->changeBook($parent->id); $chapter->rebuildPermissions(); + Activity::addForEntity($chapter, ActivityType::CHAPTER_MOVE); + return $parent; } } diff --git a/app/Entities/Repos/PageRepo.php b/app/Entities/Repos/PageRepo.php index 80c8afe98..6b593d85e 100644 --- a/app/Entities/Repos/PageRepo.php +++ b/app/Entities/Repos/PageRepo.php @@ -1,5 +1,6 @@ savePageRevision($draft, trans('entities.pages_initial_revision')); $draft->indexForSearch(); - return $draft->refresh(); + $draft->refresh(); + + Activity::addForEntity($draft, ActivityType::PAGE_CREATE); + return $draft; } /** @@ -203,6 +208,7 @@ class PageRepo $this->savePageRevision($page, $summary); } + Activity::addForEntity($page, ActivityType::PAGE_UPDATE); return $page; } @@ -266,6 +272,7 @@ class PageRepo { $trashCan = new TrashCan(); $trashCan->softDestroyPage($page); + Activity::addForEntity($page, ActivityType::PAGE_DELETE); $trashCan->autoClearOld(); } @@ -286,6 +293,7 @@ class PageRepo $page->save(); $page->indexForSearch(); + Activity::addForEntity($page, ActivityType::PAGE_RESTORE); return $page; } @@ -296,7 +304,7 @@ class PageRepo * @throws MoveOperationException * @throws PermissionsException */ - public function move(Page $page, string $parentIdentifier): Book + public function move(Page $page, string $parentIdentifier): Entity { $parent = $this->findParentByIdentifier($parentIdentifier); if ($parent === null) { @@ -311,7 +319,8 @@ class PageRepo $page->changeBook($parent instanceof Book ? $parent->id : $parent->book->id); $page->rebuildPermissions(); - return ($parent instanceof Book ? $parent : $parent->book); + Activity::addForEntity($page, ActivityType::PAGE_MOVE); + return $parent; } /** diff --git a/app/Http/Controllers/Api/BookApiController.php b/app/Http/Controllers/Api/BookApiController.php index 8333eba3a..8ec9fdc06 100644 --- a/app/Http/Controllers/Api/BookApiController.php +++ b/app/Http/Controllers/Api/BookApiController.php @@ -1,5 +1,6 @@ validate($request, $this->rules['create']); $book = $this->bookRepo->create($requestData); - Activity::add($book, 'book_create', $book->id); - return response()->json($book); } @@ -80,7 +79,6 @@ class BookApiController extends ApiController $requestData = $this->validate($request, $this->rules['update']); $book = $this->bookRepo->update($book, $requestData); - Activity::add($book, 'book_update', $book->id); return response()->json($book); } @@ -96,8 +94,6 @@ class BookApiController extends ApiController $this->checkOwnablePermission('book-delete', $book); $this->bookRepo->destroy($book); - Activity::addMessage('book_delete', $book->name); - return response('', 204); } } \ No newline at end of file diff --git a/app/Http/Controllers/Api/BookshelfApiController.php b/app/Http/Controllers/Api/BookshelfApiController.php index 14b5e053b..6792f9f45 100644 --- a/app/Http/Controllers/Api/BookshelfApiController.php +++ b/app/Http/Controllers/Api/BookshelfApiController.php @@ -1,6 +1,5 @@ get('books', []); $shelf = $this->bookshelfRepo->create($requestData, $bookIds); - Activity::add($shelf, 'bookshelf_create', $shelf->id); return response()->json($shelf); } @@ -94,12 +92,9 @@ class BookshelfApiController extends ApiController $this->checkOwnablePermission('bookshelf-update', $shelf); $requestData = $this->validate($request, $this->rules['update']); - $bookIds = $request->get('books', null); $shelf = $this->bookshelfRepo->update($shelf, $requestData, $bookIds); - Activity::add($shelf, 'bookshelf_update', $shelf->id); - return response()->json($shelf); } @@ -115,8 +110,6 @@ class BookshelfApiController extends ApiController $this->checkOwnablePermission('bookshelf-delete', $shelf); $this->bookshelfRepo->destroy($shelf); - Activity::addMessage('bookshelf_delete', $shelf->name); - return response('', 204); } } \ No newline at end of file diff --git a/app/Http/Controllers/Api/ChapterApiController.php b/app/Http/Controllers/Api/ChapterApiController.php index 50aa8834e..60e0f0131 100644 --- a/app/Http/Controllers/Api/ChapterApiController.php +++ b/app/Http/Controllers/Api/ChapterApiController.php @@ -1,5 +1,6 @@ checkOwnablePermission('chapter-create', $book); $chapter = $this->chapterRepo->create($request->all(), $book); - Activity::add($chapter, 'chapter_create', $book->id); - return response()->json($chapter->load(['tags'])); } @@ -83,8 +82,6 @@ class ChapterApiController extends ApiController $this->checkOwnablePermission('chapter-update', $chapter); $updatedChapter = $this->chapterRepo->update($chapter, $request->all()); - Activity::add($chapter, 'chapter_update', $chapter->book->id); - return response()->json($updatedChapter->load(['tags'])); } @@ -97,8 +94,6 @@ class ChapterApiController extends ApiController $this->checkOwnablePermission('chapter-delete', $chapter); $this->chapterRepo->destroy($chapter); - Activity::addMessage('chapter_delete', $chapter->name, $chapter->book->id); - return response('', 204); } } diff --git a/app/Http/Controllers/AuditLogController.php b/app/Http/Controllers/AuditLogController.php index fad4e8d38..eb6eecc94 100644 --- a/app/Http/Controllers/AuditLogController.php +++ b/app/Http/Controllers/AuditLogController.php @@ -32,7 +32,7 @@ class AuditLogController extends Controller ->orderBy($listDetails['sort'], $listDetails['order']); if ($listDetails['event']) { - $query->where('key', '=', $listDetails['event']); + $query->where('type', '=', $listDetails['event']); } if ($listDetails['date_from']) { @@ -45,12 +45,12 @@ class AuditLogController extends Controller $activities = $query->paginate(100); $activities->appends($listDetails); - $keys = DB::table('activities')->select('key')->distinct()->pluck('key'); + $types = DB::table('activities')->select('type')->distinct()->pluck('type'); $this->setPageTitle(trans('settings.audit')); return view('settings.audit', [ 'activities' => $activities, 'listDetails' => $listDetails, - 'activityKeys' => $keys, + 'activityTypes' => $types, ]); } } diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index fadac641e..31e6d848b 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -2,6 +2,7 @@ namespace BookStack\Http\Controllers\Auth; +use BookStack\Actions\ActivityType; use BookStack\Http\Controllers\Controller; use Illuminate\Foundation\Auth\SendsPasswordResetEmails; use Illuminate\Http\Request; @@ -52,6 +53,10 @@ class ForgotPasswordController extends Controller $request->only('email') ); + if ($response === Password::RESET_LINK_SENT) { + $this->logActivity(ActivityType::AUTH_PASSWORD_RESET, $request->get('email')); + } + if ($response === Password::RESET_LINK_SENT || $response === Password::INVALID_USER) { $message = trans('auth.reset_password_sent', ['email' => $request->get('email')]); $this->showSuccessNotification($message); diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 8084ce1a5..3890da4b0 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -3,10 +3,10 @@ namespace BookStack\Http\Controllers\Auth; use Activity; +use BookStack\Actions\ActivityType; use BookStack\Auth\Access\SocialAuthService; use BookStack\Exceptions\LoginAttemptEmailNeededException; use BookStack\Exceptions\LoginAttemptException; -use BookStack\Exceptions\UserRegistrationException; use BookStack\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Http\Request; @@ -151,6 +151,7 @@ class LoginController extends Controller } } + $this->logActivity(ActivityType::AUTH_LOGIN, $user); return redirect()->intended($this->redirectPath()); } diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index efdf00159..96f05db26 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -2,6 +2,7 @@ namespace BookStack\Http\Controllers\Auth; +use BookStack\Actions\ActivityType; use BookStack\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ResetsPasswords; use Illuminate\Http\Request; @@ -47,6 +48,7 @@ class ResetPasswordController extends Controller { $message = trans('auth.reset_password_success'); $this->showSuccessNotification($message); + $this->logActivity(ActivityType::AUTH_PASSWORD_RESET_UPDATE, user()); return redirect($this->redirectPath()) ->with('status', trans($response)); } diff --git a/app/Http/Controllers/BookController.php b/app/Http/Controllers/BookController.php index 25dc65194..74f9586aa 100644 --- a/app/Http/Controllers/BookController.php +++ b/app/Http/Controllers/BookController.php @@ -1,12 +1,12 @@ bookRepo = $bookRepo; @@ -97,11 +94,10 @@ class BookController extends Controller $book = $this->bookRepo->create($request->all()); $this->bookRepo->updateCoverImage($book, $request->file('image', null)); - Activity::add($book, 'book_create', $book->id); if ($bookshelf) { $bookshelf->appendBook($book); - Activity::add($bookshelf, 'bookshelf_update'); + Activity::addForEntity($bookshelf, ActivityType::BOOKSHELF_UPDATE); } return redirect($book->getUrl()); @@ -162,8 +158,6 @@ class BookController extends Controller $resetCover = $request->has('image_reset'); $this->bookRepo->updateCoverImage($book, $request->file('image', null), $resetCover); - Activity::add($book, 'book_update', $book->id); - return redirect($book->getUrl()); } @@ -187,7 +181,6 @@ class BookController extends Controller $book = $this->bookRepo->getBySlug($bookSlug); $this->checkOwnablePermission('book-delete', $book); - Activity::add($book, 'book_delete', $book->id); $this->bookRepo->destroy($book); return redirect('/books'); diff --git a/app/Http/Controllers/BookSortController.php b/app/Http/Controllers/BookSortController.php index f5fb6f255..9375b618a 100644 --- a/app/Http/Controllers/BookSortController.php +++ b/app/Http/Controllers/BookSortController.php @@ -2,6 +2,7 @@ namespace BookStack\Http\Controllers; +use BookStack\Actions\ActivityType; use BookStack\Entities\Book; use BookStack\Entities\Managers\BookContents; use BookStack\Entities\Repos\BookRepo; @@ -14,10 +15,6 @@ class BookSortController extends Controller protected $bookRepo; - /** - * BookSortController constructor. - * @param $bookRepo - */ public function __construct(BookRepo $bookRepo) { $this->bookRepo = $bookRepo; @@ -74,7 +71,7 @@ class BookSortController extends Controller // Rebuild permissions and add activity for involved books. $booksInvolved->each(function (Book $book) { - Activity::add($book, 'book_sort', $book->id); + Activity::addForEntity($book, ActivityType::BOOK_SORT); }); return redirect($book->getUrl()); diff --git a/app/Http/Controllers/BookshelfController.php b/app/Http/Controllers/BookshelfController.php index efe280235..8d2eec348 100644 --- a/app/Http/Controllers/BookshelfController.php +++ b/app/Http/Controllers/BookshelfController.php @@ -92,7 +92,6 @@ class BookshelfController extends Controller $shelf = $this->bookshelfRepo->create($request->all(), $bookIds); $this->bookshelfRepo->updateCoverImage($shelf, $request->file('image', null)); - Activity::add($shelf, 'bookshelf_create'); return redirect($shelf->getUrl()); } @@ -156,7 +155,6 @@ class BookshelfController extends Controller $shelf = $this->bookshelfRepo->update($shelf, $request->all(), $bookIds); $resetCover = $request->has('image_reset'); $this->bookshelfRepo->updateCoverImage($shelf, $request->file('image', null), $resetCover); - Activity::add($shelf, 'bookshelf_update'); return redirect($shelf->getUrl()); } @@ -182,7 +180,6 @@ class BookshelfController extends Controller $shelf = $this->bookshelfRepo->getBySlug($slug); $this->checkOwnablePermission('bookshelf-delete', $shelf); - Activity::add($shelf, 'bookshelf_delete'); $this->bookshelfRepo->destroy($shelf); return redirect('/shelves'); diff --git a/app/Http/Controllers/ChapterController.php b/app/Http/Controllers/ChapterController.php index 5d8631154..8eba43e21 100644 --- a/app/Http/Controllers/ChapterController.php +++ b/app/Http/Controllers/ChapterController.php @@ -1,6 +1,5 @@ checkOwnablePermission('chapter-create', $book); $chapter = $this->chapterRepo->create($request->all(), $book); - Activity::add($chapter, 'chapter_create', $book->id); return redirect($chapter->getUrl()); } @@ -100,7 +98,6 @@ class ChapterController extends Controller $this->checkOwnablePermission('chapter-update', $chapter); $this->chapterRepo->update($chapter, $request->all()); - Activity::add($chapter, 'chapter_update', $chapter->book->id); return redirect($chapter->getUrl()); } @@ -128,7 +125,6 @@ class ChapterController extends Controller $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug); $this->checkOwnablePermission('chapter-delete', $chapter); - Activity::add($chapter, 'chapter_delete', $chapter->book->id); $this->chapterRepo->destroy($chapter); return redirect($chapter->book->getUrl()); @@ -173,8 +169,6 @@ class ChapterController extends Controller return redirect()->back(); } - Activity::add($chapter, 'chapter_move', $newBook->id); - $this->showSuccessNotification(trans('entities.chapter_move_success', ['bookName' => $newBook->name])); return redirect($chapter->getUrl()); } diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php index 4eb56a4b0..2dc1a4de4 100644 --- a/app/Http/Controllers/CommentController.php +++ b/app/Http/Controllers/CommentController.php @@ -1,6 +1,7 @@ checkPermission('comment-create-all'); $comment = $this->commentRepo->create($page, $request->get('text'), $request->get('parent_id')); - Activity::add($page, 'commented_on', $page->book->id); return view('comments.comment', ['comment' => $comment]); } diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 6a1dfcb01..3ac139249 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -2,21 +2,20 @@ namespace BookStack\Http\Controllers; +use BookStack\Facades\Activity; +use BookStack\Interfaces\Loggable; use BookStack\Ownable; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Http\Exceptions\HttpResponseException; -use Illuminate\Http\Request; +use Illuminate\Http\JsonResponse; +use Illuminate\Http\Response; use Illuminate\Routing\Controller as BaseController; -use Illuminate\Validation\ValidationException; abstract class Controller extends BaseController { use DispatchesJobs, ValidatesRequests; - /** - * Controller constructor. - */ public function __construct() { // @@ -43,9 +42,8 @@ abstract class Controller extends BaseController /** * Adds the page title into the view. - * @param $title */ - public function setPageTitle($title) + public function setPageTitle(string $title) { view()->share('pageTitle', $title); } @@ -67,79 +65,59 @@ abstract class Controller extends BaseController } /** - * Checks for a permission. - * @param string $permissionName - * @return bool|\Illuminate\Http\RedirectResponse + * Checks that the current user has the given permission otherwise throw an exception. */ - protected function checkPermission($permissionName) + protected function checkPermission(string $permission): void { - if (!user() || !user()->can($permissionName)) { + if (!user() || !user()->can($permission)) { $this->showPermissionError(); } - return true; } /** - * Check the current user's permissions against an ownable item. - * @param $permission - * @param Ownable $ownable - * @return bool + * Check the current user's permissions against an ownable item otherwise throw an exception. */ - protected function checkOwnablePermission($permission, Ownable $ownable) + protected function checkOwnablePermission(string $permission, Ownable $ownable): void { - if (userCan($permission, $ownable)) { - return true; + if (!userCan($permission, $ownable)) { + $this->showPermissionError(); } - return $this->showPermissionError(); } /** - * Check if a user has a permission or bypass if the callback is true. - * @param $permissionName - * @param $callback - * @return bool + * Check if a user has a permission or bypass the permission + * check if the given callback resolves true. */ - protected function checkPermissionOr($permissionName, $callback) + protected function checkPermissionOr(string $permission, callable $callback): void { - $callbackResult = $callback(); - if ($callbackResult === false) { - $this->checkPermission($permissionName); + if ($callback() !== true) { + $this->checkPermission($permission); } - return true; } /** * Check if the current user has a permission or bypass if the provided user * id matches the current user. - * @param string $permissionName - * @param int $userId - * @return bool */ - protected function checkPermissionOrCurrentUser(string $permissionName, int $userId) + protected function checkPermissionOrCurrentUser(string $permission, int $userId): void { - return $this->checkPermissionOr($permissionName, function () use ($userId) { + $this->checkPermissionOr($permission, function () use ($userId) { return $userId === user()->id; }); } /** * Send back a json error message. - * @param string $messageText - * @param int $statusCode - * @return mixed */ - protected function jsonError($messageText = "", $statusCode = 500) + protected function jsonError(string $messageText = "", int $statusCode = 500): JsonResponse { return response()->json(['message' => $messageText, 'status' => 'error'], $statusCode); } /** * Create a response that forces a download in the browser. - * @param string $content - * @param string $fileName - * @return \Illuminate\Http\Response */ - protected function downloadResponse(string $content, string $fileName) + protected function downloadResponse(string $content, string $fileName): Response { return response()->make($content, 200, [ 'Content-Type' => 'application/octet-stream', @@ -149,31 +127,37 @@ abstract class Controller extends BaseController /** * Show a positive, successful notification to the user on next view load. - * @param string $message */ - protected function showSuccessNotification(string $message) + protected function showSuccessNotification(string $message): void { session()->flash('success', $message); } /** * Show a warning notification to the user on next view load. - * @param string $message */ - protected function showWarningNotification(string $message) + protected function showWarningNotification(string $message): void { session()->flash('warning', $message); } /** * Show an error notification to the user on next view load. - * @param string $message */ - protected function showErrorNotification(string $message) + protected function showErrorNotification(string $message): void { session()->flash('error', $message); } + /** + * Log an activity in the system. + * @param string|Loggable + */ + protected function logActivity(string $type, $detail = ''): void + { + Activity::add($type, $detail); + } + /** * Get the validation rules for image files. */ diff --git a/app/Http/Controllers/MaintenanceController.php b/app/Http/Controllers/MaintenanceController.php index 0d6265f90..a638b69cd 100644 --- a/app/Http/Controllers/MaintenanceController.php +++ b/app/Http/Controllers/MaintenanceController.php @@ -2,6 +2,7 @@ namespace BookStack\Http\Controllers; +use BookStack\Actions\ActivityType; use BookStack\Entities\Managers\TrashCan; use BookStack\Notifications\TestEmail; use BookStack\Uploads\ImageService; @@ -35,6 +36,7 @@ class MaintenanceController extends Controller public function cleanupImages(Request $request, ImageService $imageService) { $this->checkPermission('settings-manage'); + $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'cleanup-images'); $checkRevisions = !($request->get('ignore_revisions', 'false') === 'true'); $dryRun = !($request->has('confirm')); @@ -61,6 +63,7 @@ class MaintenanceController extends Controller public function sendTestEmail() { $this->checkPermission('settings-manage'); + $this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'send-test-email'); try { user()->notify(new TestEmail()); diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index 6396da23e..862ba3d7f 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -1,6 +1,7 @@ checkOwnablePermission('page-create', $draftPage->getParent()); $page = $this->pageRepo->publishDraft($draftPage, $request->all()); - Activity::add($page, 'page_create', $draftPage->book->id); return redirect($page->getUrl()); } @@ -224,7 +224,6 @@ class PageController extends Controller $this->checkOwnablePermission('page-update', $page); $this->pageRepo->update($page, $request->all()); - Activity::add($page, 'page_update', $page->book->id); return redirect($page->getUrl()); } @@ -304,11 +303,9 @@ class PageController extends Controller { $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug); $this->checkOwnablePermission('page-delete', $page); + $parent = $page->getParent(); - $book = $page->book; - $parent = $page->chapter ?? $book; $this->pageRepo->destroy($page); - Activity::add($page, 'page_delete', $page->book_id); return redirect($parent->getUrl()); } @@ -393,7 +390,6 @@ class PageController extends Controller return redirect()->back(); } - Activity::add($page, 'page_move', $page->book->id); $this->showSuccessNotification(trans('entities.pages_move_success', ['parentName' => $parent->name])); return redirect($page->getUrl()); } @@ -438,8 +434,6 @@ class PageController extends Controller return redirect()->back(); } - Activity::add($pageCopy, 'page_create', $pageCopy->book->id); - $this->showSuccessNotification(trans('entities.pages_copy_success')); return redirect($pageCopy->getUrl()); } diff --git a/app/Http/Controllers/PageRevisionController.php b/app/Http/Controllers/PageRevisionController.php index 797f5db8f..b56235d5b 100644 --- a/app/Http/Controllers/PageRevisionController.php +++ b/app/Http/Controllers/PageRevisionController.php @@ -1,5 +1,6 @@ pageRepo->restoreRevision($page, $revisionId); - Activity::add($page, 'page_restore', $page->book->id); return redirect($page->getUrl()); } diff --git a/app/Http/Controllers/RecycleBinController.php b/app/Http/Controllers/RecycleBinController.php index 459dbb39d..928310779 100644 --- a/app/Http/Controllers/RecycleBinController.php +++ b/app/Http/Controllers/RecycleBinController.php @@ -1,5 +1,6 @@ findOrFail($id); + $this->logActivity(ActivityType::RECYCLE_BIN_RESTORE, $deletion); $restoreCount = (new TrashCan())->restoreFromDeletion($deletion); $this->showSuccessNotification(trans('settings.recycle_bin_restore_notification', ['count' => $restoreCount])); @@ -83,6 +85,7 @@ class RecycleBinController extends Controller { /** @var Deletion $deletion */ $deletion = Deletion::query()->findOrFail($id); + $this->logActivity(ActivityType::RECYCLE_BIN_DESTROY, $deletion); $deleteCount = (new TrashCan())->destroyFromDeletion($deletion); $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount])); @@ -97,6 +100,7 @@ class RecycleBinController extends Controller { $deleteCount = (new TrashCan())->empty(); + $this->logActivity(ActivityType::RECYCLE_BIN_EMPTY); $this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount])); return redirect($this->recycleBinBaseUrl); } diff --git a/app/Http/Controllers/PermissionController.php b/app/Http/Controllers/RoleController.php similarity index 90% rename from app/Http/Controllers/PermissionController.php rename to app/Http/Controllers/RoleController.php index 1200d44ab..6e3d5afdc 100644 --- a/app/Http/Controllers/PermissionController.php +++ b/app/Http/Controllers/RoleController.php @@ -6,7 +6,7 @@ use Exception; use Illuminate\Http\Request; use Illuminate\Validation\ValidationException; -class PermissionController extends Controller +class RoleController extends Controller { protected $permissionsRepo; @@ -23,7 +23,7 @@ class PermissionController extends Controller /** * Show a listing of the roles in the system. */ - public function listRoles() + public function list() { $this->checkPermission('user-roles-manage'); $roles = $this->permissionsRepo->getAllRoles(); @@ -33,7 +33,7 @@ class PermissionController extends Controller /** * Show the form to create a new role */ - public function createRole() + public function create() { $this->checkPermission('user-roles-manage'); return view('settings.roles.create'); @@ -42,7 +42,7 @@ class PermissionController extends Controller /** * Store a new role in the system. */ - public function storeRole(Request $request) + public function store(Request $request) { $this->checkPermission('user-roles-manage'); $this->validate($request, [ @@ -59,7 +59,7 @@ class PermissionController extends Controller * Show the form for editing a user role. * @throws PermissionsException */ - public function editRole(string $id) + public function edit(string $id) { $this->checkPermission('user-roles-manage'); $role = $this->permissionsRepo->getRoleById($id); @@ -73,7 +73,7 @@ class PermissionController extends Controller * Updates a user role. * @throws ValidationException */ - public function updateRole(Request $request, string $id) + public function update(Request $request, string $id) { $this->checkPermission('user-roles-manage'); $this->validate($request, [ @@ -90,7 +90,7 @@ class PermissionController extends Controller * Show the view to delete a role. * Offers the chance to migrate users. */ - public function showDeleteRole(string $id) + public function showDelete(string $id) { $this->checkPermission('user-roles-manage'); $role = $this->permissionsRepo->getRoleById($id); @@ -105,7 +105,7 @@ class PermissionController extends Controller * Migrate from a previous role if set. * @throws Exception */ - public function deleteRole(Request $request, string $id) + public function delete(Request $request, string $id) { $this->checkPermission('user-roles-manage'); diff --git a/app/Http/Controllers/SettingController.php b/app/Http/Controllers/SettingController.php index 50d91d388..92435f924 100644 --- a/app/Http/Controllers/SettingController.php +++ b/app/Http/Controllers/SettingController.php @@ -1,5 +1,6 @@ all() as $name => $value) { + $key = str_replace('setting-', '', trim($name)); if (strpos($name, 'setting-') !== 0) { continue; } - $key = str_replace('setting-', '', trim($name)); setting()->put($key, $value); } @@ -68,8 +69,10 @@ class SettingController extends Controller setting()->remove('app-logo'); } + $section = $request->get('section', ''); + $this->logActivity(ActivityType::SETTINGS_UPDATE, $section); $this->showSuccessNotification(trans('settings.settings_save_success')); - $redirectLocation = '/settings#' . $request->get('section', ''); + $redirectLocation = '/settings#' . $section; return redirect(rtrim($redirectLocation, '#')); } } diff --git a/app/Http/Controllers/UserApiTokenController.php b/app/Http/Controllers/UserApiTokenController.php index 55675233c..ab0e9069e 100644 --- a/app/Http/Controllers/UserApiTokenController.php +++ b/app/Http/Controllers/UserApiTokenController.php @@ -1,9 +1,9 @@ flash('api-token-secret:' . $token->id, $secret); $this->showSuccessNotification(trans('settings.user_api_token_create_success')); + $this->logActivity(ActivityType::API_TOKEN_CREATE, $token); + return redirect($user->getEditUrl('/api-tokens/' . $token->id)); } @@ -93,6 +95,7 @@ class UserApiTokenController extends Controller ])->save(); $this->showSuccessNotification(trans('settings.user_api_token_update_success')); + $this->logActivity(ActivityType::API_TOKEN_UPDATE, $token); return redirect($user->getEditUrl('/api-tokens/' . $token->id)); } @@ -117,6 +120,8 @@ class UserApiTokenController extends Controller $token->delete(); $this->showSuccessNotification(trans('settings.user_api_token_delete_success')); + $this->logActivity(ActivityType::API_TOKEN_DELETE, $token); + return redirect($user->getEditUrl('#api_tokens')); } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 651dedc0d..b1b7e5c44 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -1,5 +1,6 @@ userRepo->downloadAndAssignUserAvatar($user); + $this->logActivity(ActivityType::USER_CREATE, $user); return redirect('/settings/users'); } @@ -194,6 +196,7 @@ class UserController extends Controller $user->save(); $this->showSuccessNotification(trans('settings.users_edit_success')); + $this->logActivity(ActivityType::USER_UPDATE, $user); $redirectUrl = userCan('users-manage') ? '/settings/users' : ('/settings/users/' . $user->id); return redirect($redirectUrl); @@ -234,6 +237,7 @@ class UserController extends Controller $this->userRepo->destroy($user); $this->showSuccessNotification(trans('settings.users_delete_success')); + $this->logActivity(ActivityType::USER_DELETE, $user); return redirect('/settings/users'); } diff --git a/app/Interfaces/Loggable.php b/app/Interfaces/Loggable.php new file mode 100644 index 000000000..33e1d7c95 --- /dev/null +++ b/app/Interfaces/Loggable.php @@ -0,0 +1,11 @@ +renameColumn('key', 'type'); + $table->renameColumn('extra', 'detail'); + $table->dropColumn('book_id'); + $table->integer('entity_id')->nullable()->change(); + $table->string('entity_type', 191)->nullable()->change(); + }); + + DB::table('activities') + ->where('entity_id', '=', 0) + ->update([ + 'entity_id' => null, + 'entity_type' => null, + ]); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + DB::table('activities') + ->whereNull('entity_id') + ->update([ + 'entity_id' => 0, + 'entity_type' => '', + ]); + + Schema::table('activities', function (Blueprint $table) { + $table->renameColumn('type', 'key'); + $table->renameColumn('detail', 'extra'); + $table->integer('book_id'); + + $table->integer('entity_id')->change(); + $table->string('entity_type', 191)->change(); + + $table->index('book_id'); + }); + } +} diff --git a/resources/lang/en/activities.php b/resources/lang/en/activities.php index 4cac54b2a..fe937b061 100644 --- a/resources/lang/en/activities.php +++ b/resources/lang/en/activities.php @@ -45,4 +45,5 @@ return [ // Other 'commented_on' => 'commented on', + 'permissions_update' => 'updated permissions', ]; diff --git a/resources/lang/en/settings.php b/resources/lang/en/settings.php index 269c775ba..dce345426 100755 --- a/resources/lang/en/settings.php +++ b/resources/lang/en/settings.php @@ -111,7 +111,7 @@ return [ 'audit_deleted_item_name' => 'Name: :name', 'audit_table_user' => 'User', 'audit_table_event' => 'Event', - 'audit_table_item' => 'Related Item', + 'audit_table_related' => 'Related Item or Detail', 'audit_table_date' => 'Activity Date', 'audit_date_from' => 'Date Range From', 'audit_date_to' => 'Date Range To', @@ -157,6 +157,7 @@ return [ 'user_profile' => 'User Profile', 'users_add_new' => 'Add New User', 'users_search' => 'Search Users', + 'users_latest_activity' => 'Latest Activity', 'users_details' => 'User Details', 'users_details_desc' => 'Set a display name and an email address for this user. The email address will be used for logging into the application.', 'users_details_desc_no_email' => 'Set a display name for this user so others can recognise them.', diff --git a/resources/views/settings/audit.blade.php b/resources/views/settings/audit.blade.php index 47a2355d1..1996e1c21 100644 --- a/resources/views/settings/audit.blade.php +++ b/resources/views/settings/audit.blade.php @@ -19,8 +19,8 @@
@@ -53,7 +53,7 @@@@ -37,6 +36,9 @@ {{ trans('auth.email') }} | {{ trans('settings.role_user_roles') }} | ++ {{ trans('settings.users_latest_activity') }} + |
---|---|---|
+ @if($user->latestActivity) + {{ $user->latestActivity->created_at->diffForHumans() }} + @endif + |