Repository navigation
fix(server): keep costly generation to admins and managers - #1769
Merged
Merged
Conversation
…anges The API writes with the service role, so the database's admin-or-manager rules on content_opportunities and the suggestion tables never reached these routes: an analyst could delete opportunities for good, and an agency partner could dismiss prompt suggestions. A shared assertRole in lib/access.js now checks the profile's role after the organization check: - PATCH /api/content/:id/status: any member records progress; dismissing, or moving a dismissed one back, is for admins and managers. - POST /api/content/bulk/status and /bulk/delete: admins and managers. - POST /api/prompts/suggestions/:id/dismiss: not agency partners, as the table's update rule; /accept: admins and managers, who add prompts. - POST /api/topics/suggestions/:id/accept and /dismiss: admins and managers, as the Topics page offers them. The web hides what the role can't do: the Opportunities bulk bar's Done, Dismiss All and Delete and the row and panel Dismiss; on Prompt Suggestions, Add and Add All for analysts, and Dismiss and Clear All for agency partners too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An admin can make as many managers as the team needs, so generating with AI is theirs (2026-10-29): suggestions, opportunities, briefs and Improve. The routes check the caller's role after the organization check and before anything is generated or queued, with a 403 that says who can: - POST /api/prompts/suggestions/:brandId/refresh, /suggestions/:brandId/page and /suggest - POST /api/topics/suggest and /suggestions/:brandId/refresh - POST /api/content/generate, /opportunities/generate, /:id/alternative, /prompts/:promptId/suggest and /:id/brief - POST /api/prompts/:promptId/improve, and the Improve send to the Action Center (the dashboard's and an API key's alike) The web shows these only to admins and managers and tells anyone else who can, from en.json (managersOnly): Prompt Suggestions' New and Generate, the Topic suggestions' Generate, Content Opportunities' New, the panel's Generate Brief and Another angle, the Improve tab's Generate, Regenerate and Send Actions, Insights' and Mentions' Suggest content, and the AI Traffic pages' Add prompts and Suggest content. Writing in the Content Editor, Site Audits and task updates stay open to every member. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…gers Track adds prompts, which only admins and managers may do, but the Insights Opportunities card offered it to everyone. It now shows only to them, as Suggest content already does; anyone else keeps a topic's Send action and reads who can track or suggest content (managersOnly, en.json). Adds tests for the card by role and for Topic Suggestions by role. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
approved these changes
Oct 29, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good with 94b9b9e8: rebased onto main and fixed two tests
Reviewed this PR's own change (#1763's head 47bfd96 → d16b459: f35d799 and d16b459), read on main 3b7611c.
What I changed (branch take-1769, built on main 3b7611c: this PR's two commits cherry-picked onto it, plus two test fixes)
- The base. As it stands, the branch doesn't merge with main. #1763 was squashed with later changes, so its old copy here conflicts in four web files:
content/page.test.tsx,_suggestions-card.tsx,_suggestions-card.test.tsxandopportunity-detail.test.tsx. The PR's own two commits apply to main cleanly. - 0002acec,
_topic-suggestions-card.test.tsx. The card remembers being open inlocalStorage. The first test opens it, so in the second test the mount opens it and the test's click closes it again. "tells an analyst or an agency partner who generates them" then failed. The tests now clear storage first. The test still fails if the card's change is removed. - 94b9b9e8,
prompts-improve-page-checks.test.js. This test came to main with #1724, after this branch was cut. Its user had no role, so with this PRPOST /:promptId/improveanswered 403 and the test failed. The user is now a manager.
What I checked
- Placement. Each of the 12 routes checks the role after its own access check, so another organization's id still reads as not found. Each check also runs before quota, idempotency and the job are touched.
/content/generate,/opportunities/generate,/:id/alternative,/prompts/:promptId/suggestand/:id/brief/prompts/suggestions/:brandId/refreshand/page,/prompts/suggest,/:promptId/improveandsendImproveAction/topics/suggestand/topics/suggestions/:brandId/refresh
sendImproveAction. It serves both the dashboard's Send Actions and the internal route behind the MCP'screate_improve_action, so an API key is checked by both layers.- Error passing. The catch blocks that used to turn the 403 into a 500 now pass through
statusandcode. - Setup.
/prompts/suggestand/topics/suggestalso run during setup and Add brand. A new organization's first user getsadminby default, and adding a brand is admin/manager in RLS, so setup isn't blocked. - Each check is tested. I removed each of the 12 checks one at a time, and
costly-roles.test.jsfailed every time, on that route. Without the server change,prompts-improve-send.test.jsfails too. - Web. The buttons read
canManagefromuseUserRole, the same flag the RLS-backed UI already uses. The dashboard layout fills it on the server, so it doesn't flicker. Where a button is hidden, a note shows instead, and row menus drop the item. - Embeds: none added or changed.
- Read-only workspace. No new write route or server action.
subscription-guard-coverage.test.tspasses on main with this PR and #1770. - Tests (on main with this PR and #1770). Full server suite: 284 of 295 files pass. The rest:
- Eight Framer/CMS files can't load
framer-apiin my local install, the same on main. - The
content-peopleandaudittiming tests pass when re-run. - The improve page-checks test is fixed above.
- Web:
tscis clean, and the touched component tests,lib/mcp,api/mcp,lib/agentandsubscription-guard-coveragepass: 61 files, 408 tests. The full web suite gives 598 of 600 files; the two timing tests that failed under load (shopping categories, Library paging) pass when re-run. eslint and prettier are clean on the touched files.
- Eight Framer/CMS files can't load
Before merging
- Merge
take-1769, not this branch: this branch conflicts with main. - Web and API can ship in either order. With the web first, analysts lose the buttons early. With the API first, an analyst's click gets the 403 message.
This was referenced Oct 29, 2026
Merged
gkhngyk
added a commit
that referenced
this pull request
Oct 30, 2026
…gestions (#1808) * fix(prompts): ask for a topic before adding prompts or generating suggestions Prompts are grouped under topics, but a brand with none could still add them: the Add Prompt dialog said "No topics defined yet. Add topics in brand settings." and saved the prompt without a topic, Track buttons did the same, and generating suggestions made topics the person never chose from the AI's labels (findOrCreateTopic). Server (API): - POST /api/prompts/suggestions/:brandId/refresh and /:brandId/page answer 409 { code: 'no_topics' } for a brand with no active topic, after the role check and before anything is generated, reserved or written. Server actions and MCP: - addPromptToSet (every single add: suggestions, Add All, Insights Track, fan-out Track, AI Traffic, People Also Ask) and importPrompts (Add Prompt dialog, bulk import) return { error, code: 'no_topics' } and write nothing. trackPagePrompts checks before it makes a topic. - refreshPromptSuggestions returns { ok: false, failure: 'no_topics' } as a value; other failures still throw, as before. - accept_prompt_suggestion says to add a topic first (accept_topic_suggestion or Prompts > Topics), and its description says so. - A failed topics read never counts as "no topics". UI: - One TopicFirstDialog / TopicFirstNotice (en.json "topicFirst") with an "Add a topic" link to /dashboard/prompts/topics?new=1, which opens Add Topic once and clears the param. Buttons stay visible; a click that hits no_topics shows it. - Add Prompt shows the notice instead of the form when the brand has no topics; it reads topics on every open, so a topic added meanwhile counts. - Brand > Manage prompts replaces the old "brand settings" text in both cards and asks for a topic instead of adding one without. - Onboarding and brand setup (savePromptSet) are unchanged: they create the chosen topics first. Role gating (#1763, #1769) is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(prompts): add a topic in place on the Prompts page, and say why suggestions failed Review follow-ups on the topic-first flow. - Prompts page: "Add a topic" in Add prompt, Suggestions and Query Fan-out is a button that closes the dialog, switches to the Topics tab with showSection and asks TopicsTab to open Add Topic (openAddTopic / onAddTopicOpened). The page reads its tab from the route only when it opens, so the ?new=1 link changed the address alone after a tab switch. Insights, AI Traffic and the prompt page keep the link. - Roles: AddTopicLink, TopicFirstNotice and TopicFirstDialog read canManage. Since #1790 only admins and managers write topics; anyone else gets managersOnly.addTopic and no link, and the dialog's button says Close. - refreshPromptSuggestions returns every failure as a value, as #1777's reads do (apiFailure + isTransientStatus on the body read once, so no_topics stays its own): a used-up budget, a read-only workspace or the demo brand, a role refusal, an outage, no answer. The card shows them with useFailureToast (the upgrade dialog for subscription) instead of a message production hides. - Brand > Manage prompts links to that brand's own topics (/dashboard/brands/:id/topics#add-topic, as the brand card does), not the active brand's. - trackPagePrompts reads active topics only; the AI Traffic page dialog forgets a Track's no_topics on the next open; the Insights test has its own describe block. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(help): say a brand adds a topic before its prompts Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk
added a commit
that referenced
this pull request
Oct 30, 2026
Summary
Costly generation is now for admins and managers only, on the server and in the UI. This follows the role model the product owner decided on 2026-10-29: daily work is open to every role, while settings, permanent deletes, adding prompts and costly actions are for admins and managers. An admin can make any number of managers, so a team can share this work.
Server: 403 "Only admins and managers can …" for analysts and agency partners
POST /api/prompts/suggestions/:brandId/refresh,/suggestions/:brandId/page,/api/prompts/suggestPOST /api/topics/suggest,/api/topics/suggestions/:brandId/refreshPOST /api/content/opportunities/generate,/:id/alternative,/prompts/:promptId/suggest,/api/content/generatePOST /api/content/:id/briefPOST /api/prompts/:promptId/improve, and sending Improve to the Action CenterThe brief,
/content/generate,prompts/suggestandtopics/suggestcatch blocks turned the 403 into a 500; they now pass it on.Web: the buttons that start these show only to admins and managers. Where a button is hidden, a one-line note says who can do it (
managersOnlyinen.json: "Ask an admin or a manager to …").Row menus hide the item without a note.
Stays open to every role: writing, fixing and rewriting in the Content Editor; Site Audit runs; task updates.
Related issue
None.
Stacked on #1763 (server role checks,
assertRole). The diff against it holds only this change.Type of change
fix— Bug fixHow to test
cd server && npx vitest run src/routes/costly-roles.test.js src/routes/prompts-improve-send.test.js: across 12 routes, analysts and agency partners get 403 and nothing is generated or queued; managers pass.Checklist
_before-publish.test.tsxfailed on the focus race that test(content): wait for the dialog's first focus before opening the JSON-LD code #1753 fixes; this branch doesn't touch it.🤖 Generated with Claude Code