| 95 | } |
| 96 | |
| 97 | func CreateNodeUpload(u *user.User, params map[string]string, files file.FormFiles) (node *Node, err error) { |
| 98 | // if copying node or creating subset node from parent, check if user has rights to the original node |
| 99 | |
| 100 | if copy_data_id, hasCopyData := params["copy_data"]; hasCopyData { |
| 101 | var copy_data_node *Node |
| 102 | copy_data_node, err = Load(copy_data_id) |
| 103 | if err != nil { |
| 104 | return |
| 105 | } |
| 106 | |
| 107 | rights := copy_data_node.Acl.Check(u.Uuid) |
| 108 | if copy_data_node.Acl.Owner != u.Uuid && u.Admin == false && copy_data_node.Acl.Owner != "public" && rights["read"] == false { |
| 109 | logger.Error("err@CreateNodeUpload: (Authenticate) id=" + copy_data_id + ": " + e.UnAuth) |
| 110 | //responder.RespondWithError(ctx, http.StatusUnauthorized, e.UnAuth) |
| 111 | //err = request.AuthError(err, ctx) |
| 112 | err = fmt.Errorf("copy_data_node auth error") |
| 113 | return |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | if parentNode_id, hasParentNode := params["parent_node"]; hasParentNode { |
| 118 | var parentNode *Node |
| 119 | parentNode, err = Load(parentNode_id) |
| 120 | if err != nil { |
| 121 | return |
| 122 | } |
| 123 | |
| 124 | rights := parentNode.Acl.Check(u.Uuid) |
| 125 | if parentNode.Acl.Owner != u.Uuid && u.Admin == false && parentNode.Acl.Owner != "public" && rights["read"] == false { |
| 126 | logger.Error("err@CreateNodeUpload: (Authenticate) id=" + parentNode_id + ": " + e.UnAuth) |
| 127 | //responder.RespondWithError(ctx, http.StatusUnauthorized, e.UnAuth) |
| 128 | //err = request.AuthError(err, ctx) |
| 129 | err = fmt.Errorf("parentNode auth error") |
| 130 | return |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | node = New() |
| 135 | node.Type = "basic" |
| 136 | |
| 137 | node.Acl.SetOwner(u.Uuid) |
| 138 | node.Acl.Set(u.Uuid, acl.Rights{"read": true, "write": true, "delete": true}) |
| 139 | |
| 140 | err = node.Mkdir() |
| 141 | if err != nil { |
| 142 | return |
| 143 | } |
| 144 | |
| 145 | // update saves node |
| 146 | err = node.Update(params, files, false) |
| 147 | if err != nil { |
| 148 | err = fmt.Errorf("(node.Update) %s", err.Error()) |
| 149 | node.Rmdir() |
| 150 | } |
| 151 | |
| 152 | return |
| 153 | } |
| 154 | |