feat: Track attachments access (#4416)

This commit is contained in:
Tom Moor
2022-11-12 08:41:59 -08:00
committed by GitHub
parent 622f464b9f
commit 762341a4ec
3 changed files with 24 additions and 4 deletions

View 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");
},
};

View File

@@ -44,6 +44,9 @@ class Attachment extends IdModel {
@Column
acl: string;
@Column
lastAccessedAt: Date | null;
// getters
get name() {

View File

@@ -159,11 +159,15 @@ const handleAttachmentsRedirect = async (ctx: ContextWithState) => {
rejectOnEmpty: true,
});
if (attachment.isPrivate) {
if (attachment.teamId !== user.teamId) {
throw AuthorizationError();
}
if (attachment.isPrivate && attachment.teamId !== user.teamId) {
throw AuthorizationError();
}
await attachment.update({
lastAccessedAt: new Date(),
});
if (attachment.isPrivate) {
const accessUrl = await getSignedUrl(attachment.key);
ctx.redirect(accessUrl);
} else {