-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: allow skill owner to move skill to an org acct while publishing existing skill #1562
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 |
|---|---|---|
|
|
@@ -6169,7 +6169,7 @@ export const insertVersion = internalMutation({ | |
| if (!user || user.deletedAt || user.deactivatedAt) throw new Error("User not found"); | ||
| const personalPublisher = await ensurePersonalPublisherForUser(ctx, user); | ||
| if (!personalPublisher) throw new ConvexError("Personal publisher not found"); | ||
| const ownerPublisherId = args.ownerPublisherId ?? personalPublisher._id; | ||
| let ownerPublisherId = args.ownerPublisherId ?? personalPublisher._id; | ||
| if (ownerPublisherId !== personalPublisher._id) { | ||
| await requirePublisherRole(ctx, { | ||
| publisherId: ownerPublisherId, | ||
|
|
@@ -6204,11 +6204,36 @@ export const insertVersion = internalMutation({ | |
| } | ||
|
|
||
| if (skill && skill.ownerPublisherId && skill.ownerPublisherId !== ownerPublisherId) { | ||
| const owner = await getOwnerPublisher(ctx, { | ||
| ownerPublisherId: skill.ownerPublisherId, | ||
| ownerUserId: skill.ownerUserId, | ||
| }); | ||
| throw new ConvexError(buildSlugTakenErrorMessage(skill, owner)); | ||
| // Only move the skill when the caller explicitly requested a different publisher. | ||
| // When ownerPublisherId was defaulted from the personal publisher (legacy CLI paths), | ||
| // preserve the existing publisher to avoid silently moving org skills to personal. | ||
| const explicitPublisherRequested = Boolean(args.ownerPublisherId); | ||
| if (skill.ownerUserId === userId && explicitPublisherRequested) { | ||
| await ctx.db.patch(skill._id, { ownerPublisherId, updatedAt: now }); | ||
|
Comment on lines
+6210
to
+6212
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.
This branch assumes Useful? React with 👍 / 👎.
Comment on lines
+6210
to
+6212
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.
Using Useful? React with 👍 / 👎. |
||
| const aliases = await ctx.db | ||
| .query("skillSlugAliases") | ||
| .withIndex("by_skill", (q) => q.eq("skillId", skill!._id)) | ||
| .collect(); | ||
| for (const alias of aliases) { | ||
| await ctx.db.patch(alias._id, { ownerPublisherId, updatedAt: now }); | ||
| } | ||
| skill = { ...skill, ownerPublisherId }; | ||
| } else if (skill.ownerUserId === userId && !explicitPublisherRequested) { | ||
| // Owner publishing via a legacy path that doesn't pass ownerPublisherId. | ||
| // Keep the existing publisher, but verify the caller still has access. | ||
| await requirePublisherRole(ctx, { | ||
| publisherId: skill.ownerPublisherId!, | ||
| userId, | ||
| allowed: ["publisher"], | ||
| }); | ||
| ownerPublisherId = skill.ownerPublisherId; | ||
|
Comment on lines
+6221
to
+6229
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.
In the legacy-path branch ( Useful? React with 👍 / 👎. |
||
| } else { | ||
| const owner = await getOwnerPublisher(ctx, { | ||
| ownerPublisherId: skill.ownerPublisherId, | ||
| ownerUserId: skill.ownerUserId, | ||
| }); | ||
| throw new ConvexError(buildSlugTakenErrorMessage(skill, owner)); | ||
| } | ||
| } | ||
|
|
||
| if (skill && !skill.ownerPublisherId && skill.ownerUserId !== userId) { | ||
|
|
||
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.
db.getmock missing"publishers:org"— positive test never exercises new codeWith
ownerPublisherId: "publishers:org"andpersonalPublisher._id = "publishers:personal", the handler callsrequirePublisherRole(ctx, { publisherId: "publishers:org", ... })atskills.ts:5788. That function callsctx.db.get("publishers:org"), which returnsnullhere, soisPublisherActive(null)→ false → throwsConvexError("Publisher not found").patchis never called and theexpect(patch).toHaveBeenCalledWith(...)assertion fails.Add the missing publisher to the
getmock:The same gap exists in the third test ("updates slug aliases", line 1501–1508) — add the identical
"publishers:org"branch there as well.Prompt To Fix With AI