Skip to content

Commit cb5fd20

Browse files
author
Dan Cristian, Rotaru
authored
Merge pull request #100 from e-ucm/fixremove
Added fix in delete data sessions uris
2 parents de235d1 + fa3d831 commit cb5fd20

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

a-backend-roles.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ exports.app = {
5959
{
6060
roles: 'teacher',
6161
allows: [
62+
{
63+
resources: [
64+
'/sessions/data/:sessionId',
65+
'/sessions/data/:sessionId/:user'
66+
],
67+
permissions: [
68+
'delete'
69+
]
70+
},
6271
{
6372
resources: [
6473
'/analysis/:id',

lib/sessions.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -399,40 +399,41 @@ module.exports = (function () {
399399
return Q.all(promises);
400400
};
401401

402-
var getAnalysisIndicesReplace = function(versionId, sessionId, user) {
402+
var getAnalysisIndicesReplace = function(defaultConfig, versionId, sessionId, user) {
403403
return analysis.findById(versionId, true).then(function(result) {
404404
if (!result) {
405-
throw {
406-
message: 'versionId not found',
407-
status: 404
408-
};
405+
// Use the default analysis files
406+
result = {};
407+
result.indicesPath = defaultConfig.analysisFolder + '/indices.json';
409408
}
410409
var data = fs.readFileSync(result.indicesPath, 'utf8');
411410
var returnObject = {indices: []};
412411
var obj = JSON.parse(data);
413-
obj.indices.forEach(function(indice) {
414-
returnObject.indices.push(indice.replace(obj.sessionKey, sessionId));
415-
});
416-
if (user && obj.userKey && obj.query) {
417-
if (obj.userKey) {
418-
var string = JSON.stringify(obj.query);
419-
var stringWithUser = string.replace(obj.userKey, user);
420-
returnObject.query = JSON.parse(stringWithUser);
412+
if (obj.indices) {
413+
obj.indices.forEach(function(indice) {
414+
returnObject.indices.push(indice.replace(obj.sessionKey, sessionId));
415+
});
416+
if (user && obj.userKey && obj.query) {
417+
if (obj.userKey) {
418+
var string = JSON.stringify(obj.query);
419+
var stringWithUser = string.replace(obj.userKey, user);
420+
returnObject.query = JSON.parse(stringWithUser);
421+
}
421422
}
422423
}
423424
return returnObject;
424425
});
425426
};
426427

427-
sessions.deleteAnalysisData = function (sessionId, esClient) {
428-
return sessions.find({_id: sessionId}, true).then(function(result) {
428+
sessions.deleteAnalysisData = function (defaultConfig, sessionId, esClient) {
429+
return sessions.findById(sessionId, true).then(function(result) {
429430
if (!result) {
430431
throw {
431432
message: 'Session not found',
432433
status: 404
433434
};
434435
}
435-
return getAnalysisIndicesReplace(result.versionId, sessionId).then(function (result) {
436+
return getAnalysisIndicesReplace(defaultConfig, result.versionId, sessionId).then(function (result) {
436437
var deferred = Q.defer();
437438
esClient.indices.delete({
438439
index: result.indices
@@ -449,15 +450,15 @@ module.exports = (function () {
449450
});
450451
};
451452

452-
sessions.deleteUserData = function (sessionId, userData, esClient) {
453-
return sessions.find({_id: sessionId}, true).then(function(result) {
453+
sessions.deleteUserData = function (defaultConfig, sessionId, userData, esClient) {
454+
return sessions.findById(sessionId, true).then(function(result) {
454455
if (!result) {
455456
throw {
456457
message: 'Session not found',
457458
status: 404
458459
};
459460
}
460-
return getAnalysisIndicesReplace(result.versionId, sessionId, userData).then(function(result) {
461+
return getAnalysisIndicesReplace(defaultConfig, result.versionId, sessionId, userData).then(function(result) {
461462
var deferred = Q.defer();
462463

463464
if (!result.query) {

routes/sessions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ module.exports = function (kafkaService, stormService) {
543543
});
544544

545545
/**
546-
* @api {delete} /sessions/data/:versionId/:sessionId Remove the session analysis data with the id sessionId.
546+
* @api {delete} /sessions/data/:sessionId Remove the session analysis data with the id sessionId.
547547
* @apiName deleteSessions
548548
* @apiGroup Sessions
549549
*
@@ -559,7 +559,7 @@ module.exports = function (kafkaService, stormService) {
559559
*
560560
*/
561561
router.delete('/data/:sessionId/', function (req, res) {
562-
restUtils.processResponse(sessions.deleteAnalysisData(req.params.sessionId, req.app.esClient), res);
562+
restUtils.processResponse(sessions.deleteAnalysisData(req.app.config.storm, req.params.sessionId, req.app.esClient), res);
563563
});
564564

565565
/**
@@ -579,7 +579,7 @@ module.exports = function (kafkaService, stormService) {
579579
*
580580
*/
581581
router.delete('/data/:sessionId/:user', function (req, res) {
582-
restUtils.processResponse(sessions.deleteUserData(req.params.sessionId, req.params.user, req.app.esClient), res);
582+
restUtils.processResponse(sessions.deleteUserData(req.app.config.storm, req.params.sessionId, req.params.user, req.app.esClient), res);
583583
});
584584

585585
return router;

0 commit comments

Comments
 (0)