From 930e80d3638c74c754085d9a6a8043f451ddd829 Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 1 Jun 2020 19:36:40 +0100 Subject: [PATCH] script: Delete group sessions script and fix issue where loadSettings has been moved breaking deletePad (#3973) --- bin/deleteAllGroupSessions.js | 51 +++++++++++++++++++++++++++++++++++ bin/deletePad.js | 2 +- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 bin/deleteAllGroupSessions.js diff --git a/bin/deleteAllGroupSessions.js b/bin/deleteAllGroupSessions.js new file mode 100644 index 000000000..cda4a3a59 --- /dev/null +++ b/bin/deleteAllGroupSessions.js @@ -0,0 +1,51 @@ +/* +* A tool for deleting ALL GROUP sessions Etherpad user sessions from the CLI, +* because sometimes a brick is required to fix a face. +*/ + +const request = require('../src/node_modules/request'); +const settings = require(__dirname+'/../tests/container/loadSettings').loadSettings(); +const supertest = require(__dirname+'/../src/node_modules/supertest'); +const api = supertest('http://'+settings.ip+":"+settings.port); +const path = require('path'); +const fs = require('fs'); + +// get the API Key +var filePath = path.join(__dirname, '../APIKEY.txt'); +var apikey = fs.readFileSync(filePath, {encoding: 'utf-8'}); + +// Set apiVersion to base value, we change this later. +var apiVersion = 1; +var guids; + +// Update the apiVersion +api.get('/api/') +.expect(function(res){ + apiVersion = res.body.currentVersion; + if (!res.body.currentVersion) throw new Error("No version set in API"); + return; +}) +.then(function(){ + let guri = '/api/'+apiVersion+'/listAllGroups?apikey='+apikey; + api.get(guri) + .then(function(res){ + guids = res.body.data.groupIDs; + guids.forEach(function(groupID){ + let luri = '/api/'+apiVersion+'/listSessionsOfGroup?apikey='+apikey + "&groupID="+groupID; + api.get(luri) + .then(function(res){ + if(res.body.data){ + Object.keys(res.body.data).forEach(function(sessionID){ + if(sessionID){ + console.log("Deleting", sessionID); + let duri = '/api/'+apiVersion+'/deleteSession?apikey='+apikey + "&sessionID="+sessionID; + api.post(duri); // deletes + } + }) + }else{ + // no session in this group. + } + }) + }) + }) +}) diff --git a/bin/deletePad.js b/bin/deletePad.js index 7745e1767..2ce82f8a4 100644 --- a/bin/deletePad.js +++ b/bin/deletePad.js @@ -4,7 +4,7 @@ */ const request = require('../src/node_modules/request'); -const settings = require(__dirname+'/../tests/backend/loadSettings').loadSettings(); +const settings = require(__dirname+'/../tests/container/loadSettings').loadSettings(); const supertest = require(__dirname+'/../src/node_modules/supertest'); const api = supertest('http://'+settings.ip+":"+settings.port); const path = require('path');