Action move user org unit#65
Conversation
…ction is outside our recommended scoped in documentation.
WalkthroughA new idempotent action Changes
Sequence DiagramsequenceDiagram
participant Caller
participant Connector as GoogleWorkspace<br/>Connector
participant API as Directory API
Caller->>Connector: moveAccountToOrgUnit(user_id, org_unit_path)
Connector->>Connector: Validate inputs (non-empty, leading slash)
Connector->>API: GET user details (current OrgUnitPath)
API-->>Connector: User data with current OrgUnitPath
Connector->>Connector: Check idempotency<br/>(current == target?)
alt Paths Match (Idempotent)
Connector-->>Caller: Success (no API update needed)
else Paths Differ
Connector->>API: PUT user with new OrgUnitPath
API-->>Connector: Updated user data
Connector-->>Caller: Success with previous & new paths
end
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@pkg/connector/actions.go`:
- Around line 405-419: The validation currently rejects an empty org_unit_path
but PR intent is to treat empty (after trimming) as the root path; in the
orgUnitPath handling in actions.go (variables userId, orgUnitPath from
userIdField.StringValue and orgUnitPathField.StringValue) change the logic so
that after trimming whitespace you: 1) keep rejecting whitespace-only inputs, 2)
if orgUnitPath == "" set orgUnitPath = "/" instead of returning an error, and 3)
retain the existing HasPrefix check to ensure non-root values start with "/"
(e.g., ensure "/" is accepted and paths like "/Sales" continue to be validated).
Ensure tests updated accordingly.
| userId := strings.TrimSpace(userIdField.StringValue) | ||
| orgUnitPath := strings.TrimSpace(orgUnitPathField.StringValue) | ||
|
|
||
| // Validate non-empty | ||
| if userId == "" { | ||
| return nil, nil, fmt.Errorf("user_id must be non-empty") | ||
| } | ||
| if orgUnitPath == "" { | ||
| return nil, nil, fmt.Errorf("org_unit_path must be non-empty") | ||
| } | ||
|
|
||
| // Ensure org_unit_path starts with "/" | ||
| if !strings.HasPrefix(orgUnitPath, "/") { | ||
| return nil, nil, fmt.Errorf("org_unit_path must start with '/' (e.g., '/Sales' or '/Engineering/Backend')") | ||
| } |
There was a problem hiding this comment.
Honor “empty org_unit_path = root” if that’s a supported input.
PR objectives state empty string should map to root, but the current validation rejects it. If that behavior is intended, map empty to “/” (while keeping whitespace-only invalid) and update the corresponding tests.
🛠️ Proposed fix
- orgUnitPath := strings.TrimSpace(orgUnitPathField.StringValue)
+ rawOrgUnitPath := orgUnitPathField.StringValue
+ orgUnitPath := strings.TrimSpace(rawOrgUnitPath)
// Validate non-empty
if userId == "" {
return nil, nil, fmt.Errorf("user_id must be non-empty")
}
- if orgUnitPath == "" {
- return nil, nil, fmt.Errorf("org_unit_path must be non-empty")
- }
+ if rawOrgUnitPath == "" {
+ orgUnitPath = "/"
+ } else if orgUnitPath == "" {
+ return nil, nil, fmt.Errorf("org_unit_path must be non-empty")
+ }🤖 Prompt for AI Agents
In `@pkg/connector/actions.go` around lines 405 - 419, The validation currently
rejects an empty org_unit_path but PR intent is to treat empty (after trimming)
as the root path; in the orgUnitPath handling in actions.go (variables userId,
orgUnitPath from userIdField.StringValue and orgUnitPathField.StringValue)
change the logic so that after trimming whitespace you: 1) keep rejecting
whitespace-only inputs, 2) if orgUnitPath == "" set orgUnitPath = "/" instead of
returning an error, and 3) retain the existing HasPrefix check to ensure
non-root values start with "/" (e.g., ensure "/" is accepted and paths like
"/Sales" continue to be validated). Ensure tests updated accordingly.
Summary
Adds a new action
move_account_to_org_unitthat allows moving Google Workspace accounts to different organizational units.Changes
New Action:
move_account_to_org_unitImplements a new connector action to move accounts between organizational units in Google Workspace.
Parameters:
user_id(required): ID of the user resource to moveorg_unit_path(required): Full path of the organizational unit (e.g.,/Salesor/Engineering/Backend). Use/for root.Returns:
success: Whether the account was moved successfullyprevious_org_unit_path: Account's previous organizational unit pathnew_org_unit_path: Account's new organizational unit pathKey Features:
/and parameters are non-empty/as equivalent root pathsAPI Scope Required:
https://www.googleapis.com/auth/admin.directory.userImplementation Details:
ACTION_TYPE_ACCOUNTdisable_user/enable_useractionsForceSendFieldsto ensureOrgUnitPathis sent even when emptyTesting