]> BookStack Code Mirror - bookstack/blobdiff - app/Auth/UserRepo.php
Extend /users API endpoint
[bookstack] / app / Auth / UserRepo.php
index 29a0ebc14aceae23c3e33fcfece504b4897d14b8..4444c734c35077a557fcdfe8daf8664b082bfe3d 100644 (file)
@@ -45,6 +45,14 @@ class UserRepo
         return User::query()->findOrFail($id);
     }
 
+    /**
+     * Get a user by their slug.
+     */
+    public function getBySlug(string $slug): User
+    {
+        return User::query()->where('slug', '=', $slug)->firstOrFail();
+    }
+
     /**
      * Get all the users with their permissions.
      */
@@ -53,6 +61,16 @@ class UserRepo
         return User::query()->with('roles', 'avatar')->orderBy('name', 'asc')->get();
     }
 
+    /**
+     * Get all users as Builder for API
+     */
+    public function getUsersBuilder(int $id = null ) : Builder
+    {
+        $query = User::query()->select(['*'])
+            ->withLastActivityAt()
+            ->with(['roles', 'avatar']);
+        return $query;
+    }
     /**
      * Get all the users with their permissions in a paginated format.
      */
@@ -159,7 +177,13 @@ class UserRepo
             'email_confirmed' => $emailConfirmed,
             'external_auth_id' => $data['external_auth_id'] ?? '',
         ];
-        return User::query()->forceCreate($details);
+
+        $user = new User();
+        $user->forceFill($details);
+        $user->refreshSlug();
+        $user->save();
+
+        return $user;
     }
 
     /**