From bdee86ac72d8271eae22e5656363dba6228a7b4f Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Wed, 26 Oct 2022 16:37:21 +0200 Subject: [PATCH 1/4] Changed logbook loading, so user beloning to admin role/group can see the dataset logbook independently from the permissions --- common/models/logbook.js | 18 ++++++++++++------ common/models/logbook.json | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/common/models/logbook.js b/common/models/logbook.js index f5bd839a..4514b0c8 100644 --- a/common/models/logbook.js +++ b/common/models/logbook.js @@ -77,11 +77,11 @@ module.exports = function (Logbook) { * @returns {Logbook} Logbook model instance */ - Logbook.findByName = async function (name, filters) { + Logbook.findByName = async function (name, filters = "{}") { if (logbookEnabled) { try { const accessToken = await login(username, password); - console.log("Fetching logbook", { name, filters }); + logger.lofInfo("Fetching logbook", { name, filters }); const res = await superagent .get( baseUrl + @@ -125,7 +125,7 @@ module.exports = function (Logbook) { if (logbookEnabled) { try { const accessToken = await login(username, password); - console.log("Sending message", { name, data }); + logger.logInfo("Sending message", { name, data }); const res = await superagent .post(baseUrl + `/Logbooks/${name}/message`) .set({ Authorization: `Bearer ${accessToken}` }) @@ -214,10 +214,16 @@ async function getUserProposalIds(userId) { roleNameList.push(user.username); options.currentGroups = roleNameList; } + options.currentGroups = [...new Set(options.currentGroups)]; - const proposals = await Proposal.find({ - where: { ownerGroup: { inq: options.currentGroups } }, - }); + let proposals = {}; + if ( options.currentGroups.includes("admin") ) { + proposals = await Proposal.find(); + } else { + proposals = await Proposal.find({ + where: { ownerGroup: { inq: options.currentGroups } }, + }); + } return proposals.map((proposal) => proposal.proposalId); } catch (err) { logger.logError(err.message, { diff --git a/common/models/logbook.json b/common/models/logbook.json index 45bed49d..6c66d9ee 100644 --- a/common/models/logbook.json +++ b/common/models/logbook.json @@ -48,7 +48,7 @@ { "arg": "logbooks", "type": "array", - "root": true, + "root": "true", "description": "Array of Logbook model instances" } ], From 3ddd3594dbfe25d1dd9b60fc64e75d303d57515d Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Mon, 31 Oct 2022 11:50:16 +0100 Subject: [PATCH 2/4] Added endpoint under Datasets to retrieve associated logbook --- common/models/dataset.js | 128 ++++++++++++++++++++----------------- common/models/dataset.json | 39 ++++++++++- common/models/logbook.js | 12 +++- 3 files changed, 116 insertions(+), 63 deletions(-) diff --git a/common/models/dataset.js b/common/models/dataset.js index 3ede350c..6e0da91f 100644 --- a/common/models/dataset.js +++ b/common/models/dataset.js @@ -10,10 +10,10 @@ const logger = require("../logger"); // TODO Feature Add delete functionality for dataset, which removes Dataset and all linked data: // OrigDatablock and Datablock and DatasetAttachments -module.exports = function(Dataset) { +module.exports = function (Dataset) { var app = require("../../server/server"); - Dataset.appendToArrayField = function(id, fieldName, data, ctx, next) { + Dataset.appendToArrayField = function (id, fieldName, data, ctx, next) { const where = { pid: id }; var $addToSet = {}; // $each is necessary as data is an array of values @@ -24,9 +24,9 @@ module.exports = function(Dataset) { }; - Dataset.prototype.updateSize = function(id, sizeField, size, numFilesField, numFiles, next) { + Dataset.prototype.updateSize = function (id, sizeField, size, numFilesField, numFiles, next) { // console.log("Updating size field:", id, sizeField, size) - Dataset.findById(id, function(err, instance) { + Dataset.findById(id, function (err, instance) { if (err) { return next(err); } else { @@ -38,7 +38,7 @@ module.exports = function(Dataset) { } instance[sizeField] = size + oldsize; // console.log("new size:",instance[sizeField]) - var oldNumFiles=0; + var oldNumFiles = 0; if (instance[numFilesField]) { oldNumFiles = instance[numFilesField]; } @@ -54,27 +54,27 @@ module.exports = function(Dataset) { Dataset.validatesUniquenessOf("pid"); // put - Dataset.beforeRemote("replaceOrCreate", function(ctx, instance, next) { + Dataset.beforeRemote("replaceOrCreate", function (ctx, instance, next) { // console.log("++++++++++++ PUT") utils.updateTimesToUTC(["creationTime"], ctx.args.data); utils.dropAutoGeneratedFields(ctx.args.data, next); }); // patch - Dataset.beforeRemote("patchOrCreate", function(ctx, instance, next) { + Dataset.beforeRemote("patchOrCreate", function (ctx, instance, next) { // console.log("+++++++++++++++ PATCH") utils.updateTimesToUTC(["creationTime"], ctx.args.data); utils.dropAutoGeneratedFields(ctx.args.data, next); }); // post - Dataset.beforeRemote("create", function(ctx, unused, next) { + Dataset.beforeRemote("create", function (ctx, unused, next) { // console.log("+++++++++++++++ POST") utils.updateTimesToUTC(["creationTime"], ctx.args.data); utils.dropAutoGeneratedFields(ctx.args.data, next); }); - Dataset.beforeRemote("find", function(ctx, unused, next) { + Dataset.beforeRemote("find", function (ctx, unused, next) { const accessToken = ctx.args.options.accessToken; if (!accessToken) { if (!ctx.args.filter) { @@ -90,7 +90,7 @@ module.exports = function(Dataset) { next(); }); - Dataset.afterRemote("findById", function(ctx, unused, next) { + Dataset.afterRemote("findById", function (ctx, unused, next) { const accessToken = ctx.args.options.accessToken; let error; if (!accessToken) { @@ -101,15 +101,15 @@ module.exports = function(Dataset) { } next(error); }); - Dataset.beforeRemote("prototype.__get__attachments", function(ctx, unused, next){ + Dataset.beforeRemote("prototype.__get__attachments", function (ctx, unused, next) { checkACLtoRelatedModel(ctx, next); }); - Dataset.beforeRemote("prototype.__get__origdatablocks", function(ctx, unused, next){ + Dataset.beforeRemote("prototype.__get__origdatablocks", function (ctx, unused, next) { checkACLtoRelatedModel(ctx, next); }); - Dataset.beforeRemote("prototype.__get__datablocks", function(ctx, unused, next){ + Dataset.beforeRemote("prototype.__get__datablocks", function (ctx, unused, next) { checkACLtoRelatedModel(ctx, next); }); @@ -122,18 +122,18 @@ module.exports = function(Dataset) { const groups = ctx.args.options.currentGroups; // Allow access to related model if dataset is published or user is owner or user is in a group having read access to the dataset if (ctx.instance.isPublished - || (accessToken - && (groups.indexOf(ctx.instance.ownerGroup) !== -1 - || groups.indexOf("globalaccess") !== -1 - || ctx.instance.accessGroups && groups.some(g => ctx.instance.accessGroups.indexOf(g) !== -1) - || ctx.instance.sharedWith && groups.some(g => ctx.instance.sharedWith.indexOf(g) !== -1) - || groups.indexOf(ctx.instance.instrumentGroup) !== -1))) { + || (accessToken + && (groups.indexOf(ctx.instance.ownerGroup) !== -1 + || groups.indexOf("globalaccess") !== -1 + || ctx.instance.accessGroups && groups.some(g => ctx.instance.accessGroups.indexOf(g) !== -1) + || ctx.instance.sharedWith && groups.some(g => ctx.instance.sharedWith.indexOf(g) !== -1) + || groups.indexOf(ctx.instance.instrumentGroup) !== -1))) { return next(); } return next(error); }; - Dataset.beforeRemote("findOne", function(ctx, unused, next) { + Dataset.beforeRemote("findOne", function (ctx, unused, next) { const accessToken = ctx.args.options.accessToken; if (!accessToken) { if (!ctx.args.filter) { @@ -149,7 +149,7 @@ module.exports = function(Dataset) { next(); }); - Dataset.beforeRemote("metadataKeys", function(ctx, unused, next) { + Dataset.beforeRemote("metadataKeys", function (ctx, unused, next) { const accessToken = ctx.args.options.accessToken; if (!accessToken) { ctx.args.fields.isPublished = true; @@ -157,7 +157,7 @@ module.exports = function(Dataset) { next(); }); - Dataset.beforeRemote("fullfacet", function(ctx, unused, next) { + Dataset.beforeRemote("fullfacet", function (ctx, unused, next) { const accessToken = ctx.args.options.accessToken; if (!accessToken) { ctx.args.fields.isPublished = true; @@ -165,7 +165,7 @@ module.exports = function(Dataset) { next(); }); - Dataset.beforeRemote("fullquery", function(ctx, unused, next) { + Dataset.beforeRemote("fullquery", function (ctx, unused, next) { const accessToken = ctx.args.options.accessToken; if (!accessToken) { ctx.args.fields.isPublished = true; @@ -196,8 +196,8 @@ module.exports = function(Dataset) { currentUnit, unit ); - lodash.update(scientificMetadata, `${lhs}.unit`, () => {return unitRequested;}); - lodash.update(scientificMetadata, `${lhs}.value`, () => {return valueRequested;}); + lodash.update(scientificMetadata, `${lhs}.unit`, () => { return unitRequested; }); + lodash.update(scientificMetadata, `${lhs}.value`, () => { return valueRequested; }); } }); }); @@ -223,7 +223,7 @@ module.exports = function(Dataset) { ownerGroup: ownerGroup } }, - function(err, policyInstance) { + function (err, policyInstance) { if (err) { return next(err); } @@ -254,7 +254,7 @@ module.exports = function(Dataset) { defaultPolicy.archiveEmailsToBeNotified = []; defaultPolicy.retrieveEmailsToBeNotified = []; defaultPolicy.embargoPeriod = 3; - Policy.create(defaultPolicy, ctx.options, function( + Policy.create(defaultPolicy, ctx.options, function ( err, _instance ) { @@ -314,7 +314,7 @@ module.exports = function(Dataset) { ctx.instance.datasetlifecycle.isOnCentralDisk = true; if (!("archiveStatusMessage" in subblock)) ctx.instance.datasetlifecycle.archiveStatusMessage = - "datasetCreated"; + "datasetCreated"; if (!("retrieveStatusMessage" in subblock)) ctx.instance.datasetlifecycle.retrieveStatusMessage = ""; if (!("retrieveIntegrityCheck" in subblock)) @@ -325,7 +325,7 @@ module.exports = function(Dataset) { var retention = new Date( now.setFullYear( now.getFullYear() + - config.policyRetentionShiftInYears + config.policyRetentionShiftInYears ) ); ctx.instance.datasetlifecycle.archiveRetentionTime = retention @@ -337,7 +337,7 @@ module.exports = function(Dataset) { var pubDate = new Date( now.setFullYear( now.getFullYear() + - config.policyPublicationShiftInYears + config.policyPublicationShiftInYears ) ); ctx.instance.datasetlifecycle.dateOfPublishing = pubDate @@ -353,7 +353,7 @@ module.exports = function(Dataset) { if (ctx.instance.sourceFolder) { // remove trailing slashes if (ctx.instance.sourceFolder !== "/") { - ctx.instance.sourceFolder = ctx.instance.sourceFolder.replace(/\/$/,""); + ctx.instance.sourceFolder = ctx.instance.sourceFolder.replace(/\/$/, ""); } // autofill datasetName if (!ctx.instance.datasetName) { @@ -362,7 +362,7 @@ module.exports = function(Dataset) { ctx.instance.datasetName = arr[0]; } else { ctx.instance.datasetName = - arr[arr.length - 2] + "/" + arr[arr.length - 1]; + arr[arr.length - 2] + "/" + arr[arr.length - 1]; } } } @@ -375,13 +375,13 @@ module.exports = function(Dataset) { ownerGroup: ctx.instance.ownerGroup } }; - Policy.findOne(filter, ctx.options, function(err, policyInstance) { + Policy.findOne(filter, ctx.options, function (err, policyInstance) { if (err) { var msg = - "Error when looking for Policy of pgroup " + - ctx.instance.ownerGroup + - " " + - err; + "Error when looking for Policy of pgroup " + + ctx.instance.ownerGroup + + " " + + err; console.log(msg); next(msg); } else if (policyInstance) { @@ -389,17 +389,17 @@ module.exports = function(Dataset) { // Case 1: classification undefined but policy defined:, define classification via policy let classification = ""; switch (policyInstance.tapeRedundancy) { - case "low": - classification = "IN=medium,AV=low,CO=low"; - break; - case "medium": - classification = "IN=medium,AV=medium,CO=low"; - break; - case "high": - classification = "IN=medium,AV=high,CO=low"; - break; - default: - classification = "IN=medium,AV=low,CO=low"; + case "low": + classification = "IN=medium,AV=low,CO=low"; + break; + case "medium": + classification = "IN=medium,AV=medium,CO=low"; + break; + case "high": + classification = "IN=medium,AV=high,CO=low"; + break; + default: + classification = "IN=medium,AV=low,CO=low"; } ctx.instance.classification = classification; } @@ -446,9 +446,9 @@ module.exports = function(Dataset) { // clean up data connected to a dataset, e.g. if archiving failed // TODO can the additional findbyId calls be avoided ? - Dataset.reset = function(id, options, next) { + Dataset.reset = function (id, options, next) { var Datablock = app.models.Datablock; - Dataset.findById(id, options, function(err, l) { + Dataset.findById(id, options, function (err, l) { if (err) { next(err); } else { @@ -465,7 +465,7 @@ module.exports = function(Dataset) { packedSize: 0 }, options, - function(err, _dsInstance) { + function (err, _dsInstance) { if (err) { next(err); } @@ -474,7 +474,7 @@ module.exports = function(Dataset) { datasetId: id }, options, - function(err, _b) { + function (err, _b) { if (err) { next(err); } else { @@ -488,9 +488,9 @@ module.exports = function(Dataset) { }); }; - Dataset.isValid = function(dataset, next) { + Dataset.isValid = function (dataset, next) { var ds = new Dataset(dataset); - ds.isValid(function(valid) { + ds.isValid(function (valid) { if (!valid) { next(null, { errors: ds.errors, @@ -504,7 +504,7 @@ module.exports = function(Dataset) { }); }; - Dataset.thumbnail = async function(id) { + Dataset.thumbnail = async function (id) { const Attachment = app.models.Attachment; const filter = { where: { @@ -513,7 +513,7 @@ module.exports = function(Dataset) { }; return Attachment.findOne(filter).then(instance => { const base64stringExample = - "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAMAAAANI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+zIg7OqsCkNFsl9qVkuqC06ZXPKBt7uURMAY+JmZ7CK/Um2QrDQ+9p1tARvjST8sY/sbGwLFwIoT0WE9Iyb4UEEPfqisHcKAn9HbGf7s3VlSBGPkeC2PMa6Zz51HnTEeBX9iI7+vrPoHMzSgQA/a6GKLspo5i5WeuHqa6cuX1yReGMPWl7CfTrkv7de3aT72VMx93X96t6zl8cDuADGO1qjs+Bp9Nd/eb7qEr7i5dovT6masHUSd3X7kPhSVuqDMr10Nj8Nh0F8m+LlFvx/yZ95d3I/wAAp1pdugrINlWNGTP7dqqu+dMjyD77Sqiu1+OwUQ4Y9DZZWcAnpi2C+Hy17cY+hX29Ua1ZdBfqjgH7LUbewe6cePLk3eQ9ipvnj54BtAweyWjgWIrODF3yn86PENb61Rn0TJieh132S1Situq1HJCDHKSdCSUKB5PU9aQlkX3Rs3pdPqonFQbN82nHGbxRNE9H9NGL0fWMZW3o2Rd+GelmQ0AF2vGYxYN/vAiGHmWjGSHvtQI0X8o+K++fgJVsMdEaov+5gAAAABJRU5ErkJggg=="; let base64string2 = ""; if (instance && instance.__data && instance.__data.thumbnail !== undefined) { base64string2 = instance.__data.thumbnail; @@ -530,7 +530,7 @@ module.exports = function(Dataset) { * @returns {Object} The response from the OpenWhisk reduce action */ - Dataset.reduceDataset = function(dataset) { + Dataset.reduceDataset = function (dataset) { if (config.datasetReductionEnabled) { const Producer = kafka.Producer; const Consumer = kafka.Consumer; @@ -588,7 +588,7 @@ module.exports = function(Dataset) { } }; - Dataset.metadataKeys = async function(fields, limits, options) { + Dataset.metadataKeys = async function (fields, limits, options) { try { const blacklist = [ new RegExp(".*_date"), @@ -605,7 +605,7 @@ module.exports = function(Dataset) { // ensure that no more than MAXLIMIT someCollections are read for metadata key extraction let MAXLIMIT; - if(config.metadataParentInstancesReturnLimit) { + if (config.metadataParentInstancesReturnLimit) { MAXLIMIT = config.metadataParentInstancesReturnLimit; let lm; @@ -678,4 +678,14 @@ module.exports = function(Dataset) { logger.logError(err.message, { location: "Dataset.metadatakeys" }); } }; + + Dataset.logbook = async function (id, filters = "{}" ) { + const Logbook = app.models.Logbook; + + // returns logbook associated with dataset + const ds = await Dataset.findById(id) + + // the logbook chat has the same name as the proposal id + return Logbook.findDatasetLogbook(ds.proposalId, filters); + }; }; diff --git a/common/models/dataset.json b/common/models/dataset.json index c17af3b3..ff14f6d8 100644 --- a/common/models/dataset.json +++ b/common/models/dataset.json @@ -332,7 +332,44 @@ "type": "string", "root": true } + }, + "logbook": { + "accepts": [ + { + "arg": "id", + "type": "string", + "required": true, + "description": "Dataset pid", + "http": { + "source": "path" + } + }, + { + "arg": "filters", + "type": "string", + "required": false, + "description": "Filter json object, keys: textSearch, showBotMessages, showUserMessages, showImages, skip, limit, sortField", + "http": { + "source": "query" + } + } + ], + "returns": [ + { + "arg": "logbook", + "type": "object", + "root": true, + "description": "Logbook model instance associated with dataset" + } + ], + "description": "Find Logbook model instance associated with dataset", + "http": [ + { + "path": "/:id/logbook", + "verb": "get" + } + ] } - + } } diff --git a/common/models/logbook.js b/common/models/logbook.js index 4514b0c8..25bc7ace 100644 --- a/common/models/logbook.js +++ b/common/models/logbook.js @@ -77,11 +77,15 @@ module.exports = function (Logbook) { * @returns {Logbook} Logbook model instance */ - Logbook.findByName = async function (name, filters = "{}") { + Logbook.findByName = findsByNameCommon; + + Logbook.findDatasetLogbook = findsByNameCommon; + + async function findsByNameCommon(name, filters = "{}") { if (logbookEnabled) { try { const accessToken = await login(username, password); - logger.lofInfo("Fetching logbook", { name, filters }); + logger.logInfo("Fetching logbook", { name, filters }); const res = await superagent .get( baseUrl + @@ -221,7 +225,9 @@ async function getUserProposalIds(userId) { proposals = await Proposal.find(); } else { proposals = await Proposal.find({ - where: { ownerGroup: { inq: options.currentGroups } }, + where: { + ownerGroup: { inq: options.currentGroups }, + } }); } return proposals.map((proposal) => proposal.proposalId); From e0e1802309e7e58be16a7c75fc953b880c81858b Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Tue, 1 Nov 2022 13:55:42 +0100 Subject: [PATCH 3/4] Fixed linting issues --- common/models/dataset.js | 6 +++--- common/models/logbook.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/models/dataset.js b/common/models/dataset.js index 6e0da91f..1dd7ebde 100644 --- a/common/models/dataset.js +++ b/common/models/dataset.js @@ -679,12 +679,12 @@ module.exports = function (Dataset) { } }; - Dataset.logbook = async function (id, filters = "{}" ) { + Dataset.logbook = async function (id, filters = "{}") { const Logbook = app.models.Logbook; // returns logbook associated with dataset - const ds = await Dataset.findById(id) - + const ds = await Dataset.findById(id); + // the logbook chat has the same name as the proposal id return Logbook.findDatasetLogbook(ds.proposalId, filters); }; diff --git a/common/models/logbook.js b/common/models/logbook.js index 25bc7ace..9ce45360 100644 --- a/common/models/logbook.js +++ b/common/models/logbook.js @@ -116,7 +116,7 @@ module.exports = function (Logbook) { } } return []; - }; + } /** * Send message to a Logbook From a859aca1c40eef09d4c47bab8a89a53bea15800e Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Tue, 1 Nov 2022 14:58:47 +0100 Subject: [PATCH 4/4] Fixed linting and added some more output --- common/models/dataset.js | 22 +++++++++++----------- test/Datablock.js | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/common/models/dataset.js b/common/models/dataset.js index 1dd7ebde..2c3ecf34 100644 --- a/common/models/dataset.js +++ b/common/models/dataset.js @@ -389,17 +389,17 @@ module.exports = function (Dataset) { // Case 1: classification undefined but policy defined:, define classification via policy let classification = ""; switch (policyInstance.tapeRedundancy) { - case "low": - classification = "IN=medium,AV=low,CO=low"; - break; - case "medium": - classification = "IN=medium,AV=medium,CO=low"; - break; - case "high": - classification = "IN=medium,AV=high,CO=low"; - break; - default: - classification = "IN=medium,AV=low,CO=low"; + case "low": + classification = "IN=medium,AV=low,CO=low"; + break; + case "medium": + classification = "IN=medium,AV=medium,CO=low"; + break; + case "high": + classification = "IN=medium,AV=high,CO=low"; + break; + default: + classification = "IN=medium,AV=low,CO=low"; } ctx.instance.classification = classification; } diff --git a/test/Datablock.js b/test/Datablock.js index a8151da1..d6969541 100644 --- a/test/Datablock.js +++ b/test/Datablock.js @@ -266,7 +266,7 @@ describe("Test Datablocks and OrigDatablocks and their relation to raw Datasets" for (const item of array) { await deleteDatablock(item); } - // console.log("==== Finishing all deletes") + console.log("==== Finishing all deletes"); } it("remove potentially existing datablocks to guarantee uniqueness", function (done) { @@ -282,7 +282,7 @@ describe("Test Datablocks and OrigDatablocks and their relation to raw Datasets" .end((err, res) => { if (err) return done(err); - // console.log(" ==================== Found existing datablocks:", res.body) + console.log(" ==================== Found existing datablocks:", res.body); // now remove all these entries processArray(res.body); done();