{"modulePath":"github.com/devoid/shock","version":"v0.0.0-20130710231832-27e80109ea27","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package acl\n\n## Variables\n\n```go\nvar Controller goweb.ControllerFunc = func(cx *goweb.Context) {\n\trequest.Log(cx.Request)\n\tu, err := request.Authenticate(cx.Request)\n\tif err != nil \u0026\u0026 err.Error() != e.NoAuth {\n\t\trequest.AuthError(err, cx)\n\t\treturn\n\t}\n\n\tif u == nil {\n\t\tcx.RespondWithErrorMessage(e.NoAuth, http.StatusUnauthorized)\n\t\treturn\n\t}\n\n\tid := cx.PathParams[\"nid\"]\n\tn, err := node.Load(id, u.Uuid)\n\tif err != nil {\n\t\tif err.Error() == e.UnAuth {\n\t\t\tcx.RespondWithError(http.StatusUnauthorized)\n\t\t\treturn\n\t\t} else if err.Error() == e.MongoDocNotFound {\n\t\t\tcx.RespondWithNotFound()\n\t\t\treturn\n\t\t} else {\n\n\t\t\tlogger.Error(\"Err@node_Read:LoadNode: \" + err.Error())\n\t\t\tcx.RespondWithError(http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\t}\n\n\trights := n.Acl.Check(u.Uuid)\n\tif cx.Request.Method != \"GET\" {\n\t\tids, err := parseAclRequest(cx)\n\t\tif err != nil {\n\t\t\tcx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)\n\t\t\treturn\n\t\t}\n\t\tif (cx.Request.Method == \"POST\" || cx.Request.Method == \"PUT\") \u0026\u0026 (u.Uuid == n.Acl.Owner || rights[\"write\"]) {\n\t\t\tfor k, v := range ids {\n\t\t\t\tfor _, i := range v {\n\t\t\t\t\tn.Acl.Set(i, map[string]bool{k: true})\n\t\t\t\t}\n\t\t\t}\n\t\t\tn.Save()\n\t\t} else if cx.Request.Method == \"DELETE\" \u0026\u0026 (u.Uuid == n.Acl.Owner || rights[\"delete\"]) {\n\t\t\tfor k, v := range ids {\n\t\t\t\tfor _, i := range v {\n\t\t\t\t\tn.Acl.UnSet(i, map[string]bool{k: true})\n\t\t\t\t}\n\t\t\t}\n\t\t\tn.Save()\n\t\t} else {\n\t\t\tcx.RespondWithError(http.StatusUnauthorized)\n\t\t\treturn\n\t\t}\n\t}\n\n\tif u.Uuid == n.Acl.Owner || rights[\"read\"] {\n\t\tcx.RespondWithData(n.Acl)\n\t} else {\n\t\tcx.RespondWithError(http.StatusUnauthorized)\n\t\treturn\n\t}\n\treturn\n}\n```\nGET, POST, PUT, DELETE: /node/{nid}/acl/\n\n```go\nvar ControllerTyped goweb.ControllerFunc = func(cx *goweb.Context) {\n\trequest.Log(cx.Request)\n\tu, err := request.Authenticate(cx.Request)\n\tif err != nil \u0026\u0026 err.Error() != e.NoAuth {\n\t\trequest.AuthError(err, cx)\n\t\treturn\n\t}\n\n\tif u == nil {\n\t\tcx.RespondWithErrorMessage(e.NoAuth, http.StatusUnauthorized)\n\t\treturn\n\t}\n\n\trtype := cx.PathParams[\"type\"]\n\tif !validAclTypes[rtype] {\n\t\tcx.RespondWithErrorMessage(\"Invalid acl type\", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tid := cx.PathParams[\"nid\"]\n\tn, err := node.Load(id, u.Uuid)\n\tif err != nil {\n\t\tif err.Error() == e.UnAuth {\n\t\t\tcx.RespondWithError(http.StatusUnauthorized)\n\t\t\treturn\n\t\t} else if err.Error() == e.MongoDocNotFound {\n\t\t\tcx.RespondWithNotFound()\n\t\t\treturn\n\t\t} else {\n\n\t\t\tlogger.Error(\"Err@node_Read:LoadNode: \" + err.Error())\n\t\t\tcx.RespondWithError(http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\t}\n\n\trights := n.Acl.Check(u.Uuid)\n\tif cx.Request.Method != \"GET\" {\n\t\tids, err := parseAclRequestTyped(cx)\n\t\tif err != nil {\n\t\t\tcx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)\n\t\t\treturn\n\t\t}\n\t\tif (cx.Request.Method == \"POST\" || cx.Request.Method == \"PUT\") \u0026\u0026 (u.Uuid == n.Acl.Owner || rights[\"write\"]) {\n\t\t\tif rtype == \"owner\" {\n\t\t\t\tif u.Uuid == n.Acl.Owner {\n\t\t\t\t\tif len(ids) == 1 {\n\t\t\t\t\t\tn.Acl.SetOwner(ids[0])\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcx.RespondWithErrorMessage(\"Too many users. Nodes may have only one owner.\", http.StatusBadRequest)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tcx.RespondWithErrorMessage(\"Only owner can change ownership of Node.\", http.StatusBadRequest)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor _, i := range ids {\n\t\t\t\t\tn.Acl.Set(i, map[string]bool{rtype: true})\n\t\t\t\t}\n\t\t\t}\n\t\t\tn.Save()\n\t\t} else if cx.Request.Method == \"DELETE\" \u0026\u0026 (u.Uuid == n.Acl.Owner || rights[\"delete\"]) {\n\t\t\tfor _, i := range ids {\n\t\t\t\tn.Acl.UnSet(i, map[string]bool{rtype: true})\n\t\t\t}\n\t\t\tn.Save()\n\t\t} else {\n\t\t\tcx.RespondWithError(http.StatusUnauthorized)\n\t\t\treturn\n\t\t}\n\t}\n\n\tif u.Uuid == n.Acl.Owner || rights[\"read\"] {\n\t\tswitch rtype {\n\t\tcase \"read\":\n\t\t\tcx.RespondWithData(map[string][]string{\"read\": n.Acl.Read})\n\t\tcase \"write\":\n\t\t\tcx.RespondWithData(map[string][]string{\"write\": n.Acl.Write})\n\t\tcase \"delete\":\n\t\t\tcx.RespondWithData(map[string][]string{\"delete\": n.Acl.Delete})\n\t\tcase \"owner\":\n\t\t\tcx.RespondWithData(map[string]string{\"owner\": n.Acl.Owner})\n\t\t}\n\t} else {\n\t\tcx.RespondWithError(http.StatusUnauthorized)\n\t\treturn\n\t}\n\treturn\n}\n```\nGET, POST, PUT, DELETE: /node/{nid}/acl/{type}\n\n","path":"github.com/devoid/shock/shock-server/controller/node/acl","name":"acl","synopsis":"","isRedistributable":true}
