mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-03 07:12:50 +00:00
fix(agents): let owners inherit tenant_id from auth context on create
Previously owners were required to explicitly provide tenant_id when creating agents. Now it falls back to the auth context tenant_id, matching the behavior of non-owner callers.
This commit is contained in:
1 parent
a9aedc843e
commit
bc958f6620
2 files changed
+12
-13
No files matched your search
@@ -84,19 +84,19 @@ func (m *AgentsMethods) handleCreate(ctx context.Context, client *gateway.Client
|
||||
ownerID = params.OwnerIDs[0]
|
||||
}
|
||||
|
||||
// Resolve tenant_id: cross-tenant callers must provide it; others inherit their own tenant.
|
||||
// Resolve tenant_id: explicit param for cross-tenant; otherwise inherit from connection scope.
|
||||
var tenantID uuid.UUID
|
||||
if client.IsOwner() {
|
||||
if params.TenantID == "" {
|
||||
client.SendResponse(protocol.NewErrorResponse(req.ID, protocol.ErrInvalidRequest, i18n.T(locale, i18n.MsgRequired, "tenant_id")))
|
||||
return
|
||||
if params.TenantID != "" {
|
||||
tid, err := uuid.Parse(params.TenantID)
|
||||
if err != nil {
|
||||
client.SendResponse(protocol.NewErrorResponse(req.ID, protocol.ErrInvalidRequest, i18n.T(locale, i18n.MsgInvalidID, "tenant_id")))
|
||||
return
|
||||
}
|
||||
tenantID = tid
|
||||
} else {
|
||||
tenantID = client.TenantID()
|
||||
}
|
||||
tid, err := uuid.Parse(params.TenantID)
|
||||
if err != nil {
|
||||
client.SendResponse(protocol.NewErrorResponse(req.ID, protocol.ErrInvalidRequest, i18n.T(locale, i18n.MsgInvalidID, "tenant_id")))
|
||||
return
|
||||
}
|
||||
tenantID = tid
|
||||
} else {
|
||||
tenantID = client.TenantID()
|
||||
}
|
||||
|
||||
@@ -120,11 +120,10 @@ func (h *AgentsHandler) handleCreate(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
req.OwnerID = userID
|
||||
|
||||
// Resolve tenant_id: cross-tenant callers must provide it; others inherit their own tenant.
|
||||
// Resolve tenant_id: explicit body field for cross-tenant; otherwise inherit from auth context.
|
||||
if store.IsOwnerRole(r.Context()) {
|
||||
if req.TenantID == uuid.Nil {
|
||||
writeJSON(w, http.StatusBadRequest, map[string]string{"error": i18n.T(locale, i18n.MsgRequired, "tenant_id")})
|
||||
return
|
||||
req.TenantID = store.TenantIDFromContext(r.Context())
|
||||
}
|
||||
} else {
|
||||
req.TenantID = store.TenantIDFromContext(r.Context())
|
||||
|
||||
Reference in new issue
Block a user