Add wiki page editing functionality with authentication and git integration
🎉 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
40
TASK_LOG.md
40
TASK_LOG.md
@@ -521,3 +521,43 @@
|
||||
4. JavaScript API calls use Authorization header via `authenticatedFetch()`
|
||||
- **Result:** Working JWT authentication with unstyled HTML forms, supporting both browser navigation and API calls
|
||||
|
||||
---
|
||||
|
||||
### 25. Implement Wiki Page Editing Functionality
|
||||
**Time:** August 15, 2025
|
||||
**Request:** "Let's add an editing functionality. Make a new branch for this or a small batch of kittens will die!"
|
||||
**Actions:**
|
||||
- Created new branch `feature/wiki-editing` for development
|
||||
- **1. Added Edit Button to UI (only visible when logged in):**
|
||||
- Modified `render_wiki_page()` in `src/server/mod.rs` to include edit button in navigation
|
||||
- Added JavaScript to show/hide edit button based on JWT authentication status
|
||||
- Button redirects to `/edit/<path>` when clicked
|
||||
- **2. Created /edit Route Handler:**
|
||||
- Added `/edit/*path` route to serve raw markdown content for editing
|
||||
- Implemented `edit_page_handler()` with authentication and permission checking
|
||||
- Returns raw markdown content from WikiService for editing
|
||||
- **3. Built Multi-line Text Editor Page:**
|
||||
- Created `render_edit_page()` function with full HTML template
|
||||
- Features no-frills textarea editor preserving all whitespace
|
||||
- Added Save and Cancel buttons with proper styling
|
||||
- Auto-focus on editor for immediate typing
|
||||
- **4. Implemented PUT API Endpoint:**
|
||||
- Added PUT handler to `/api/wiki/*path` route for saving edited content
|
||||
- Implemented `save_wiki_handler()` with authentication and permission validation
|
||||
- Uses existing `WikiService.save_page()` method for file operations
|
||||
- **5. Added Git Commit Functionality:**
|
||||
- Created `git_commit_changes()` helper function
|
||||
- Automatically stages and commits edited files if git repository exists
|
||||
- Includes commit message with editor username: "Update {path}\n\nEdited by: {username}"
|
||||
- Fails silently if no git repository present (as requested)
|
||||
- **6. Helper Functions:**
|
||||
- Added `get_user_from_headers()` to extract user from JWT tokens
|
||||
- Made `WikiService.can_edit_page()` method public for permission checking
|
||||
- **Technical Implementation:**
|
||||
- Uses existing authentication system (JWT tokens)
|
||||
- Respects user role permissions (Admin/Editor can edit, Viewer cannot)
|
||||
- Handles both Bearer token headers and auth_token cookies
|
||||
- Proper URL encoding/decoding for nested paths
|
||||
- JavaScript fetch API with proper error handling
|
||||
- **Result:** Complete editing workflow allowing authenticated users to edit any wiki page with automatic git versioning
|
||||
|
||||
|
||||
Reference in New Issue
Block a user