docs: Update README with admin system and role management

- Document first-user automatic admin assignment
- Update admin setup instructions with correct database name
- Add last-user protection documentation
- Update API endpoints with role field and protection notes
- Document Bruno collection reorganization and admin folder
- Clarify authentication flow and role-based access
- Update role permissions section with new protections
This commit is contained in:
2026-01-26 21:19:29 -05:00
parent f2994f9147
commit d4feea15c5
+24 -7
View File
@@ -87,18 +87,30 @@ echo "DBPASS=$DBPASS" >> .env
### Admin Setup ### Admin Setup
After creating your first user account, you'll need to set up admin privileges: The first user who registers automatically becomes an admin. For subsequent users, you can manually set admin privileges:
**Option 1: Direct Database Update** **Option 1: Direct Database Update**
```sql ```sql
-- Connect to the database and update user role -- Connect to database and update user role
UPDATE users SET role = 'admin' WHERE email = 'your-admin-email@example.com'; UPDATE users SET role = 'admin' WHERE email = 'your-admin-email@example.com';
``` ```
**Option 2: Using psql** **Option 2: Using psql**
```bash ```bash
# Connect to the running database container # Connect to the running database container
docker exec -it bookmann-db-1 psql -U postgres -d ebookdb docker exec -it bookmann_db psql -U postgres -d bookmann
# Update user role
UPDATE users SET role = 'admin' WHERE email = 'your-admin-email@example.com';
# Exit psql
\q
```
**Option 2: Using psql**
```bash
# Connect to the running database container
docker exec -it bookmann-db-1 psql -U postgres -d bookmann
# Update user role # Update user role
UPDATE users SET role = 'admin' WHERE email = 'your-admin-email@example.com'; UPDATE users SET role = 'admin' WHERE email = 'your-admin-email@example.com';
@@ -111,6 +123,8 @@ UPDATE users SET role = 'admin' WHERE email = 'your-admin-email@example.com';
- **Admin Users**: Can add/edit/delete folders, scan ebooks, modify/delete any ebook metadata - **Admin Users**: Can add/edit/delete folders, scan ebooks, modify/delete any ebook metadata
- **Regular Users**: Can view all ebooks, rate books, track reading progress, manage their profile - **Regular Users**: Can view all ebooks, rate books, track reading progress, manage their profile
- **Shared Library**: All users see the same ebook collection, but only admins can modify it - **Shared Library**: All users see the same ebook collection, but only admins can modify it
- **First User Protection**: The very first user to register automatically becomes admin
- **Last User Protection**: The system prevents deletion of the last remaining user account
**Option 2: Using docker-compose variables** **Option 2: Using docker-compose variables**
1. Clone the repository 1. Clone the repository
@@ -128,7 +142,7 @@ UPDATE users SET role = 'admin' WHERE email = 'your-admin-email@example.com';
### Database ### Database
PostgreSQL runs on port 5432 with default credentials: PostgreSQL runs on port 5432 with default credentials:
- Database: ebookdb - Database: bookmann
- User: postgres - User: postgres
- Password: password - Password: password
@@ -160,7 +174,9 @@ The application uses Go HTML templates for server-side rendering with HTMX for d
## API Endpoints ## API Endpoints
### Auth (Public) ### Auth (Public)
- `POST /api/auth/register` - Register new user - `POST /api/auth/register` - Register new user (role field: "user" or "admin")
- **Auto-Admin**: First user automatically gets admin role
- **Role Validation**: Subsequent users can specify "user" or "admin"
- `POST /api/auth/login` - Login user (email or username) - `POST /api/auth/login` - Login user (email or username)
- `GET /api/auth/profile` - Get user profile (requires JWT) - `GET /api/auth/profile` - Get user profile (requires JWT)
- `PUT /api/auth/profile` - Update user profile (first_name, last_name) (requires JWT) - `PUT /api/auth/profile` - Update user profile (first_name, last_name) (requires JWT)
@@ -169,6 +185,7 @@ The application uses Go HTML templates for server-side rendering with HTMX for d
- `PUT /api/user/email` - Update email (requires JWT) - `PUT /api/user/email` - Update email (requires JWT)
- `PUT /api/user/password` - Update password (requires JWT) - `PUT /api/user/password` - Update password (requires JWT)
- `DELETE /api/user/account` - Delete user account (requires JWT) - `DELETE /api/user/account` - Delete user account (requires JWT)
- **Protection**: Cannot delete the last user account
### Ebook Folders (Admin Only) ### Ebook Folders (Admin Only)
- `POST /api/auth/ebook-folders` - Add an ebook folder for scanning - `POST /api/auth/ebook-folders` - Add an ebook folder for scanning
@@ -182,7 +199,7 @@ The application uses Go HTML templates for server-side rendering with HTMX for d
### Ebooks (Mixed Access) ### Ebooks (Mixed Access)
- `GET /api/ebooks` - List ebooks (all authenticated users) - `GET /api/ebooks` - List ebooks (all authenticated users)
- `GET /api/ebooks/:id` - Get specific ebook (all authenticated users) - `GET /api/ebooks/:id` - Get specific ebook (all authenticated users)
- `POST /api/ebooks` - Create new ebook (admin only) - `POST /api/ebooks` - Create new ebook (admin only, tracks admin who added it)
- `PUT /api/ebooks/:id` - Update ebook (admin only) - `PUT /api/ebooks/:id` - Update ebook (admin only)
- `DELETE /api/ebooks/:id` - Delete ebook (admin only) - `DELETE /api/ebooks/:id` - Delete ebook (admin only)
@@ -409,4 +426,4 @@ Use the included Bruno collection in the `bruno/` directory for testing the API:
## License ## License
GPL-3.0 GPL-3.0