fix: bootstrap namespace self-ref and write access when created explicitly via --type namespace

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-01 12:55:21 +02:00
parent 6288879468
commit 9e5194893e
2 changed files with 68 additions and 0 deletions

View File

@@ -328,6 +328,30 @@ func (s *nodeServiceImpl) Add(input AddInput) (*models.Node, error) {
}
}
// Namespace bootstrap: when creating a namespace node directly, apply the
// same setup as ensureNamespace — self in_namespace and creator write access.
if tmp.GetProperty("type") == "namespace" {
if !hasNamespace {
// Replace the default namespace rel (user's ns) with self-reference.
userNsID, _ := s.resolveIDByNameAndType(st, s.userID, "namespace")
if userNsID != "" {
if err := st.RemoveRel(id, string(models.RelInNamespace), userNsID); err != nil {
return err
}
}
if err := st.AddRel(id, string(models.RelInNamespace), id); err != nil {
return err
}
}
creatorID, err := s.resolveUserRef(st, s.userID)
if err != nil {
return err
}
if err := st.AddRel(creatorID, string(models.RelHasWriteAccess), id); err != nil {
return err
}
}
return nil
})
if err != nil {