Fix this issue When I used the tool to import and export _users, the copy was not made…
- User
Fix this issue When I used the tool to import and export _users, the copy was not made as "Staged" but as "Invited," which triggered an email to everyone in the test environment. and add an additional option to import the users as disabled except admins
Assistant
Let me explore how
_usersare handled in the import flow.Assistant
Now let me read the specific user import code.
Assistant
Now let me check the ImportOptions struct and import command flags.
Assistant
Let me check the User type and any related API endpoints.
Assistant
Let me check the import command flags and migrate command to understand where to add new options.
Assistant
Let me check for any user fixtures or tests to understand the user data structure.
Assistant
There's an OpenAPI spec. Let me check user endpoints there.
Assistant
The
notifyquery param controls email sending. Let me also check the PATCH endpoint for thedisabledstatus.Assistant
Let me check the backup.json to understand user data structure.
Assistant
Now I have all the context needed. Let me look at the import/migrate command variable declarations.
Assistant
Let me check how
importUsersis called and ifoptsis accessible.Assistant
Good,
optsis already available inimportOtherResources. Now I have everything needed. Let me implement all the changes.Assistant
Now I'll make all the changes:
Assistant
Now update
Optionsstruct andimportUsersin the import module:Assistant
Now update the
importUserscall to passopts.UsersAsDisabled:Assistant
Now update the
importUsersfunction itself:Assistant
Now add the flag to the import command:
Assistant
Now add the flag registration:
Assistant
Now do the same for migrate command:
Assistant
Now let me check the migrate module's Options struct:
Assistant
The migrate module also has its own user import. Let me check its
importToTargetsignature and how opts flows:Assistant
importToTargetdoesn't takeopts. Let me update it to passusersAsDisabled:Assistant
Now add the disable logic after the user create in migrate:
Assistant
Now I need to add the
isAdminUserhelper in the migrate package. Let me check if it can just be imported from import_module or if I need to add it locally:Assistant
It's unexported. I'll either export it or add it inline in migrate. The function is tiny - let me add it locally in migrate.go:
Assistant
Now add
UsersAsDisabledto the migrateOptionsstruct and the migrate command:Assistant
Now update the migrate command to add the flag:
Assistant
Now build to verify everything compiles:
Assistant
Clean build. Let me verify the changes look right:
Assistant
Tests call
importToTargetdirectly. Let me fix those:Assistant
All 492 tests pass. Summary of changes:
Fix (staged, no email):
InviteUsernow always appends?notify=falseto the/users/inviteURL. Users are created asSTAGEDinstead ofINVITED— no emails sent.New flag
--users-as-disabledon bothimportandmigrate: after staging a new non-admin user (type != "ADMIN"), callsPATCH /users/{email}with{"status": "DISABLED"}. Admin users skip the disable step.Changed files:
internal/api/requests.go—InviteUsergets?notify=false; newDisableUsermethodinternal/modules/import_module/import.go—Options.UsersAsDisabled;isAdminUserhelper;importUserscalls disable on new non-adminsinternal/modules/migrate/migrate.go— sameOptions.UsersAsDisabled;isAdminUserhelper;importToTargetgetsusersAsDisabledparam; disable called after createinternal/commands/import.go+migrate.go—--users-as-disabledflag wired through
- User
open as a new PR
Assistant
Using the finishing-a-development-branch skill to complete this work.
Tests already passed (492/492). Let me detect the environment.
Assistant
On
mainwith no new commits yet — changes are uncommitted. Let me check the diff:Assistant
The
examples/ado-blueprint-sync/deletions are pre-existing staged files unrelated to this fix. I'll create a branch and commit only the relevant files.Assistant
Wait — the commit accidentally included the
ado-blueprint-syncfiles that were pre-staged. Let me fix that:Assistant
The pre-staged files are gone from the index. Now commit only our changes:
Assistant
PR open: https://github.com/port-experimental/port-cli/pull/84
The 12 uncommitted changes warning is the pre-existing untracked files (
.beads/,.claude/,CLAUDE.md, etc.) — unrelated to this PR.- User
For the users, instead of inviting them we should be using this https://docs.port.io/api-reference/create-multiple-entities and creating the users as staged by default, and the --users-as-disabled flag should create them as disabled. This is only for creation. In future imports if the user exists then it should be as it is in the source
Assistant
Let me check the entity creation API and understand the
_userblueprint entity structure.Assistant
Now let me look at the existing entity API client and the
_userentity structure:Assistant
Let me check what's currently used and how the entity update API works, then plan the rewrite:
Assistant
Let me look at the full migrate user section and the errgroup pattern:
Assistant
Let me check if tests reference these methods directly:
Assistant
Good — no tests reference those. Now I'll implement the full rewrite. Let me check
stringsis imported inimport.go:Assistant
Both already import
strings. Now I'll make all the changes:Assistant
Now rewrite
importUsersin the import module:Assistant
Now rewrite the migrate module's user section:
Assistant
Now replace the user import block in migrate's
importToTarget:Assistant
I need to export
userToEntityand adduserStatusForCreateto migrate. Let me check imports first:Assistant
Good —
import_moduleis already imported. Now exportuserToEntityand adduserStatusForCreateto migrate:Assistant
Now add
userStatusForCreateto migrate.go:Assistant
Now build to catch any compilation errors:
Assistant
All 492 tests pass. Let me update the PR:
Assistant
PR updated: https://github.com/port-experimental/port-cli/pull/84
Key changes vs the previous approach:
POST /blueprints/_user/entities/bulk?upsert=falsereplacesPOST /users/invite— creates users as_userentities, STAGED by default, no emails--users-as-disabledsetsstatus: "DISABLED"on non-admin users at creation time (in the entity payload), not a separate PATCH call- Conflict (existing user): calls
PUT /blueprints/_user/entities/{email}with source data and no status override — target org's current state is preserved - Batched at 20 per request per the API limit
- User
For conflict I want to still use the POST and not the PUT
Assistant
Small change — for conflicts, re-call the bulk POST with
upsert=trueinstead of switching to PUT. Let me update the API method and both call sites.Assistant
Now update
importUsersin import_module to use POST upsert for conflicts instead of PUT:Assistant
Now update migrate to use POST upsert instead of
UpdateEntity:Assistant
Done. The conflict flow now uses
POST /blueprints/_user/entities/bulk?upsert=truethroughout — no PUT anywhere. The pattern is:- New users:
POST bulk?upsert=falsewith STAGED/DISABLED status - 409 conflicts:
POST bulk?upsert=truewith source data as-is (no status override) - Known updates (migrate): same
POST bulk?upsert=truewith source data, directly
- New users: