]> BookStack Code Mirror - bookstack/commitdiff
Added activity text for each activity type
authorDan Brown <redacted>
Mon, 12 Jun 2023 15:45:30 +0000 (16:45 +0100)
committerDan Brown <redacted>
Mon, 12 Jun 2023 15:47:36 +0000 (16:47 +0100)
Ensures some sensible text is always in webhook text data.
Also aligned some notification reporting to use centralised activity
system instead of custom success events.

For #4216

12 files changed:
app/Api/UserApiTokenController.php
app/Entities/Controllers/ChapterController.php
app/Entities/Controllers/PageController.php
app/Entities/Controllers/PageRevisionController.php
app/Entities/Controllers/RecycleBinController.php
app/Settings/SettingController.php
app/Users/Controllers/UserController.php
lang/en/activities.php
lang/en/entities.php
lang/en/settings.php
tests/LanguageTest.php
tests/Permissions/RolesTest.php

index d8fc1171c41f11e3be488dee6171c114b9f8190e..8357420ee13015f4d8dac9d6315f4b27a267cc28 100644 (file)
@@ -58,7 +58,6 @@ class UserApiTokenController extends Controller
         $token->save();
 
         session()->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));
@@ -96,7 +95,6 @@ class UserApiTokenController extends Controller
             'expires_at' => $request->get('expires_at') ?: ApiToken::defaultExpiry(),
         ])->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));
@@ -123,7 +121,6 @@ class UserApiTokenController extends Controller
         [$user, $token] = $this->checkPermissionAndFetchUserToken($userId, $tokenId);
         $token->delete();
 
-        $this->showSuccessNotification(trans('settings.user_api_token_delete_success'));
         $this->logActivity(ActivityType::API_TOKEN_DELETE, $token);
 
         return redirect($user->getEditUrl('#api_tokens'));
index cf7611685b1529ee9ca940d4fbb4321e7b3dbecc..7dcb669038bca6d770c59b1da206a4f3a74c8afe 100644 (file)
@@ -191,8 +191,6 @@ class ChapterController extends Controller
             return redirect()->back();
         }
 
-        $this->showSuccessNotification(trans('entities.chapter_move_success', ['bookName' => $newBook->name]));
-
         return redirect($chapter->getUrl());
     }
 
index e0444ecd2198f0bca4827227149947d3fd6528a8..3187e6486fa6d60b82ea2a0e6625a278ce4f223f 100644 (file)
@@ -389,7 +389,7 @@ class PageController extends Controller
         }
 
         try {
-            $parent = $this->pageRepo->move($page, $entitySelection);
+            $this->pageRepo->move($page, $entitySelection);
         } catch (PermissionsException $exception) {
             $this->showPermissionError();
         } catch (Exception $exception) {
@@ -398,8 +398,6 @@ class PageController extends Controller
             return redirect()->back();
         }
 
-        $this->showSuccessNotification(trans('entities.pages_move_success', ['parentName' => $parent->name]));
-
         return redirect($page->getUrl());
     }
 
index a723513a868011b5ed398e9b4758592958425c89..9e6a90477984cf01b1db0398b67512f944f32d2a 100644 (file)
@@ -15,11 +15,9 @@ use Ssddanbrown\HtmlDiff\Diff;
 
 class PageRevisionController extends Controller
 {
-    protected PageRepo $pageRepo;
-
-    public function __construct(PageRepo $pageRepo)
-    {
-        $this->pageRepo = $pageRepo;
+    public function __construct(
+        protected PageRepo $pageRepo
+    ) {
     }
 
     /**
@@ -153,7 +151,6 @@ class PageRevisionController extends Controller
 
         $revision->delete();
         Activity::add(ActivityType::REVISION_DELETE, $revision);
-        $this->showSuccessNotification(trans('entities.revision_delete_success'));
 
         return redirect($page->getUrl('/revisions'));
     }
index 30b184bbe00c9356cffe5707606faf0d127e9ecb..78f86a5ae5076df7c5cea7320b2c25fc657a121b 100644 (file)
@@ -11,7 +11,7 @@ use BookStack\Http\Controller;
 
 class RecycleBinController extends Controller
 {
-    protected $recycleBinBaseUrl = '/settings/recycle-bin';
+    protected string $recycleBinBaseUrl = '/settings/recycle-bin';
 
     /**
      * On each request to a method of this controller check permissions
index ffdd7545e7837678a6328591c8aa502e9bcaa290..bd55222f2302ee6a820fff3f67c8ecb8a007c4ad 100644 (file)
@@ -52,9 +52,7 @@ class SettingController extends Controller
         ]);
 
         $store->storeFromUpdateRequest($request, $category);
-
         $this->logActivity(ActivityType::SETTINGS_UPDATE, $category);
-        $this->showSuccessNotification(trans('settings.settings_save_success'));
 
         return redirect("/settings/{$category}");
     }
index b185f0856410ccdc4ca4d2fecfea5ff80481f031..1c1b7ba23903ae48465ac81ade2f742bb507ad5d 100644 (file)
@@ -19,13 +19,10 @@ use Illuminate\Validation\ValidationException;
 
 class UserController extends Controller
 {
-    protected UserRepo $userRepo;
-    protected ImageRepo $imageRepo;
-
-    public function __construct(UserRepo $userRepo, ImageRepo $imageRepo)
-    {
-        $this->userRepo = $userRepo;
-        $this->imageRepo = $imageRepo;
+    public function __construct(
+        protected UserRepo $userRepo,
+        protected ImageRepo $imageRepo
+    ) {
     }
 
     /**
index e89b8eab2555df9489efbafc0f6ad3cf2ab31608..e71a490de4696d4924e354db69751e746f0dbac4 100644 (file)
@@ -15,6 +15,7 @@ return [
     'page_restore'                => 'restored page',
     'page_restore_notification'   => 'Page successfully restored',
     'page_move'                   => 'moved page',
+    'page_move_notification'      => 'Page successfully moved',
 
     // Chapters
     'chapter_create'              => 'created chapter',
@@ -24,6 +25,7 @@ return [
     'chapter_delete'              => 'deleted chapter',
     'chapter_delete_notification' => 'Chapter successfully deleted',
     'chapter_move'                => 'moved chapter',
+    'chapter_move_notification' => 'Chapter successfully moved',
 
     // Books
     'book_create'                 => 'created book',
@@ -47,14 +49,30 @@ return [
     'bookshelf_delete'                 => 'deleted shelf',
     'bookshelf_delete_notification'    => 'Shelf successfully deleted',
 
+    // Revisions
+    'revision_restore' => 'restored revision',
+    'revision_delete' => 'deleted revision',
+    'revision_delete_notification' => 'Revision successfully deleted',
+
     // Favourites
     'favourite_add_notification' => '":name" has been added to your favourites',
     'favourite_remove_notification' => '":name" has been removed from your favourites',
 
-    // MFA
+    // Auth
+    'auth_login' => 'logged in',
+    'auth_register' => 'registered as new user',
+    'auth_password_reset_request' => 'requested user password reset',
+    'auth_password_reset_update' => 'reset user password',
+    'mfa_setup_method' => 'configured MFA method',
     'mfa_setup_method_notification' => 'Multi-factor method successfully configured',
+    'mfa_remove_method' => 'removed MFA method',
     'mfa_remove_method_notification' => 'Multi-factor method successfully removed',
 
+    // Settings
+    'settings_update' => 'updated settings',
+    'settings_update_notification' => 'Settings successfully updated',
+    'maintenance_action_run' => 'ran maintenance action',
+
     // Webhooks
     'webhook_create' => 'created webhook',
     'webhook_create_notification' => 'Webhook successfully created',
@@ -64,14 +82,34 @@ return [
     'webhook_delete_notification' => 'Webhook successfully deleted',
 
     // Users
+    'user_create' => 'created user',
+    'user_create_notification' => 'User successfully created',
+    'user_update' => 'updated user',
     'user_update_notification' => 'User successfully updated',
+    'user_delete' => 'deleted user',
     'user_delete_notification' => 'User successfully removed',
 
+    // API Tokens
+    'api_token_create' => 'created api token',
+    'api_token_create_notification' => 'API token successfully created',
+    'api_token_update' => 'updated api token',
+    'api_token_update_notification' => 'API token successfully updated',
+    'api_token_delete' => 'deleted api token',
+    'api_token_delete_notification' => 'API token successfully deleted',
+
     // Roles
+    'role_create' => 'created role',
     'role_create_notification' => 'Role successfully created',
+    'role_update' => 'updated role',
     'role_update_notification' => 'Role successfully updated',
+    'role_delete' => 'deleted role',
     'role_delete_notification' => 'Role successfully deleted',
 
+    // Recycle Bin
+    'recycle_bin_empty' => 'emptied recycle bin',
+    'recycle_bin_restore' => 'restored from recycle bin',
+    'recycle_bin_destroy' => 'removed from recycle bin',
+
     // Other
     'commented_on'                => 'commented on',
     'permissions_update'          => 'updated permissions',
index caf9e2361ddbf4a7a44a61a3472aca60fa39aa1d..92903ed1f3fe1a1dfdf8bc5e5c6f730988a5823a 100644 (file)
@@ -180,7 +180,6 @@ return [
     'chapters_save' => 'Save Chapter',
     'chapters_move' => 'Move Chapter',
     'chapters_move_named' => 'Move Chapter :chapterName',
-    'chapter_move_success' => 'Chapter moved to :bookName',
     'chapters_copy' => 'Copy Chapter',
     'chapters_copy_success' => 'Chapter successfully copied',
     'chapters_permissions' => 'Chapter Permissions',
@@ -240,7 +239,6 @@ return [
     'pages_md_sync_scroll' => 'Sync preview scroll',
     'pages_not_in_chapter' => 'Page is not in a chapter',
     'pages_move' => 'Move Page',
-    'pages_move_success' => 'Page moved to ":parentName"',
     'pages_copy' => 'Copy Page',
     'pages_copy_desination' => 'Copy Destination',
     'pages_copy_success' => 'Page successfully copied',
@@ -375,7 +373,6 @@ return [
     // Revision
     'revision_delete_confirm' => 'Are you sure you want to delete this revision?',
     'revision_restore_confirm' => 'Are you sure you want to restore this revision? The current page contents will be replaced.',
-    'revision_delete_success' => 'Revision deleted',
     'revision_cannot_delete_latest' => 'Cannot delete the latest revision.',
 
     // Copy view
index 38d817915b82ed3129d80d4f213a3444d8130af7..c110e89921ad97fa132e8d88305956469d3cf43c 100644 (file)
@@ -9,7 +9,6 @@ return [
     // Common Messages
     'settings' => 'Settings',
     'settings_save' => 'Save Settings',
-    'settings_save_success' => 'Settings saved',
     'system_version' => 'System Version',
     'categories' => 'Categories',
 
@@ -232,8 +231,6 @@ return [
     'user_api_token_expiry' => 'Expiry Date',
     'user_api_token_expiry_desc' => 'Set a date at which this token expires. After this date, requests made using this token will no longer work. Leaving this field blank will set an expiry 100 years into the future.',
     'user_api_token_create_secret_message' => 'Immediately after creating this token a "Token ID" & "Token Secret" will be generated and displayed. The secret will only be shown a single time so be sure to copy the value to somewhere safe and secure before proceeding.',
-    'user_api_token_create_success' => 'API token successfully created',
-    'user_api_token_update_success' => 'API token successfully updated',
     'user_api_token' => 'API Token',
     'user_api_token_id' => 'Token ID',
     'user_api_token_id_desc' => 'This is a non-editable system generated identifier for this token which will need to be provided in API requests.',
@@ -244,7 +241,6 @@ return [
     'user_api_token_delete' => 'Delete Token',
     'user_api_token_delete_warning' => 'This will fully delete this API token with the name \':tokenName\' from the system.',
     'user_api_token_delete_confirm' => 'Are you sure you want to delete this API token?',
-    'user_api_token_delete_success' => 'API token successfully deleted',
 
     // Webhooks
     'webhooks' => 'Webhooks',
index b65227dd826838472ea4ef412f2d42b74b2c7876..a66227ff2e8181f2f560fe3e5e14580d2d4564cf 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace Tests;
 
+use BookStack\Activity\ActivityType;
+
 class LanguageTest extends TestCase
 {
     protected array $langs;
@@ -90,4 +92,12 @@ class LanguageTest extends TestCase
         $loginReq->assertOk();
         $loginReq->assertSee('Log In');
     }
+
+    public function test_all_activity_types_have_activity_text()
+    {
+        foreach (ActivityType::all() as $activityType) {
+            $langKey = 'activities.' . $activityType;
+            $this->assertNotEquals($langKey, trans($langKey, [], 'en'));
+        }
+    }
 }
index dafa1f2bb10de8ae8031815e8f87498c6f6404db..4c8ea1ab48b9b67fa666914946d2c0fb7ca65598 100644 (file)
@@ -301,7 +301,7 @@ class RolesTest extends TestCase
         $resp = $this->post('/settings/features', []);
         $resp->assertRedirect('/settings/features');
         $resp = $this->get('/settings/features');
-        $resp->assertSee('Settings saved');
+        $resp->assertSee('Settings successfully updated');
     }
 
     public function test_restrictions_manage_all_permission()