]> BookStack Code Mirror - bookstack/commitdiff
Users API: Fixed incorrect created_at date on index endpoint
authorDan Brown <redacted>
Sat, 17 Jun 2023 17:18:17 +0000 (18:18 +0100)
committerDan Brown <redacted>
Sat, 17 Jun 2023 17:18:17 +0000 (18:18 +0100)
For #4325

app/Activity/Models/Activity.php
app/Users/Controllers/UserApiController.php
dev/api/responses/users-list.json
tests/Api/UsersApiTest.php

index 1fa36e5beaf76e2768b078fe58db64374c4892ea..9e4cb785864e32a60bfbcd7fa01a428022748ea1 100644 (file)
@@ -19,6 +19,8 @@ use Illuminate\Support\Str;
  * @property string $entity_type
  * @property int    $entity_id
  * @property int    $user_id
+ * @property Carbon $created_at
+ * @property Carbon $updated_at
  */
 class Activity extends Model
 {
index 759aafbd84a2364fed6a27773462af9db93394e7..880165e1bc77780b46a5d234c7ba2ed7d36bea49 100644 (file)
@@ -73,7 +73,7 @@ class UserApiController extends ApiController
      */
     public function list()
     {
-        $users = User::query()->select(['*'])
+        $users = User::query()->select(['users.*'])
             ->scopes('withLastActivityAt')
             ->with(['avatar']);
 
index e070ee6a64d648a66735a6bc6a6b3639e48e9118..cbc7fb1043ed3f2efc47e1fe96142c9b613a8991 100644 (file)
@@ -18,7 +18,7 @@
       "id": 2,
       "name": "Benny",
       "email": "benny@example.com",
-      "created_at": "2022-01-31T20:39:24.000000Z",
+      "created_at": "2020-01-15T04:43:11.000000Z",
       "updated_at": "2021-11-18T17:10:58.000000Z",
       "external_auth_id": "",
       "slug": "benny",
index 6af9c2a7a53b8f7ac453c50c2098d4258a1355c3..e2a04b528ee43cac66dec437b28b8b5e046df569 100644 (file)
@@ -3,7 +3,9 @@
 namespace Tests\Api;
 
 use BookStack\Activity\ActivityType;
+use BookStack\Activity\Models\Activity as ActivityModel;
 use BookStack\Entities\Models\Entity;
+use BookStack\Facades\Activity;
 use BookStack\Notifications\UserInvite;
 use BookStack\Users\Models\Role;
 use BookStack\Users\Models\User;
@@ -67,6 +69,27 @@ class UsersApiTest extends TestCase
         ]]);
     }
 
+    public function test_index_endpoint_has_correct_created_and_last_activity_dates()
+    {
+        $user = $this->users->editor();
+        $user->created_at = now()->subYear();
+        $user->save();
+
+        $this->actingAs($user);
+        Activity::add(ActivityType::AUTH_LOGIN, 'test login activity');
+        /** @var ActivityModel $activity */
+        $activity = ActivityModel::query()->where('user_id', '=', $user->id)->latest()->first();
+
+        $resp = $this->asAdmin()->getJson($this->baseEndpoint . '?filter[id]=3');
+        $resp->assertJson(['data' => [
+            [
+                'id'          => $user->id,
+                'created_at' => $user->created_at->toJSON(),
+                'last_activity_at' => $activity->created_at->toJson(),
+            ],
+        ]]);
+    }
+
     public function test_create_endpoint()
     {
         $this->actingAsApiAdmin();
Morty Proxy This is a proxified and sanitized view of the page, visit original site.