♻️🩹🚨 backend,oo: remove company_id when key available and minor cleanup (#525)
This commit is contained in:
@@ -1043,6 +1043,20 @@ export class DocumentsService {
|
||||
throw new CrudException("Invalid editing_session_key", 400);
|
||||
}
|
||||
|
||||
try {
|
||||
const parsedKey = EditingSessionKeyFormat.parse(editing_session_key);
|
||||
context = {
|
||||
...context,
|
||||
company: { id: parsedKey.companyId },
|
||||
};
|
||||
} catch (e) {
|
||||
this.logger.error(
|
||||
"Invalid editing_session_key value: " + JSON.stringify(editing_session_key),
|
||||
e,
|
||||
);
|
||||
throw new CrudException("Invalid editing_session_key", 400);
|
||||
}
|
||||
|
||||
const driveFile = await this.repository.findOne({ editing_session_key }, {}, context);
|
||||
if (!driveFile) {
|
||||
this.logger.error("Drive item not found by editing session key");
|
||||
|
||||
@@ -5,6 +5,7 @@ import { createDocumentSchema, createVersionSchema, beginEditingSchema } from ".
|
||||
|
||||
const baseUrl = "/companies/:company_id";
|
||||
const serviceUrl = `${baseUrl}/item`;
|
||||
const editingSessionBase = "/editing_session/:editing_session_key";
|
||||
|
||||
const routes: FastifyPluginCallback = (fastify: FastifyInstance, _options, next) => {
|
||||
const documentsController = new DocumentsController();
|
||||
@@ -89,21 +90,21 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, _options, next)
|
||||
|
||||
fastify.route({
|
||||
method: "GET",
|
||||
url: `${serviceUrl}/editing_session/:editing_session_key`,
|
||||
url: editingSessionBase, //TODO NONONO check authenticate*Optional*
|
||||
preValidation: [fastify.authenticateOptional],
|
||||
handler: documentsController.getByEditingSessionKey.bind(documentsController),
|
||||
});
|
||||
|
||||
fastify.route({
|
||||
method: "POST",
|
||||
url: `${serviceUrl}/editing_session/:editing_session_key`,
|
||||
url: editingSessionBase,
|
||||
preValidation: [fastify.authenticateOptional],
|
||||
handler: documentsController.endEditing.bind(documentsController),
|
||||
});
|
||||
|
||||
fastify.route({
|
||||
method: "DELETE",
|
||||
url: `${serviceUrl}/editing_session/:editing_session_key`,
|
||||
url: editingSessionBase,
|
||||
preValidation: [fastify.authenticateOptional],
|
||||
handler: documentsController.cancelEditing.bind(documentsController),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user