diff --git a/package-lock.json b/package-lock.json index 23b76cd..bb04711 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "Caracal", "version": "1.0.0", "license": "GPL-3.0", "dependencies": { @@ -780,7 +781,6 @@ "dependencies": { "anymatch": "~3.1.1", "braces": "~3.0.2", - "fsevents": "~2.3.1", "glob-parent": "~5.1.0", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", @@ -2803,8 +2803,7 @@ "bson": "^1.1.4", "denque": "^1.4.1", "optional-require": "^1.0.2", - "safe-buffer": "^5.1.2", - "saslprep": "^1.0.0" + "safe-buffer": "^5.1.2" }, "engines": { "node": ">=4" diff --git a/routes.json.example b/routes.json.example index 2290e15..534364a 100644 --- a/routes.json.example +++ b/routes.json.example @@ -1,462 +1,1102 @@ [ { - "method":"static", - "use":"static" - },{ - "method":"static", - "use":"camicroscope" + "method": "static", + "use": "static" }, - { - "method":"use", + "method": "static", + "use": "camicroscope" + }, + { + "method": "use", "route": "/loader/", - "handlers":[ - {"function": "loginHandler", "args":[]}, - {"function":"permissionHandler", "args": [["Admin", "Editor"]]} + "access": { + "entity": "middleware", + "operation": "loader.login" + }, + "handlers": [ + { + "function": "loginHandler", + "args": [] + }, + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + } ] - },{ - "method":"use", + }, + { + "method": "use", "route": "/loader/slide/delete", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin"]]} + "access": { + "entity": "middleware", + "operation": "loader.slide.delete" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin"]] + } ] - },{ - "method":"use", + }, + { + "method": "use", "route": "/loader/", - "handlers":[ - {"function":"proxyHandler", "args": ["http://ca-load:4000/"]} + "access": { + "entity": "middleware", + "operation": "loader.proxyHandler" + }, + "handlers": [ + { + "function": "proxyHandler", + "args": ["http://ca-load:4000/"] + } ] - },{ - "method":"use", + }, + { + "method": "use", "route": "/googleAuth/", - "handlers":[ - {"function":"proxyHandler", "args": ["http://ca-load:4001/"]} + "access": { + "entity": "middleware", + "operation": "googleAuth" + }, + "handlers": [ + { + "function": "proxyHandler", + "args": ["http://ca-load:4001/"] + } ] }, - { - "method":"use", + "method": "use", "route": "/img/IIP/raw/", - "handlers":[ - {"function": "loginHandler", "args":[]}, - {"function":"iipHandler", "args": []} - ] - }, - - { - "route":"/data", - "method":"use", - "handlers":[ - {"function":"loginHandler", "args": []}, - {"function":"sanitizeBody", "args": []} - ] - }, - - { - "route":"/data/Slide/find", - "method":"get", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "slide"]}, - {"function":"filterHandler", "args": ["data", "userFilter", "filter"]} - ] - },{ - "route":"/data/Slide/post", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoAdd", "args": ["camic", "slide"]} - ] - },{ - "route":"/data/Slide/delete", - "method":"delete", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoFind", "args": ["camic", "slide"]}, - {"function":"editHandler", "args": ["data", "userFilter", "filter"]}, - {"function":"mongoDelete", "args": ["camic", "slide"]} - ] - },{ - "route":"/data/Slide/update", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoFind", "args": ["camic", "slide"]}, - {"function":"editHandler", "args": ["data", "userFilter", "filter"]}, - {"function":"mongoUpdate", "args": ["camic", "slide"]} - ] - }, - - { - "route":"/data/Request/find", - "method":"get", - "handlers":[ - {"function":"permissionHandler", "args": [["Editor", "Admin"]]}, - {"function":"mongoFind", "args": ["camic", "request"]} - ] - },{ - "route":"/data/Request/post", - "method":"post", - "handlers":[ - {"function":"mongoAdd", "args": ["camic", "request"]} - ] - },{ - "route":"/data/Request/delete", - "method":"delete", - "handlers":[ - {"function":"permissionHandler", "args": [["Editor", "Admin"]]}, - {"function":"mongoFind", "args": ["camic", "request"]}, - {"function":"editHandler", "args": ["data", "userFilter", "filter"]}, - {"function":"mongoDelete", "args": ["camic", "request"]} - ] - }, - - { - "route":"/data/Mark/find", - "method":"get", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "mark"]} - ] - },{ - "route":"/data/Mark/post", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoAdd", "args": ["camic", "mark"]} - ] - },{ - "route":"/data/Mark/delete", - "method":"delete", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "mark"]}, - {"function":"editHandler", "args": ["data"]}, - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoDelete", "args": ["camic", "mark"]} - ] - },{ - "route":"/data/Mark/update", - "method":"post", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "mark"]}, - {"function":"editHandler", "args": ["data"]}, - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoUpdate", "args": ["camic", "mark"]} - ] - },{ - "route":"/data/Mark/types", - "method":"get", - "handlers":[ - {"function":"mongoDistinct", "args": ["camic", "mark", "provenance.analysis"]} - ] - },{ - "route":"/data/Mark/multi", - "method":"post", - "handlers":[ - {"function":"markMulti", "args": []} - ] - },{ - "route":"/data/Mark/spatial", - "method":"get", - "handlers":[ - {"function":"markSpatial", "args": []} - ] - },{ - "route":"/data/Mark/findMarkTypes", - "method":"get", - "handlers":[ - {"function":"findMarkTypes", "args": []} - ] - },{ - "route":"/data/Presetlabels/add", - "method":"post", - "handlers":[ - {"function":"addPresetlabels", "args": []} - ] - },{ - "route":"/data/Presetlabels/update", - "method":"post", - "handlers":[ - {"function":"updatePresetlabels", "args": []} - ] - },{ - "route":"/data/Presetlabels/remove", - "method":"post", - "handlers":[ - {"function":"removePresetlabels", "args": []} - ] - }, - { - "route":"/data/Template/find", - "method":"get", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "template"]} - ] - },{ - "route":"/data/Template/post", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoAdd", "args": ["camic", "template"]} - ] - },{ - "route":"/data/Template/delete", - "method":"delete", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoDelete", "args": ["camic", "template"]} - ] - },{ - "route":"/data/Template/update", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin"]]}, - {"function":"mongoUpdate", "args": ["camic", "template"]} - ] - }, - - { - "route":"/data/Heatmap/find", - "method":"get", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "heatmap"]} - ] - },{ - "route":"/data/Heatmap/types", - "method":"get", - "handlers":[ - {"function":"heatmapTypes", "args": []} - ] - },{ - "route":"/data/Heatmap/post", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoAdd", "args": ["camic", "heatmap"]} - ] - },{ - "route":"/data/Heatmap/delete", - "method":"delete", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "heatmap"]}, - {"function":"editHandler", "args": ["data"]}, - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoDelete", "args": ["camic", "heatmap"]} - ] - },{ - "route":"/data/Heatmap/update", - "method":"post", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "heatmap"]}, - {"function":"editHandler", "args": ["data"]}, - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoUpdate", "args": ["camic", "heatmap"]} - ] - }, - - { - "route":"/data/HeatmapEdit/find", - "method":"get", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "heatmapEdit"]} - ] - },{ - "route":"/data/HeatmapEdit/post", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoAdd", "args": ["camic", "heatmapEdit"]} - ] - },{ - "route":"/data/HeatmapEdit/delete", - "method":"delete", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "heatmap"]}, - {"function":"editHandler", "args": ["data"]}, - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoDelete", "args": ["camic", "heatmapEdit"]} - ] - },{ - "route":"/data/HeatmapEdit/update", - "method":"post", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "heatmap"]}, - {"function":"editHandler", "args": ["data"]}, - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoUpdate", "args": ["camic", "heatmapEdit"]} - ] - }, - - { - "route":"/data/Log/find", - "method":"get", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "log"]} - ] - },{ - "route":"/data/Log/post", - "method":"post", - "handlers":[ - {"function":"mongoAdd", "args": ["camic", "log"]} - ] - },{ - "route":"/data/Log/delete", - "method":"delete", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoDelete", "args": ["camic", "log"]} - ] - },{ - "route":"/data/Log/update", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoUpdate", "args": ["camic", "log"]} - ] - }, - - { - "route":"/data/Freeform/find", - "method":"get", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "freeform"]} - ] - },{ - "route":"/data/Freeform/post", - "method":"post", - "handlers":[ - {"function":"mongoAdd", "args": ["camic", "freeform"]} - ] - },{ - "route":"/data/Freeform/delete", - "method":"delete", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoDelete", "args": ["camic", "freeform"]} - ] - },{ - "route":"/data/Freeform/update", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoUpdate", "args": ["camic", "freeform"]} - ] - }, - - { - "route":"/data/Configuration/find", - "method":"get", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "configuration"]} - ] - },{ - "route":"/data/Configuration/post", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoAdd", "args": ["camic", "configuration"]} - ] - },{ - "route":"/data/Configuration/delete", - "method":"delete", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoDelete", "args": ["camic", "configuration"]} - ] - },{ - "route":"/data/Configuration/update", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoUpdate", "args": ["camic", "configuration"]} - ] - },{ - "route":"/data/Collection/find", - "method":"get", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "collection"]} - ] - },{ - "route":"/data/Collection/post", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoAdd", "args": ["camic", "collection"]} - ] - },{ - "route":"/data/Collection/update", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoUpdate", "args": ["camic", "collection"]} - ] - },{ - "route":"/data/Collection/delete", - "method":"delete", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"mongoDelete", "args": ["camic", "collection"]} - ] - }, - - { - "route":"/data/User/find", - "method":"get", - "handlers":[ - {"function":"mongoFind", "args": ["camic", "user"]} - ] - },{ - "route":"/data/User/post", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin"]]}, - {"function":"mongoAdd", "args": ["camic", "user"]} - ] - },{ - "route":"/data/User/delete", - "method":"delete", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin"]]}, - {"function":"mongoDelete", "args": ["camic", "user"]} - ] - },{ - "route":"/data/User/update", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin"]]}, - {"function":"mongoUpdate", "args": ["camic", "user"]} - ] - },{ - "route":"/data/User/wcido", - "method":"get", - "handlers":[ - {"function":"wcido", "args": []} - ] - },{ - "route":"/workbench/uploadDataset", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"getDataset", "args": []} - ] - },{ - "route":"/workbench/trainModel", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"trainModel", "args": []} - ] - },{ - "route":"/workbench/deleteUserData", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"deleteDataset", "args": []} - ] - },{ - "route":"/workbench/modelDownload", - "method":"post", - "handlers":[ - {"function":"permissionHandler", "args": [["Admin", "Editor"]]}, - {"function":"sendTrainedModel", "args": []} + "access": { + "entity": "middleware", + "operation": "img.iip.raw" + }, + "handlers": [ + { + "function": "loginHandler", + "args": [] + }, + { + "function": "iipHandler", + "args": [] + } + ] + }, + { + "route": "/data", + "method": "use", + "access": { + "entity": "middleware", + "operation": "data" + }, + "handlers": [ + { + "function": "loginHandler", + "args": [] + }, + { + "function": "sanitizeBody", + "args": [] + } + ] + }, + { + "route": "/data/Slide/find", + "method": "get", + "access": { + "entity": "slide", + "operation": "read" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "slide"] + }, + { + "function": "filterHandler", + "args": ["data", "userFilter", "filter"] + } + ] + }, + { + "route": "/data/Slide/post", + "method": "post", + "access": { + "entity": "slide", + "operation": "create" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoAdd", + "args": ["camic", "slide"] + } + ] + }, + { + "route": "/data/Slide/delete", + "method": "delete", + "access": { + "entity": "slide", + "operation": "delete" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoFind", + "args": ["camic", "slide"] + }, + { + "function": "editHandler", + "args": ["data", "userFilter", "filter"] + }, + { + "function": "mongoDelete", + "args": ["camic", "slide"] + } + ] + }, + { + "route": "/data/Slide/update", + "method": "post", + "access": { + "entity": "slide", + "operation": "update" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoFind", + "args": ["camic", "slide"] + }, + { + "function": "editHandler", + "args": ["data", "userFilter", "filter"] + }, + { + "function": "mongoUpdate", + "args": ["camic", "slide"] + } + ] + }, + { + "route": "/data/Request/find", + "method": "get", + "access": { + "entity": "request", + "operation": "read" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Editor", "Admin"]] + }, + { + "function": "mongoFind", + "args": ["camic", "request"] + } + ] + }, + { + "route": "/data/Request/post", + "method": "post", + "access": { + "entity": "request", + "operation": "create" + }, + "handlers": [ + { + "function": "mongoAdd", + "args": ["camic", "request"] + } + ] + }, + { + "route": "/data/Request/delete", + "method": "delete", + "access": { + "entity": "request", + "operation": "delete" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Editor", "Admin"]] + }, + { + "function": "mongoFind", + "args": ["camic", "request"] + }, + { + "function": "editHandler", + "args": ["data", "userFilter", "filter"] + }, + { + "function": "mongoDelete", + "args": ["camic", "request"] + } + ] + }, + { + "route": "/data/Mark/find", + "method": "get", + "access": { + "entity": "mark", + "operation": "read" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "mark"] + } + ] + }, + { + "route": "/data/Mark/post", + "method": "post", + "access": { + "entity": "mark", + "operation": "create" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoAdd", + "args": ["camic", "mark"] + } + ] + }, + { + "route": "/data/Mark/delete", + "method": "delete", + "access": { + "entity": "mark", + "operation": "delete" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "mark"] + }, + { + "function": "editHandler", + "args": ["data"] + }, + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoDelete", + "args": ["camic", "mark"] + } + ] + }, + { + "route": "/data/Mark/update", + "method": "post", + "access": { + "entity": "mark", + "operation": "update" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "mark"] + }, + { + "function": "editHandler", + "args": ["data"] + }, + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoUpdate", + "args": ["camic", "mark"] + } + ] + }, + { + "route": "/data/Mark/types", + "method": "get", + "access": { + "entity": "mark", + "operation": "types" + }, + "handlers": [ + { + "function": "mongoDistinct", + "args": ["camic", "mark", "provenance.analysis"] + } + ] + }, + { + "route": "/data/Mark/multi", + "method": "post", + "access": { + "entity": "mark", + "operation": "multi" + }, + "handlers": [ + { + "function": "markMulti", + "args": [] + } + ] + }, + { + "route": "/data/Mark/spatial", + "method": "get", + "access": { + "entity": "mark", + "operation": "spatial" + }, + "handlers": [ + { + "function": "markSpatial", + "args": [] + } + ] + }, + { + "route": "/data/Mark/findMarkTypes", + "method": "get", + "access": { + "entity": "mark", + "operation": "findMarkTypes" + }, + "handlers": [ + { + "function": "findMarkTypes", + "args": [] + } + ] + }, + { + "route": "/data/Presetlabels/add", + "method": "post", + "access": { + "entity": "presetLabel", + "operation": "create" + }, + "handlers": [ + { + "function": "addPresetlabels", + "args": [] + } + ] + }, + { + "route": "/data/Presetlabels/update", + "method": "post", + "access": { + "entity": "presetLabel", + "operation": "update" + }, + "handlers": [ + { + "function": "updatePresetlabels", + "args": [] + } + ] + }, + { + "route": "/data/Presetlabels/remove", + "method": "post", + "access": { + "entity": "presetLabel", + "operation": "delete" + }, + "handlers": [ + { + "function": "removePresetlabels", + "args": [] + } + ] + }, + { + "route": "/data/Template/find", + "method": "get", + "access": { + "entity": "template", + "operation": "read" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "template"] + } + ] + }, + { + "route": "/data/Template/post", + "method": "post", + "access": { + "entity": "template", + "operation": "create" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoAdd", + "args": ["camic", "template"] + } + ] + }, + { + "route": "/data/Template/delete", + "method": "delete", + "access": { + "entity": "template", + "operation": "delete" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoDelete", + "args": ["camic", "template"] + } + ] + }, + { + "route": "/data/Template/update", + "method": "post", + "access": { + "entity": "template", + "operation": "update" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin"]] + }, + { + "function": "mongoUpdate", + "args": ["camic", "template"] + } + ] + }, + { + "route": "/data/Heatmap/find", + "method": "get", + "access": { + "entity": "heatmap", + "operation": "read" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "heatmap"] + } + ] + }, + { + "route": "/data/Heatmap/types", + "method": "get", + "access": { + "entity": "heatmap", + "operation": "types" + }, + "handlers": [ + { + "function": "heatmapTypes", + "args": [] + } + ] + }, + { + "route": "/data/Heatmap/post", + "method": "post", + "access": { + "entity": "heatmap", + "operation": "create" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoAdd", + "args": ["camic", "heatmap"] + } + ] + }, + { + "route": "/data/Heatmap/delete", + "method": "delete", + "access": { + "entity": "heatmap", + "operation": "delete" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "heatmap"] + }, + { + "function": "editHandler", + "args": ["data"] + }, + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoDelete", + "args": ["camic", "heatmap"] + } + ] + }, + { + "route": "/data/Heatmap/update", + "method": "post", + "access": { + "entity": "heatmap", + "operation": "update" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "heatmap"] + }, + { + "function": "editHandler", + "args": ["data"] + }, + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoUpdate", + "args": ["camic", "heatmap"] + } + ] + }, + { + "route": "/data/HeatmapEdit/find", + "method": "get", + "access": { + "entity": "heatmapEdit", + "operation": "read" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "heatmapEdit"] + } + ] + }, + { + "route": "/data/HeatmapEdit/post", + "method": "post", + "access": { + "entity": "heatmapEdit", + "operation": "create" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoAdd", + "args": ["camic", "heatmapEdit"] + } + ] + }, + { + "route": "/data/HeatmapEdit/delete", + "method": "delete", + "access": { + "entity": "heatmapEdit", + "operation": "delete" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "heatmap"] + }, + { + "function": "editHandler", + "args": ["data"] + }, + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoDelete", + "args": ["camic", "heatmapEdit"] + } + ] + }, + { + "route": "/data/HeatmapEdit/update", + "method": "post", + "access": { + "entity": "heatmapEdit", + "operation": "update" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "heatmap"] + }, + { + "function": "editHandler", + "args": ["data"] + }, + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoUpdate", + "args": ["camic", "heatmapEdit"] + } + ] + }, + { + "route": "/data/Log/find", + "method": "get", + "access": { + "entity": "log", + "operation": "read" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "log"] + } + ] + }, + { + "route": "/data/Log/post", + "method": "post", + "access": { + "entity": "log", + "operation": "create" + }, + "handlers": [ + { + "function": "mongoAdd", + "args": ["camic", "log"] + } + ] + }, + { + "route": "/data/Log/delete", + "method": "delete", + "access": { + "entity": "log", + "operation": "delete" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoDelete", + "args": ["camic", "log"] + } + ] + }, + { + "route": "/data/Log/update", + "method": "post", + "access": { + "entity": "log", + "operation": "update" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoUpdate", + "args": ["camic", "log"] + } + ] + }, + { + "route": "/data/Freeform/find", + "method": "get", + "access": { + "entity": "freeform", + "operation": "read" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "freeform"] + } + ] + }, + { + "route": "/data/Freeform/post", + "method": "post", + "access": { + "entity": "freeform", + "operation": "create" + }, + "handlers": [ + { + "function": "mongoAdd", + "args": ["camic", "freeform"] + } + ] + }, + { + "route": "/data/Freeform/delete", + "method": "delete", + "access": { + "entity": "freeform", + "operation": "delete" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoDelete", + "args": ["camic", "freeform"] + } + ] + }, + { + "route": "/data/Freeform/update", + "method": "post", + "access": { + "entity": "freeform", + "operation": "update" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoUpdate", + "args": ["camic", "freeform"] + } + ] + }, + { + "route": "/data/Configuration/find", + "method": "get", + "access": { + "entity": "configuration", + "operation": "read" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "configuration"] + } + ] + }, + { + "route": "/data/Configuration/post", + "method": "post", + "access": { + "entity": "configuration", + "operation": "create" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoAdd", + "args": ["camic", "configuration"] + } + ] + }, + { + "route": "/data/Configuration/delete", + "method": "delete", + "access": { + "entity": "configuration", + "operation": "delete" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoDelete", + "args": ["camic", "configuration"] + } + ] + }, + { + "route": "/data/Configuration/update", + "method": "post", + "access": { + "entity": "configuration", + "operation": "update" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoUpdate", + "args": ["camic", "configuration"] + } + ] + }, + { + "route": "/data/Collection/find", + "method": "get", + "access": { + "entity": "collection", + "operation": "read" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "collection"] + } + ] + }, + { + "route": "/data/Collection/post", + "method": "post", + "access": { + "entity": "collection", + "operation": "create" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoAdd", + "args": ["camic", "collection"] + } + ] + }, + { + "route": "/data/Collection/update", + "method": "post", + "access": { + "entity": "collection", + "operation": "update" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoUpdate", + "args": ["camic", "collection"] + } + ] + }, + { + "route": "/data/Collection/delete", + "method": "delete", + "access": { + "entity": "collection", + "operation": "delete" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "mongoDelete", + "args": ["camic", "collection"] + } + ] + }, + { + "route": "/data/User/find", + "method": "get", + "access": { + "entity": "user", + "operation": "read" + }, + "handlers": [ + { + "function": "mongoFind", + "args": ["camic", "user"] + } + ] + }, + { + "route": "/data/User/post", + "method": "post", + "access": { + "entity": "user", + "operation": "create" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin"]] + }, + { + "function": "mongoAdd", + "args": ["camic", "user"] + } + ] + }, + { + "route": "/data/User/delete", + "method": "delete", + "access": { + "entity": "user", + "operation": "delete" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin"]] + }, + { + "function": "mongoDelete", + "args": ["camic", "user"] + } + ] + }, + { + "route": "/data/User/update", + "method": "post", + "access": { + "entity": "user", + "operation": "update" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin"]] + }, + { + "function": "mongoUpdate", + "args": ["camic", "user"] + } + ] + }, + { + "route": "/data/User/wcido", + "method": "get", + "access": { + "entity": "user", + "operation": "wcido" + }, + "handlers": [ + { + "function": "wcido", + "args": [] + } + ] + }, + { + "route": "/workbench/uploadDataset", + "method": "post", + "access": { + "entity": "workbench", + "operation": "uploadDataset" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "getDataset", + "args": [] + } + ] + }, + { + "route": "/workbench/trainModel", + "method": "post", + "access": { + "entity": "workbench", + "operation": "trainModel" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "trainModel", + "args": [] + } + ] + }, + { + "route": "/workbench/deleteUserData", + "method": "post", + "access": { + "entity": "workbench", + "operation": "deleteUserData" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "deleteDataset", + "args": [] + } + ] + }, + { + "route": "/workbench/modelDownload", + "method": "post", + "access": { + "entity": "workbench", + "operation": "modelDownload" + }, + "handlers": [ + { + "function": "permissionHandler", + "args": [["Admin", "Editor"]] + }, + { + "function": "sendTrainedModel", + "args": [] + } ] } ] diff --git a/service/routes/entityAndOperations.js b/service/routes/entityAndOperations.js new file mode 100644 index 0000000..75fd26e --- /dev/null +++ b/service/routes/entityAndOperations.js @@ -0,0 +1,32 @@ +const fs = require('fs'); +const path = require('path'); +/** + * Returns all the entities defined in the application + * along with the operations. + */ +const listEntityAndOperations = async () => { + const rawData = await fs.readFileSync( + path.join(__dirname, '../../routes.json'), + ); + const data = JSON.parse(rawData); + + const entityList = {}; + + /** + * for each entry in routes.json, find all possible operations + */ + data.forEach((entry) => { + if (entry.access !== undefined) { + if (!Object.keys(entityList).includes(entry.access.entity)) { + entityList[entry.access.entity] = []; + } + + entityList[entry.access.entity].push(entry.access.operation); + } + }); + + console.log(JSON.stringify(entityList)); + return entityList; +}; +listEntityAndOperations(); +module.exports = { listEntityAndOperations }; diff --git a/validator.js b/service/routes/validator.js similarity index 59% rename from validator.js rename to service/routes/validator.js index 763e85d..ca1286c 100644 --- a/validator.js +++ b/service/routes/validator.js @@ -1,9 +1,10 @@ -const Ajv = require("ajv"); +const Ajv = require('ajv'); +const path = require('path'); const ajv = new Ajv(); -require("ajv-keywords")(ajv); +require('ajv-keywords')(ajv); /** loading dataset */ -const routeDefinitions = require("./routes.json"); +const routeDefinitions = require('../../routes.json'); /** * Quick information about schema declaration @@ -18,21 +19,21 @@ const routeDefinitions = require("./routes.json"); /** declare schema */ const schema = { - type: "array", + type: 'array', items: { - type: "object", + type: 'object', oneOf: [ /** static blocks */ { properties: { method: { - const: "static", + const: 'static', }, use: { - type: "string", + type: 'string', }, }, - required: ["method", "use"], + required: ['method', 'use'], }, /** use middleware */ @@ -40,36 +41,49 @@ const schema = { properties: { /** the type of requests which are accepted by the entry */ method: { - enum: ["use", "get", "post", "delete"], + enum: ['use', 'get', 'post', 'delete'], }, /** the URL fragment on which the route is attached */ route: { - type: "string", + type: 'string', + }, + + /** information related to access rights of the item */ + access: { + type: 'object', + properties: { + /** the category to which the operation belongs */ + entity: { type: 'string' }, + + /** slug to identify the operation */ + operation: { type: 'string' }, + }, + required: ['entity', 'operation'], }, /** list of handlers / middleware layers attached to given route */ handlers: { /** each route has multiple handles attached to it, therefore array */ - type: "array", + type: 'array', items: { - type: "object", + type: 'object', properties: { /** the name of the function that is attached from the codebase to the route */ - function: {type: "string"}, + function: { type: 'string' }, /** array of arguments that are passed into the above specified function */ args: { - type: "array", + type: 'array', }, }, - required: ["function", "args"], + required: ['function', 'args'], }, }, }, - required: ["method", "route", "handlers"], + required: ['method', 'route', 'handlers', 'access'], }, ], }, @@ -79,4 +93,4 @@ const schema = { const validate = ajv.compile(schema); const valid = validate(routeDefinitions); -valid === true ? console.log("ok") : console.log(validate.errors); +valid === true ? console.log('ok') : console.log(validate.errors);