[PR #2734] [CLOSED] DRAFT: API endpoint for user management #6054

Closed
opened 2026-02-05 10:23:29 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/BookStackApp/BookStack/pull/2734
Author: @itbane
Created: 5/6/2021
Status: Closed

Base: developmentHead: api-endpoint-users


📝 Commits (2)

  • 0762666 Test API Endpoint for users
  • 4cbd1a9 Extend /users API endpoint

📊 Changes

5 files changed (+81 additions, -3 deletions)

View changed files

📝 app/Api/ListingResponseBuilder.php (+4 -1)
📝 app/Auth/UserRepo.php (+10 -0)
📝 app/Http/Controllers/Api/ApiController.php (+3 -2)
app/Http/Controllers/Api/UserApiController.php (+61 -0)
📝 routes/api.php (+3 -0)

📄 Description

Hi,

I've found the need to get users (and their email) from the API for automation purposes. As there isn't an endpoint for user management yet, I thought I'd give it a shot and tried to implement it.

I'd like to get some feedback on whether I'm on the right track and should continue working on this.

Disclaimer: I haven't worked with Laravel ever before and my last contact with php was ~10 years ago. I'm grateful for any advice and pointers you can give me to improve the PR.

Tests and CREATE, UPDATE, DELETE operations are still WIP. I've seen someone request SCIM-Support (#2701) - I'd have to look into that.

Current state:

  • GET: /api/users - Route (only accessible with users-manage permissions); lists all users + their roles
  • GET: /api/users/{id} - Route (only accessible with users-manage permissions); lists details of a specific user

Quick overview on my changes / thought process:

  • Add new routes for users
  • Add new Controller UserApiController
  • Use as much from existing User and UserRepo-classes as possible
    • obstacle: apiListingResponse requires a Builder-object, User::getAll() returns a collection
      • If I understood correctly, the collection contains all the data already, while the builder only contains the databasequery
      • solution: Implemented a new Function within UserRepo that returns a Builder-object
    • obstacle: some fields in the User-object are hidden, but need to be displayed, such as email
      • solution: added a new optional parameter to apiListingResponse that takes an array of fields that should be returned anyways (using data->makeVisible() in ListingResponseBuilder::to_response)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/BookStackApp/BookStack/pull/2734 **Author:** [@itbane](https://github.com/itbane) **Created:** 5/6/2021 **Status:** ❌ Closed **Base:** `development` ← **Head:** `api-endpoint-users` --- ### 📝 Commits (2) - [`0762666`](https://github.com/BookStackApp/BookStack/commit/07626669dad962856e52dddeacb1a9f000f93150) Test API Endpoint for users - [`4cbd1a9`](https://github.com/BookStackApp/BookStack/commit/4cbd1a9eb526bcd5fe5d9446dbf27c5813042678) Extend /users API endpoint ### 📊 Changes **5 files changed** (+81 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `app/Api/ListingResponseBuilder.php` (+4 -1) 📝 `app/Auth/UserRepo.php` (+10 -0) 📝 `app/Http/Controllers/Api/ApiController.php` (+3 -2) ➕ `app/Http/Controllers/Api/UserApiController.php` (+61 -0) 📝 `routes/api.php` (+3 -0) </details> ### 📄 Description Hi, I've found the need to get users (and their email) from the API for automation purposes. As there isn't an endpoint for user management yet, I thought I'd give it a shot and tried to implement it. I'd like to get some feedback on whether I'm on the right track and should continue working on this. **Disclaimer**: I haven't worked with Laravel ever before and my last contact with php was ~10 years ago. I'm grateful for any advice and pointers you can give me to improve the PR. Tests and `CREATE`, `UPDATE`, `DELETE` operations are still WIP. I've seen someone request SCIM-Support (#2701) - I'd have to look into that. **Current state:** * GET: `/api/users` - Route (only accessible with `users-manage` permissions); lists all users + their roles * GET: `/api/users/{id}` - Route (only accessible with `users-manage` permissions); lists details of a specific user **Quick overview on my changes / thought process:** - Add new routes for `users` - Add new Controller `UserApiController` - Use as much from existing `User` and `UserRepo`-classes as possible - obstacle: `apiListingResponse` requires a `Builder`-object, `User::getAll()` returns a collection - If I understood correctly, the collection contains all the data already, while the builder only contains the databasequery - solution: Implemented a new Function within `UserRepo` that returns a `Builder`-object - obstacle: some fields in the `User`-object are hidden, but need to be displayed, such as `email` - solution: added a new optional parameter to `apiListingResponse` that takes an array of fields that should be returned anyways (using `data->makeVisible()` in `ListingResponseBuilder::to_response`) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
OVERLORD added the pull-request label 2026-02-05 10:23:29 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#6054