summaryrefslogtreecommitdiffstats
path: root/server/lib
diff options
context:
space:
mode:
authorJannik Schönartz2020-06-02 18:33:13 +0200
committerJannik Schönartz2020-06-02 18:33:13 +0200
commit79f09bacdc4bd515e135060226888b02e285d146 (patch)
tree0e6dd40e90834c7aa2ae8e1e2141559486c01588 /server/lib
parent[webapp] add no permission snackbar to 403 responses (diff)
downloadbas-79f09bacdc4bd515e135060226888b02e285d146.tar.gz
bas-79f09bacdc4bd515e135060226888b02e285d146.tar.xz
bas-79f09bacdc4bd515e135060226888b02e285d146.zip
[users/ipxe/backends] PM integration
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/httpresponse.js13
-rw-r--r--server/lib/permissions/modules/backends.json12
-rw-r--r--server/lib/permissions/modules/ipxe.json12
-rw-r--r--server/lib/permissions/modules/users.json12
4 files changed, 49 insertions, 0 deletions
diff --git a/server/lib/httpresponse.js b/server/lib/httpresponse.js
index cb4b216..c402e39 100644
--- a/server/lib/httpresponse.js
+++ b/server/lib/httpresponse.js
@@ -27,12 +27,25 @@ HttpResponse.successBatch = (action, type, count) => {
}
// ############################################################################
+// ############################## WARNING #####################################
+
+HttpResponse.warningBatch = (action, type, successfull, count) => {
+ const failed = count - successfull
+ let tmpType = type
+ if (failed > 1) tmpType += 's'
+ if (Array.isArray(type)) type = type[successfull === 1 ? 0 : 1]
+ else if (successfull !== 1) type += 's'
+ return new HttpResponse(200, action.toUpperCase() + '_MULTIPLE', `Warning: ${action} ${successfull}/${count} ${type}. ${failed} ${tmpType} failed.`, { successfull, count })
+}
+
+// ############################################################################
// ############################### ERROR ######################################
// General
HttpResponse.notFound = (id) => new HttpResponse(404, 'NOT_FOUND', 'ID ' + id + ' does not exist.')
HttpResponse.invalidId = (zeroAllowed) => new HttpResponse(400, 'INVALID_ID', 'ID has to be an integer' + (zeroAllowed ? '' : ' greater than 0') + '.')
HttpResponse.invalidBodyValue = (key, rule) => new HttpResponse(400, 'BAD_REQUEST', 'JSON body value for key "' + key + '" has to be ' + rule + '.')
+HttpResponse.noPermission = (id, permission) => new HttpResponse(403, 'NO_PERMISSION', 'Missing permission ' + permission + ' for object ' + id + '.')
// Authentication
HttpResponse.invalidToken = () => new HttpResponse(401, 'INVALID_TOKEN', 'The provided token is invalid.')
diff --git a/server/lib/permissions/modules/backends.json b/server/lib/permissions/modules/backends.json
new file mode 100644
index 0000000..5143ec3
--- /dev/null
+++ b/server/lib/permissions/modules/backends.json
@@ -0,0 +1,12 @@
+[
+ {
+ "name": "view",
+ "description": "View all backends including their informations.",
+ "groupdependent": false
+ },
+ {
+ "name": "edit",
+ "description": "Edit and delete backends.",
+ "groupdependent": false
+ }
+] \ No newline at end of file
diff --git a/server/lib/permissions/modules/ipxe.json b/server/lib/permissions/modules/ipxe.json
new file mode 100644
index 0000000..2375cbf
--- /dev/null
+++ b/server/lib/permissions/modules/ipxe.json
@@ -0,0 +1,12 @@
+[
+ {
+ "name": "view",
+ "description": "View all information for building ipxe.",
+ "groupdependent": false
+ },
+ {
+ "name": "edit",
+ "description": "Edit informations, configs, scripts for building ipxe.",
+ "groupdependent": false
+ }
+] \ No newline at end of file
diff --git a/server/lib/permissions/modules/users.json b/server/lib/permissions/modules/users.json
new file mode 100644
index 0000000..1818e7f
--- /dev/null
+++ b/server/lib/permissions/modules/users.json
@@ -0,0 +1,12 @@
+[
+ {
+ "name": "view",
+ "description": "View all users including their informations.",
+ "groupdependent": false
+ },
+ {
+ "name": "edit",
+ "description": "Edit and delete users.",
+ "groupdependent": false
+ }
+] \ No newline at end of file