-
Notifications
You must be signed in to change notification settings - Fork 2
fix: make clients shared across all users while keeping work entries per-user #482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,13 +8,13 @@ const router = express.Router(); | |
| // All routes require authentication | ||
| router.use(authenticateUser); | ||
|
|
||
| // Get all clients for authenticated user | ||
| // Get all clients (shared across all users) | ||
| router.get('/', (req, res) => { | ||
| const db = getDatabase(); | ||
|
|
||
| db.all( | ||
| 'SELECT id, name, description, department, email, created_at, updated_at FROM clients WHERE user_email = ? ORDER BY name', | ||
| [req.userEmail], | ||
| 'SELECT id, name, description, department, email, created_at, updated_at FROM clients ORDER BY name', | ||
| [], | ||
| (err, rows) => { | ||
| if (err) { | ||
| console.error('Database error:', err); | ||
|
|
@@ -37,8 +37,8 @@ router.get('/:id', (req, res) => { | |
| const db = getDatabase(); | ||
|
|
||
| db.get( | ||
| 'SELECT id, name, description, department, email, created_at, updated_at FROM clients WHERE id = ? AND user_email = ?', | ||
| [clientId, req.userEmail], | ||
| 'SELECT id, name, description, department, email, created_at, updated_at FROM clients WHERE id = ?', | ||
| [clientId], | ||
| (err, row) => { | ||
| if (err) { | ||
| console.error('Database error:', err); | ||
|
|
@@ -113,10 +113,10 @@ router.put('/:id', (req, res, next) => { | |
|
|
||
| const db = getDatabase(); | ||
|
|
||
| // Check if client exists and belongs to user | ||
| // Check if client exists | ||
| db.get( | ||
| 'SELECT id FROM clients WHERE id = ? AND user_email = ?', | ||
| [clientId, req.userEmail], | ||
| 'SELECT id FROM clients WHERE id = ?', | ||
| [clientId], | ||
| (err, row) => { | ||
| if (err) { | ||
| console.error('Database error:', err); | ||
|
|
@@ -152,9 +152,9 @@ router.put('/:id', (req, res, next) => { | |
| } | ||
|
|
||
| updates.push('updated_at = CURRENT_TIMESTAMP'); | ||
| values.push(clientId, req.userEmail); | ||
| values.push(clientId); | ||
|
|
||
| const query = `UPDATE clients SET ${updates.join(', ')} WHERE id = ? AND user_email = ?`; | ||
| const query = `UPDATE clients SET ${updates.join(', ')} WHERE id = ?`; | ||
|
|
||
| db.run(query, values, function(err) { | ||
| if (err) { | ||
|
|
@@ -186,27 +186,6 @@ router.put('/:id', (req, res, next) => { | |
| } | ||
| }); | ||
|
|
||
| // Delete all clients for authenticated user | ||
| router.delete('/', (req, res) => { | ||
| const db = getDatabase(); | ||
|
|
||
| db.run( | ||
| 'DELETE FROM clients WHERE user_email = ?', | ||
| [req.userEmail], | ||
| function(err) { | ||
| if (err) { | ||
| console.error('Database error:', err); | ||
| return res.status(500).json({ error: 'Failed to delete clients' }); | ||
| } | ||
|
|
||
| res.json({ | ||
| message: 'All clients deleted successfully', | ||
| deletedCount: this.changes | ||
| }); | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| // Delete client | ||
| router.delete('/:id', (req, res) => { | ||
| const clientId = parseInt(req.params.id); | ||
|
|
@@ -217,10 +196,10 @@ router.delete('/:id', (req, res) => { | |
|
|
||
| const db = getDatabase(); | ||
|
|
||
| // Check if client exists and belongs to user | ||
| // Check if client exists | ||
| db.get( | ||
| 'SELECT id FROM clients WHERE id = ? AND user_email = ?', | ||
| [clientId, req.userEmail], | ||
| 'SELECT id FROM clients WHERE id = ?', | ||
| [clientId], | ||
|
Comment on lines
200
to
+202
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Removing user_email check on client delete allows any user to cascade-delete other users' work entries The authorization check ( Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
| (err, row) => { | ||
| if (err) { | ||
| console.error('Database error:', err); | ||
|
|
@@ -233,8 +212,8 @@ router.delete('/:id', (req, res) => { | |
|
|
||
| // Delete client (work entries will be deleted due to CASCADE) | ||
| db.run( | ||
| 'DELETE FROM clients WHERE id = ? AND user_email = ?', | ||
| [clientId, req.userEmail], | ||
| 'DELETE FROM clients WHERE id = ?', | ||
| [clientId], | ||
| function(err) { | ||
| if (err) { | ||
| console.error('Database error:', err); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Frontend "Clear All" button calls removed backend endpoint, causing 404
The PR removed the
DELETE /api/clients(delete-all) route handler frombackend/src/routes/clients.js:189-208(old lines), but the frontend still references it.frontend/src/api/client.ts:84-87definesdeleteAllClients()which callsDELETE /api/clients, andfrontend/src/pages/ClientsPage.tsx:83-92wires it into adeleteAllMutationrendered as a "Clear All" button atClientsPage.tsx:174-184. When a user clicks this button, the request will get a 404 since no route handler matchesDELETE /api/clientsanymore (the remainingDELETE /:idroute won't match an empty id segment).Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.