Skip to content

Commit

Permalink
Merge pull request #241 from nzzdev/release-10.7.0
Browse files Browse the repository at this point in the history
Release 10.7.0
  • Loading branch information
migingreen committed May 22, 2023
2 parents 791817a + 4a5da8d commit cabe108
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 167 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nzz/q-server",
"version": "10.6.14",
"version": "10.7.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
34 changes: 18 additions & 16 deletions plugins/core/base/routes/admin/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ module.exports = {
path: "/admin/migration/{tool}/{id?}",
method: "GET",
config: {
auth: "q-auth",
auth: {
strategies: ["q-auth-azure", "q-auth-ld"],
},
cors: {
credentials: true
credentials: true,
},
description:
"Executes migration of items in database for specified tool or for a single item with the specified id respectively",
tags: ["api"]
tags: ["api"],
},
handler: async (request, h) => {
const tool = request.params.tool;
Expand All @@ -33,16 +35,16 @@ module.exports = {
ignoreInactive: true,
session: {
credentials: request.auth.credentials,
artifacts: request.auth.artifacts
}
artifacts: request.auth.artifacts,
},
});
const migrationStatus = await migrateItem(
item,
toolBaseUrl,
request.server.app.db
);
return {
status: migrationStatus.status
status: migrationStatus.status,
};
} catch (err) {
Bounce.rethrow(err, "system");
Expand All @@ -53,11 +55,11 @@ module.exports = {
tool,
session: {
credentials: request.auth.credentials,
artifacts: request.auth.artifacts
}
artifacts: request.auth.artifacts,
},
});

let migrationStatuses = items.map(async item => {
let migrationStatuses = items.map(async (item) => {
return await migrateItem(item, toolBaseUrl, request.server.app.db);
});

Expand All @@ -77,45 +79,45 @@ module.exports = {

return stats;
}
}
},
};

function migrateItem(item, toolBaseUrl, db) {
return new Promise(async (resolve, reject) => {
const body = {
item: item
item: item,
};

try {
const response = await fetch(`${toolBaseUrl}/migration`, {
method: "POST",
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json"
}
"Content-Type": "application/json",
},
});

if (response.status === 200) {
const json = await response.json();
await saveItem(json.item, db);
return resolve({
id: item._id,
status: statusUpdated
status: statusUpdated,
});
}

if (response.status === 304) {
return resolve({
id: item._id,
status: statusNotUpdated
status: statusNotUpdated,
});
}

throw new Error(`item ${item._id} could not be migrated`);
} catch (e) {
resolve({
id: item._id,
status: statusFailed
status: statusFailed,
});
}
});
Expand Down
74 changes: 39 additions & 35 deletions plugins/core/base/routes/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function validateAgainstSchema(request, doc) {
reject(
Boom.badRequest(
validate.errors
.map(error => {
.map((error) => {
return JSON.stringify(error);
})
.join("\n")
Expand All @@ -41,30 +41,30 @@ module.exports = {
method: "GET",
options: {
auth: {
strategies: ["q-auth"],
mode: "optional"
strategies: ["q-auth-azure", "q-auth-ld"],
mode: "optional",
},
cors: {
credentials: true
credentials: true,
},
validate: {
params: {
id: Joi.string().required()
}
id: Joi.string().required(),
},
},
description: "gets the item with the given id from the database",
tags: ["api", "editor"]
tags: ["api", "editor"],
},
handler: async function(request, h) {
handler: async function (request, h) {
return request.server.methods.db.item.getById({
id: request.params.id,
ignoreInactive: true,
session: {
credentials: request.auth.credentials,
artifacts: request.auth.artifacts
}
artifacts: request.auth.artifacts,
},
});
}
},
},
post: {
path: "/item",
Expand All @@ -75,21 +75,23 @@ module.exports = {
_id: Joi.string().optional(),
_rev: Joi.forbidden(),
title: Joi.string().required(),
tool: Joi.string().required()
tool: Joi.string().required(),
},
options: {
allowUnknown: true
}
allowUnknown: true,
},
},
auth: {
strategies: ["q-auth-azure", "q-auth-ld"],
},
auth: "q-auth",
cors: {
credentials: true
credentials: true,
},
description:
"stores a new item to the database and returns the id among other things",
tags: ["api", "editor"]
tags: ["api", "editor"],
},
handler: async function(request, h) {
handler: async function (request, h) {
let doc = request.payload;
let now = new Date();

Expand Down Expand Up @@ -118,20 +120,20 @@ module.exports = {
doc,
session: {
credentials: request.auth.credentials,
artifacts: request.auth.artifacts
}
artifacts: request.auth.artifacts,
},
});

docDiff._id = res.id;
docDiff._rev = res.rev;

const savedDoc = Object.assign(doc, docDiff);
request.server.events.emit("item.new", {
newItem: savedDoc
newItem: savedDoc,
});

return docDiff;
}
},
},
put: {
path: "/item",
Expand All @@ -142,21 +144,23 @@ module.exports = {
_id: Joi.string().required(),
_rev: Joi.string().required(),
title: Joi.string().required(),
tool: Joi.string().required()
tool: Joi.string().required(),
},
options: {
allowUnknown: true
}
allowUnknown: true,
},
},
auth: {
strategies: ["q-auth-azure", "q-auth-ld"],
},
auth: "q-auth",
cors: {
credentials: true
credentials: true,
},
description:
"updates an existing item to the database and returns the new revision number among other things",
tags: ["api", "editor"]
tags: ["api", "editor"],
},
handler: async function(request, h) {
handler: async function (request, h) {
let doc = request.payload;
let now = new Date();
try {
Expand All @@ -178,7 +182,7 @@ module.exports = {

const oldDoc = await request.server.methods.db.item.getById({
id: request.payload._id,
ignoreInactive: true
ignoreInactive: true,
});

// if the active state change to true, we set activateDate
Expand Down Expand Up @@ -206,16 +210,16 @@ module.exports = {
doc,
session: {
credentials: request.auth.credentials,
artifacts: request.auth.artifacts
}
artifacts: request.auth.artifacts,
},
});

docDiff._rev = res.rev;
const savedDoc = Object.assign(doc, docDiff);

const eventData = {
newItem: savedDoc,
oldItem: oldDoc
oldItem: oldDoc,
};

if (isNewActive) {
Expand All @@ -231,6 +235,6 @@ module.exports = {
request.server.events.emit("item.update", eventData);

return docDiff;
}
}
},
},
};
2 changes: 1 addition & 1 deletion plugins/core/base/routes/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
method: "GET",
options: {
auth: {
strategy: "q-auth",
strategies: ["q-auth-azure", "q-auth-ld"],
mode: "try",
},
cors: {
Expand Down
23 changes: 12 additions & 11 deletions plugins/core/editor/routes/tools-ordered-by-user-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@ module.exports = {
path: "/editor/tools-ordered-by-user-usage",
method: "GET",
options: {
auth: "q-auth",
auth: {
strategies: ["q-auth-azure", "q-auth-ld"],
},
cors: {
credentials: true
credentials: true,
},
description: "Returns all available Q tool names",
tags: ["api", "editor"]
tags: ["api", "editor"],
},
handler: async (request, h) => {
const username = request.auth.credentials.name;
const toolsWithUsageByUser = await request.server.methods.db.tools.getWithUserUsage(
{
const toolsWithUsageByUser =
await request.server.methods.db.tools.getWithUserUsage({
username,
session: {
credentials: request.auth.credentials,
artifacts: request.auth.artifacts
}
}
);
artifacts: request.auth.artifacts,
},
});
return toolsWithUsageByUser
.sort((a, b) => {
return b.usage - a.usage;
})
.map(row => {
.map((row) => {
return row.tool;
});
}
},
};
20 changes: 14 additions & 6 deletions plugins/file/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const Boom = require("@hapi/boom");
const { S3Client, PutObjectCommand, GetObjectCommand } = require("@aws-sdk/client-s3");
const {
S3Client,
PutObjectCommand,
GetObjectCommand,
} = require("@aws-sdk/client-s3");
const Mimos = require("@hapi/mimos");
const mimos = new Mimos.Mimos();
const hasha = require("hasha");
Expand Down Expand Up @@ -56,7 +60,9 @@ module.exports = {
method: "POST",
path: "/file",
options: {
auth: "q-auth",
auth: {
strategies: ["q-auth-azure", "q-auth-ld"],
},
cors: {
credentials: true,
additionalHeaders: [
Expand Down Expand Up @@ -157,10 +163,12 @@ module.exports = {
},
handler: async function (request, h) {
try {
const data = await s3Client.send(new GetObjectCommand({
Bucket: options.s3Bucket,
Key: request.params.fileKey,
}));
const data = await s3Client.send(
new GetObjectCommand({
Bucket: options.s3Bucket,
Key: request.params.fileKey,
})
);
return h
.response(data.Body)
.header(
Expand Down
Loading

0 comments on commit cabe108

Please sign in to comment.