MCPcopy Create free account
hub / github.com/pydio/cells / CreateCheck

Method CreateCheck

gateway/restv2/api-create.go:89–149  ·  view source on GitHub ↗

CreateCheck performs some validation checks before creating resources Api Endpoint: POST /node/create/precheck

(req *restful.Request, resp *restful.Response)

Source from the content-addressed store, hash-verified

87// CreateCheck performs some validation checks before creating resources
88// Api Endpoint: POST /node/create/precheck
89func (h *Handler) CreateCheck(req *restful.Request, resp *restful.Response) error {
90 input := &rest.CreateCheckRequest{}
91 if err := req.ReadEntity(input); err != nil {
92 return err
93 }
94 ctx := req.Request.Context()
95 findNext := input.GetFindAvailablePath()
96 output := &rest.CreateCheckResponse{}
97 pathRouter := h.TreeHandler.GetRouter()
98 uuidRouter := h.UuidClient(true)
99 for _, n := range input.GetInputs() {
100 var handler nodes.Handler
101 targetNode := &tree.Node{}
102 pa := n.GetLocator().GetPath()
103 var iNode *tree.Node
104 var er error
105
106 if pa != "" {
107 handler = pathRouter
108 targetNode.SetPath(pa)
109 iNode, er = nodes.FindNodeByInsensitiveName(ctx, pathRouter, targetNode)
110 } else {
111 handler = uuidRouter
112 targetNode.SetUuid(n.GetLocator().GetUuid())
113 rr, er1 := handler.ReadNode(ctx, &tree.ReadNodeRequest{Node: targetNode, StatFlags: []uint32{tree.StatFlagMetaMinimal}})
114 if er1 != nil {
115 er = er1
116 } else {
117 iNode = rr.GetNode()
118 }
119 }
120
121 cr := &rest.CheckResult{InputLocator: n.GetLocator(), Exists: false}
122 if er == nil {
123 cr.Exists = true
124 cr.Node = h.TreeNodeToNode(ctx, iNode)
125 if pa != "" && findNext {
126 // Find next available name
127 var childrenLocks []string
128 if parentResp, er := pathRouter.ReadNode(ctx, &tree.ReadNodeRequest{Node: &tree.Node{Path: path.Dir(targetNode.Path)}}); er == nil {
129 if cl, err := permissions.GetChildrenLocks(ctx, parentResp.GetNode()); err != nil {
130 return errors.WithMessage(err, "cannot find next available path (children locks)")
131 } else {
132 childrenLocks = append(childrenLocks, cl...)
133 }
134 }
135 if err := nodes.SuffixPathIfNecessary(ctx, pathRouter, targetNode, n.Type == tree.NodeType_COLLECTION, childrenLocks...); err == nil {
136 cr.NextPath = targetNode.GetPath()
137 } else {
138 return errors.WithMessage(err, "cannot find next available path")
139 }
140 }
141 output.Results = append(output.Results, cr)
142 } else if errors.Is(er, errors.NodeNotFound) {
143 output.Results = append(output.Results, cr)
144 } else {
145 return er
146 }

Callers

nothing calls this directly

Calls 15

GetFindAvailablePathMethod · 0.95
UuidClientMethod · 0.95
GetInputsMethod · 0.95
SetPathMethod · 0.95
SetUuidMethod · 0.95
ReadNodeMethod · 0.95
TreeNodeToNodeMethod · 0.95
GetPathMethod · 0.95
GetChildrenLocksFunction · 0.92
SuffixPathIfNecessaryFunction · 0.92
GetRouterMethod · 0.80

Tested by

no test coverage detected