Admin audit 2026 06 03#1
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds admin-facing tooling to audit MongoDB indexes and to recompute likeCount fields from likedBy, and tightens the API to prevent likeCount from being set directly via design-item updates.
Changes:
- Added admin API endpoints for recomputing like counts, auditing indexes, and viewing recent admin audit records.
- Added a lightweight static admin page + JS to invoke the new admin endpoints.
- Added Node.js tooling scripts for audit/recompute and updated
jsdomdependency version.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/adminForceRecompute.js | Adds a CLI recompute script using an aggregation-pipeline updateMany. |
| tools/adminAudit.js | Adds a CLI audit script that recomputes like counts and prints index info. |
| server.js | Prevents design-item likeCount writes via CRUD updates; adds admin endpoints for recompute/audit/history. |
| public/admin.js | Adds a small browser script to call the new admin endpoints with a JWT. |
| public/admin.html | Adds a static admin UI page for audit/recompute/history operations. |
| package.json | Adds admin-audit script and changes jsdom version. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $expr: { | ||
| $ne: [ | ||
| { $ifNull: ["$likeCount", null] }, | ||
| { $size: { $ifNull: ["$likedBy", []] } } |
Comment on lines
+24
to
+25
| likedBy: { $ifNull: ["$likedBy", []] }, | ||
| likeCount: { $size: { $ifNull: ["$likedBy", []] } } |
| const summary = {}; | ||
| for (const name of collectionNames) { | ||
| const col = db.collection(name); | ||
| const cursor = col.find(); |
|
|
||
| if (matched > 0) { | ||
| const result = await bulk.execute(); | ||
| modified = result.nModified || result.nModified === undefined ? (result.nModified || Object.values(result).reduce((s, v) => s + (v.nModified || 0), 0)) : result.nModified; |
| const db = client.db(DB_NAME); | ||
| console.log('Connected to', uri, 'db:', DB_NAME); | ||
|
|
||
| const targets = ['posts', 'designItems', 'staticBlogItems', 'achievers']; |
Comment on lines
+549
to
+553
| buildUpdate: (body) => ({ | ||
| title: body.title, | ||
| imageUrl: body.imageUrl, | ||
| category: body.category | ||
| }), |
| <h2>Admin: Audit & Recompute</h2> | ||
| <p>Paste an admin JWT below, then run the audit or recompute operations.</p> | ||
| <div class="row"> | ||
| <input id="token" type="text" placeholder="Bearer token" /> |
| </div> | ||
|
|
||
| <h3>Result</h3> | ||
| <textarea id="output" readonly></textarea> |
| "express-rate-limit": "^8.5.2", | ||
| "helmet": "^8.2.0", | ||
| "jsdom": "^29.1.1", | ||
| "jsdom": "^22.1.0", |
| const db = client.db(DB_NAME); | ||
| console.log('Connected to', uri, 'db:', DB_NAME); | ||
|
|
||
| const targets = ['posts', 'designItems', 'staticBlogItems', 'achievers']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.