Remove the in_namespace edge relation. A node now belongs to a namespace if that namespace has has_ownership on it. This simplifies the model: namespace membership is determined by the ownership chain rather than a separate relation type. Changes: - Remove RelInNamespace constant - Add Namespace fields to AddInput, UpdateInput, and ListFilter - Update Add() to resolve namespace from input and assign it as owner - Update List() to filter by namespace ownership instead of in_namespace edges - Update() can now transfer nodes between namespaces via ownership transfer - Remove in_namespace self-references from ensureNamespace/ensureGlobalNamespace The ownership chain now fully describes both permissions and namespace membership, reducing redundancy. All tests pass with the new model. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
84 lines
2.3 KiB
Go
84 lines
2.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"axolotl/models"
|
|
"axolotl/service"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var cDue, cContent, cType, cStatus, cPrio, cNamespace, cAssignee string
|
|
var cTags, cRels []string
|
|
|
|
var addCmd = &cobra.Command{
|
|
Use: "add <title>", Short: "Create a new node", Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
svc, err := getNodeService()
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
return
|
|
}
|
|
|
|
input := service.AddInput{
|
|
Title: args[0],
|
|
Content: cContent,
|
|
DueDate: cDue,
|
|
}
|
|
|
|
// --tag is an alias for --rel with no target.
|
|
for _, tag := range cTags {
|
|
input.Rels = append(input.Rels, service.RelInput{Type: models.RelType(tag), Target: ""})
|
|
}
|
|
|
|
// Shorthand flags expand to property rels or edge rels.
|
|
if cType != "" {
|
|
input.Rels = append(input.Rels, service.RelInput{Type: models.RelType("_type::" + cType), Target: ""})
|
|
}
|
|
if cStatus != "" {
|
|
input.Rels = append(input.Rels, service.RelInput{Type: models.RelType("_status::" + cStatus), Target: ""})
|
|
}
|
|
if cPrio != "" {
|
|
input.Rels = append(input.Rels, service.RelInput{Type: models.RelType("_prio::" + cPrio), Target: ""})
|
|
}
|
|
if cNamespace != "" {
|
|
input.Namespace = cNamespace
|
|
}
|
|
if cAssignee != "" {
|
|
input.Rels = append(input.Rels, service.RelInput{Type: models.RelAssignee, Target: cAssignee})
|
|
}
|
|
|
|
for _, r := range cRels {
|
|
ri, err := parseRelInput(r)
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
return
|
|
}
|
|
input.Rels = append(input.Rels, ri)
|
|
}
|
|
|
|
n, err := svc.Add(input)
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, "failed to create:", err)
|
|
return
|
|
}
|
|
|
|
PrintNode(cmd.OutOrStdout(), svc, n, jsonFlag)
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(addCmd)
|
|
f := addCmd.Flags()
|
|
f.StringVar(&cType, "type", "", "node type (issue, note, …)")
|
|
f.StringVar(&cStatus, "status", "", "initial status (open, done)")
|
|
f.StringVar(&cPrio, "prio", "", "priority (high, medium, low)")
|
|
f.StringVar(&cNamespace, "namespace", "", "namespace name or ID")
|
|
f.StringVar(&cAssignee, "assignee", "", "assignee username or ID")
|
|
f.StringVar(&cDue, "due", "", "due date")
|
|
f.StringVar(&cContent, "content", "", "node body")
|
|
f.StringArrayVar(&cTags, "tag", nil, "label tag (alias for --rel tagname)")
|
|
f.StringArrayVar(&cRels, "rel", nil, "relation (prefix::value or relname:target)")
|
|
}
|