feat: Track attachments access (#4416)
This commit is contained in:
13
server/migrations/20221112162341-attachment-tracking.js
Normal file
13
server/migrations/20221112162341-attachment-tracking.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
up: async (queryInterface, Sequelize) => {
|
||||||
|
await queryInterface.addColumn("attachments", "lastAccessedAt", {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
allowNull: true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
down: async (queryInterface) => {
|
||||||
|
await queryInterface.removeColumn("attachments", "lastAccessedAt");
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -44,6 +44,9 @@ class Attachment extends IdModel {
|
|||||||
@Column
|
@Column
|
||||||
acl: string;
|
acl: string;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
lastAccessedAt: Date | null;
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
|
|||||||
@@ -159,11 +159,15 @@ const handleAttachmentsRedirect = async (ctx: ContextWithState) => {
|
|||||||
rejectOnEmpty: true,
|
rejectOnEmpty: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (attachment.isPrivate) {
|
if (attachment.isPrivate && attachment.teamId !== user.teamId) {
|
||||||
if (attachment.teamId !== user.teamId) {
|
throw AuthorizationError();
|
||||||
throw AuthorizationError();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
await attachment.update({
|
||||||
|
lastAccessedAt: new Date(),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (attachment.isPrivate) {
|
||||||
const accessUrl = await getSignedUrl(attachment.key);
|
const accessUrl = await getSignedUrl(attachment.key);
|
||||||
ctx.redirect(accessUrl);
|
ctx.redirect(accessUrl);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user