chore: Extend use of Event.createFromContext (#7010)
This commit is contained in:
@@ -31,16 +31,14 @@ router.post(
|
|||||||
{ transaction }
|
{ transaction }
|
||||||
);
|
);
|
||||||
|
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "api_keys.create",
|
name: "api_keys.create",
|
||||||
modelId: key.id,
|
modelId: key.id,
|
||||||
teamId: user.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
name,
|
name,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{ transaction }
|
{ transaction }
|
||||||
);
|
);
|
||||||
@@ -90,16 +88,14 @@ router.post(
|
|||||||
authorize(user, "delete", key);
|
authorize(user, "delete", key);
|
||||||
|
|
||||||
await key.destroy({ transaction });
|
await key.destroy({ transaction });
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "api_keys.delete",
|
name: "api_keys.delete",
|
||||||
modelId: key.id,
|
modelId: key.id,
|
||||||
teamId: user.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
name: key.name,
|
name: key.name,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{ transaction }
|
{ transaction }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -78,16 +78,14 @@ router.post(
|
|||||||
},
|
},
|
||||||
{ transaction }
|
{ transaction }
|
||||||
);
|
);
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "attachments.create",
|
name: "attachments.create",
|
||||||
data: {
|
data: {
|
||||||
name,
|
name,
|
||||||
},
|
},
|
||||||
modelId,
|
modelId,
|
||||||
teamId: user.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{ transaction }
|
{ transaction }
|
||||||
);
|
);
|
||||||
@@ -141,11 +139,8 @@ router.post(
|
|||||||
|
|
||||||
authorize(user, "delete", attachment);
|
authorize(user, "delete", attachment);
|
||||||
await attachment.destroy();
|
await attachment.destroy();
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "attachments.delete",
|
name: "attachments.delete",
|
||||||
teamId: user.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
|
|||||||
@@ -163,16 +163,14 @@ router.post(
|
|||||||
const { user } = auth;
|
const { user } = auth;
|
||||||
|
|
||||||
await user.rotateJwtSecret({ transaction });
|
await user.rotateJwtSecret({ transaction });
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "users.signout",
|
name: "users.signout",
|
||||||
actorId: user.id,
|
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId: user.teamId,
|
|
||||||
data: {
|
data: {
|
||||||
name: user.name,
|
name: user.name,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
transaction,
|
transaction,
|
||||||
|
|||||||
@@ -57,16 +57,14 @@ router.post(
|
|||||||
await authenticationProvider.disable({ transaction });
|
await authenticationProvider.disable({ transaction });
|
||||||
}
|
}
|
||||||
|
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "authenticationProviders.update",
|
name: "authenticationProviders.update",
|
||||||
data: {
|
data: {
|
||||||
enabled,
|
enabled,
|
||||||
},
|
},
|
||||||
modelId: id,
|
modelId: id,
|
||||||
teamId: user.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{ transaction }
|
{ transaction }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -103,16 +103,14 @@ router.post(
|
|||||||
|
|
||||||
await collection.save({ transaction });
|
await collection.save({ transaction });
|
||||||
|
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "collections.create",
|
name: "collections.create",
|
||||||
collectionId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
name,
|
name,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
transaction,
|
transaction,
|
||||||
@@ -208,11 +206,10 @@ router.post(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "fileOperations.create",
|
name: "fileOperations.create",
|
||||||
teamId: user.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
modelId: fileOperation.id,
|
modelId: fileOperation.id,
|
||||||
data: {
|
data: {
|
||||||
type: FileOperationType.Import,
|
type: FileOperationType.Import,
|
||||||
@@ -264,17 +261,14 @@ router.post(
|
|||||||
await membership.save();
|
await membership.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "collections.add_group",
|
name: "collections.add_group",
|
||||||
collectionId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
modelId: groupId,
|
modelId: groupId,
|
||||||
data: {
|
data: {
|
||||||
name: group.name,
|
name: group.name,
|
||||||
membershipId: membership.id,
|
membershipId: membership.id,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
@@ -315,18 +309,16 @@ router.post(
|
|||||||
}
|
}
|
||||||
|
|
||||||
await collection.$remove("group", group);
|
await collection.$remove("group", group);
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "collections.remove_group",
|
name: "collections.remove_group",
|
||||||
collectionId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
modelId: groupId,
|
modelId: groupId,
|
||||||
data: {
|
data: {
|
||||||
name: group.name,
|
name: group.name,
|
||||||
membershipId: membership.id,
|
membershipId: membership.id,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{ transaction }
|
{ transaction }
|
||||||
);
|
);
|
||||||
@@ -439,19 +431,17 @@ router.post(
|
|||||||
await membership.save({ transaction });
|
await membership.save({ transaction });
|
||||||
}
|
}
|
||||||
|
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "collections.add_user",
|
name: "collections.add_user",
|
||||||
userId,
|
userId,
|
||||||
modelId: membership.id,
|
modelId: membership.id,
|
||||||
collectionId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
|
||||||
actorId: actor.id,
|
|
||||||
data: {
|
data: {
|
||||||
isNew,
|
isNew,
|
||||||
permission: membership.permission,
|
permission: membership.permission,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
transaction,
|
transaction,
|
||||||
@@ -495,18 +485,16 @@ router.post(
|
|||||||
|
|
||||||
await collection.$remove("user", user, { transaction });
|
await collection.$remove("user", user, { transaction });
|
||||||
|
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "collections.remove_user",
|
name: "collections.remove_user",
|
||||||
userId,
|
userId,
|
||||||
modelId: membership.id,
|
modelId: membership.id,
|
||||||
collectionId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
|
||||||
actorId: actor.id,
|
|
||||||
data: {
|
data: {
|
||||||
name: user.name,
|
name: user.name,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{ transaction }
|
{ transaction }
|
||||||
);
|
);
|
||||||
@@ -737,16 +725,14 @@ router.post(
|
|||||||
}
|
}
|
||||||
|
|
||||||
await collection.save({ transaction });
|
await collection.save({ transaction });
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "collections.update",
|
name: "collections.update",
|
||||||
collectionId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
name,
|
name,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
transaction,
|
transaction,
|
||||||
@@ -754,17 +740,15 @@ router.post(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (privacyChanged || sharingChanged) {
|
if (privacyChanged || sharingChanged) {
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "collections.permission_changed",
|
name: "collections.permission_changed",
|
||||||
collectionId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
privacyChanged,
|
privacyChanged,
|
||||||
sharingChanged,
|
sharingChanged,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
transaction,
|
transaction,
|
||||||
@@ -912,16 +896,14 @@ router.post(
|
|||||||
transaction,
|
transaction,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "collections.move",
|
name: "collections.move",
|
||||||
collectionId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
index,
|
index,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
transaction,
|
transaction,
|
||||||
|
|||||||
@@ -681,31 +681,25 @@ router.post(
|
|||||||
authorize(user, "restore", document);
|
authorize(user, "restore", document);
|
||||||
// restore a previously deleted document
|
// restore a previously deleted document
|
||||||
await document.unarchive(user.id);
|
await document.unarchive(user.id);
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "documents.restore",
|
name: "documents.restore",
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
collectionId: document.collectionId,
|
collectionId: document.collectionId,
|
||||||
teamId: document.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
title: document.title,
|
title: document.title,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
} else if (document.archivedAt) {
|
} else if (document.archivedAt) {
|
||||||
authorize(user, "unarchive", document);
|
authorize(user, "unarchive", document);
|
||||||
// restore a previously archived document
|
// restore a previously archived document
|
||||||
await document.unarchive(user.id);
|
await document.unarchive(user.id);
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "documents.unarchive",
|
name: "documents.unarchive",
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
collectionId: document.collectionId,
|
collectionId: document.collectionId,
|
||||||
teamId: document.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
title: document.title,
|
title: document.title,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
} else if (revisionId) {
|
} else if (revisionId) {
|
||||||
// restore a document to a specific revision
|
// restore a document to a specific revision
|
||||||
@@ -716,16 +710,13 @@ router.post(
|
|||||||
document.restoreFromRevision(revision);
|
document.restoreFromRevision(revision);
|
||||||
await document.save();
|
await document.save();
|
||||||
|
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "documents.restore",
|
name: "documents.restore",
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
collectionId: document.collectionId,
|
collectionId: document.collectionId,
|
||||||
teamId: document.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
title: document.title,
|
title: document.title,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
assertPresent(revisionId, "revisionId is required");
|
assertPresent(revisionId, "revisionId is required");
|
||||||
@@ -960,18 +951,16 @@ router.post(
|
|||||||
transaction,
|
transaction,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "documents.create",
|
name: "documents.create",
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
collectionId: document.collectionId,
|
collectionId: document.collectionId,
|
||||||
teamId: document.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
title: document.title,
|
title: document.title,
|
||||||
template: true,
|
template: true,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
transaction,
|
transaction,
|
||||||
@@ -1195,16 +1184,13 @@ router.post(
|
|||||||
authorize(user, "archive", document);
|
authorize(user, "archive", document);
|
||||||
|
|
||||||
await document.archive(user.id);
|
await document.archive(user.id);
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "documents.archive",
|
name: "documents.archive",
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
collectionId: document.collectionId,
|
collectionId: document.collectionId,
|
||||||
teamId: document.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
title: document.title,
|
title: document.title,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
@@ -1230,16 +1216,13 @@ router.post(
|
|||||||
authorize(user, "permanentDelete", document);
|
authorize(user, "permanentDelete", document);
|
||||||
|
|
||||||
await documentPermanentDeleter([document]);
|
await documentPermanentDeleter([document]);
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "documents.permanent_delete",
|
name: "documents.permanent_delete",
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
collectionId: document.collectionId,
|
collectionId: document.collectionId,
|
||||||
teamId: document.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
title: document.title,
|
title: document.title,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const document = await Document.findByPk(id, {
|
const document = await Document.findByPk(id, {
|
||||||
@@ -1249,16 +1232,13 @@ router.post(
|
|||||||
authorize(user, "delete", document);
|
authorize(user, "delete", document);
|
||||||
|
|
||||||
await document.delete(user.id);
|
await document.delete(user.id);
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "documents.delete",
|
name: "documents.delete",
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
collectionId: document.collectionId,
|
collectionId: document.collectionId,
|
||||||
teamId: document.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
title: document.title,
|
title: document.title,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1293,16 +1273,13 @@ router.post(
|
|||||||
}
|
}
|
||||||
|
|
||||||
await document.unpublish(user.id);
|
await document.unpublish(user.id);
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "documents.unpublish",
|
name: "documents.unpublish",
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
collectionId: document.collectionId,
|
collectionId: document.collectionId,
|
||||||
teamId: document.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
title: document.title,
|
title: document.title,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
@@ -1550,15 +1527,13 @@ router.post(
|
|||||||
await membership.save({ transaction });
|
await membership.save({ transaction });
|
||||||
}
|
}
|
||||||
|
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "documents.add_user",
|
name: "documents.add_user",
|
||||||
userId,
|
userId,
|
||||||
modelId: membership.id,
|
modelId: membership.id,
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
teamId: document.teamId,
|
|
||||||
actorId: actor.id,
|
|
||||||
ip: ctx.request.ip,
|
|
||||||
data: {
|
data: {
|
||||||
title: document.title,
|
title: document.title,
|
||||||
isNew,
|
isNew,
|
||||||
@@ -1618,15 +1593,13 @@ router.post(
|
|||||||
|
|
||||||
await membership.destroy({ transaction });
|
await membership.destroy({ transaction });
|
||||||
|
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "documents.remove_user",
|
name: "documents.remove_user",
|
||||||
userId,
|
userId,
|
||||||
modelId: membership.id,
|
modelId: membership.id,
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
teamId: document.teamId,
|
|
||||||
actorId: actor.id,
|
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{ transaction }
|
{ transaction }
|
||||||
);
|
);
|
||||||
@@ -1736,11 +1709,8 @@ router.post(
|
|||||||
});
|
});
|
||||||
|
|
||||||
await documentPermanentDeleter(documents);
|
await documentPermanentDeleter(documents);
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "documents.empty_trash",
|
name: "documents.empty_trash",
|
||||||
teamId: user.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
|
|||||||
@@ -105,15 +105,12 @@ router.post(
|
|||||||
// reload to get default scope
|
// reload to get default scope
|
||||||
const group = await Group.findByPk(g.id, { rejectOnEmpty: true });
|
const group = await Group.findByPk(g.id, { rejectOnEmpty: true });
|
||||||
|
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "groups.create",
|
name: "groups.create",
|
||||||
actorId: user.id,
|
|
||||||
teamId: user.teamId,
|
|
||||||
modelId: group.id,
|
modelId: group.id,
|
||||||
data: {
|
data: {
|
||||||
name: group.name,
|
name: group.name,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
@@ -138,15 +135,12 @@ router.post(
|
|||||||
|
|
||||||
if (group.changed()) {
|
if (group.changed()) {
|
||||||
await group.save();
|
await group.save();
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "groups.update",
|
name: "groups.update",
|
||||||
teamId: user.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
modelId: group.id,
|
modelId: group.id,
|
||||||
data: {
|
data: {
|
||||||
name,
|
name,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,15 +163,12 @@ router.post(
|
|||||||
authorize(user, "delete", group);
|
authorize(user, "delete", group);
|
||||||
|
|
||||||
await group.destroy();
|
await group.destroy();
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "groups.delete",
|
name: "groups.delete",
|
||||||
actorId: user.id,
|
|
||||||
modelId: group.id,
|
modelId: group.id,
|
||||||
teamId: group.teamId,
|
|
||||||
data: {
|
data: {
|
||||||
name: group.name,
|
name: group.name,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
@@ -275,16 +266,13 @@ router.post(
|
|||||||
// reload to get default scope
|
// reload to get default scope
|
||||||
group = await Group.findByPk(id, { rejectOnEmpty: true });
|
group = await Group.findByPk(id, { rejectOnEmpty: true });
|
||||||
|
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "groups.add_user",
|
name: "groups.add_user",
|
||||||
userId,
|
userId,
|
||||||
teamId: user.teamId,
|
|
||||||
modelId: group.id,
|
modelId: group.id,
|
||||||
actorId: actor.id,
|
|
||||||
data: {
|
data: {
|
||||||
name: user.name,
|
name: user.name,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,16 +303,13 @@ router.post(
|
|||||||
authorize(actor, "read", user);
|
authorize(actor, "read", user);
|
||||||
|
|
||||||
await group.$remove("user", user);
|
await group.$remove("user", user);
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "groups.remove_user",
|
name: "groups.remove_user",
|
||||||
userId,
|
userId,
|
||||||
modelId: group.id,
|
modelId: group.id,
|
||||||
teamId: user.teamId,
|
|
||||||
actorId: actor.id,
|
|
||||||
data: {
|
data: {
|
||||||
name: user.name,
|
name: user.name,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// reload to get default scope
|
// reload to get default scope
|
||||||
|
|||||||
@@ -157,13 +157,11 @@ router.post(
|
|||||||
|
|
||||||
await integration.destroy({ transaction });
|
await integration.destroy({ transaction });
|
||||||
|
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "integrations.delete",
|
name: "integrations.delete",
|
||||||
modelId: integration.id,
|
modelId: integration.id,
|
||||||
teamId: integration.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{ transaction }
|
{ transaction }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -200,20 +200,17 @@ router.post(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (isCreated) {
|
if (isCreated) {
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "shares.create",
|
name: "shares.create",
|
||||||
documentId,
|
documentId,
|
||||||
collectionId: document.collectionId,
|
collectionId: document.collectionId,
|
||||||
modelId: share.id,
|
modelId: share.id,
|
||||||
teamId: user.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
name: document.title,
|
name: document.title,
|
||||||
published,
|
published,
|
||||||
includeChildDocuments,
|
includeChildDocuments,
|
||||||
urlId,
|
urlId,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,16 +258,13 @@ router.post(
|
|||||||
}
|
}
|
||||||
|
|
||||||
await share.save();
|
await share.save();
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "shares.update",
|
name: "shares.update",
|
||||||
documentId: share.documentId,
|
documentId: share.documentId,
|
||||||
modelId: share.id,
|
modelId: share.id,
|
||||||
teamId: user.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
published,
|
published,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
@@ -297,17 +291,14 @@ router.post(
|
|||||||
const { document } = share;
|
const { document } = share;
|
||||||
|
|
||||||
await share.revoke(user.id);
|
await share.revoke(user.id);
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "shares.revoke",
|
name: "shares.revoke",
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
collectionId: document.collectionId,
|
collectionId: document.collectionId,
|
||||||
modelId: share.id,
|
modelId: share.id,
|
||||||
teamId: user.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
data: {
|
data: {
|
||||||
name: document.title,
|
name: document.title,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
|
|||||||
@@ -90,15 +90,13 @@ router.post(
|
|||||||
membership.index = index;
|
membership.index = index;
|
||||||
await membership.save({ transaction });
|
await membership.save({ transaction });
|
||||||
|
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name: "userMemberships.update",
|
name: "userMemberships.update",
|
||||||
modelId: membership.id,
|
modelId: membership.id,
|
||||||
userId: membership.userId,
|
userId: membership.userId,
|
||||||
teamId: user.teamId,
|
|
||||||
actorId: user.id,
|
|
||||||
documentId: membership.documentId,
|
documentId: membership.documentId,
|
||||||
ip: ctx.request.ip,
|
|
||||||
data: {
|
data: {
|
||||||
index: membership.index,
|
index: membership.index,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -335,17 +335,15 @@ async function updateRole(ctx: APIContext<T.UsersChangeRoleReq>) {
|
|||||||
|
|
||||||
await user.update({ role }, { transaction });
|
await user.update({ role }, { transaction });
|
||||||
|
|
||||||
await Event.create(
|
await Event.createFromContext(
|
||||||
|
ctx,
|
||||||
{
|
{
|
||||||
name,
|
name,
|
||||||
userId,
|
userId,
|
||||||
actorId: actor.id,
|
|
||||||
teamId: actor.teamId,
|
|
||||||
data: {
|
data: {
|
||||||
name: user.name,
|
name: user.name,
|
||||||
role,
|
role,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
transaction,
|
transaction,
|
||||||
|
|||||||
@@ -56,17 +56,14 @@ router.post(
|
|||||||
userId: user.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
await Event.create({
|
await Event.createFromContext(ctx, {
|
||||||
name: "views.create",
|
name: "views.create",
|
||||||
actorId: user.id,
|
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
collectionId: document.collectionId,
|
collectionId: document.collectionId,
|
||||||
teamId: user.teamId,
|
|
||||||
modelId: view.id,
|
modelId: view.id,
|
||||||
data: {
|
data: {
|
||||||
title: document.title,
|
title: document.title,
|
||||||
},
|
},
|
||||||
ip: ctx.request.ip,
|
|
||||||
});
|
});
|
||||||
view.user = user;
|
view.user = user;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user