feat: Record share link last accessed time (#2047)

* chore: Migrations

* chore: Add recording of share link views

* feat: Add display of share link accessed date in admin

* translations

* test

* translations, admin pagination
This commit is contained in:
Tom Moor
2021-04-18 09:38:13 -07:00
committed by GitHub
parent e9f083feb8
commit 7f9cba9819
11 changed files with 80 additions and 36 deletions

View File

@@ -518,6 +518,8 @@ async function loadDocument({ id, shareId, user }) {
if (!team.sharing) {
throw new AuthorizationError();
}
await share.update({ lastAccessedAt: new Date() });
} else {
document = await Document.findByPk(id, {
userId: user ? user.id : undefined,

View File

@@ -93,6 +93,9 @@ describe("#documents.info", () => {
expect(body.data.id).toEqual(document.id);
expect(body.data.createdBy).toEqual(undefined);
expect(body.data.updatedBy).toEqual(undefined);
await share.reload();
expect(share.lastAccessedAt).toBeTruthy();
});
it("should not return document from shareId if sharing is disabled for team", async () => {

View File

@@ -36,7 +36,7 @@ router.post("shares.info", auth(), async (ctx) => {
authorize(user, "read", share);
ctx.body = {
data: presentShare(share),
data: presentShare(share, user.isAdmin),
policies: presentPolicies(user, [share]),
};
});
@@ -89,7 +89,7 @@ router.post("shares.list", auth(), pagination(), async (ctx) => {
ctx.body = {
pagination: ctx.state.pagination,
data: shares.map(presentShare),
data: shares.map((share) => presentShare(share, user.isAdmin)),
policies: presentPolicies(user, shares),
};
});
@@ -117,7 +117,7 @@ router.post("shares.update", auth(), async (ctx) => {
});
ctx.body = {
data: presentShare(share),
data: presentShare(share, user.isAdmin),
policies: presentPolicies(user, [share]),
};
});