Files
outline/server/queues/tasks/CollectionCreatedNotificationsTask.ts
Tom Moor d8b4fef554 feat: Collection admins (#5273
* Split permissions for reading documents from updating collection

* fix: Admins should have collection read permission, tests

* tsc

* Add admin option to permission selector

* Combine publish and create permissions, update -> createDocuments where appropriate

* Plural -> singular

* wip

* Quick version of collection structure loading, will revisit

* Remove documentIds method

* stash

* fixing tests to account for admin creation

* Add self-hosted migration

* fix: Allow groups to have admin permission

* Prefetch collection documents

* fix: Document explorer (move/publish) not working with async documents

* fix: Cannot re-parent document to collection by drag and drop

* fix: Cannot drag to import into collection item without admin permission

* Remove unused isEditor getter
2023-04-30 06:38:47 -07:00

45 lines
1.3 KiB
TypeScript

import { NotificationEventType } from "@shared/types";
import { Collection, Notification } from "@server/models";
import NotificationHelper from "@server/models/helpers/NotificationHelper";
import { CollectionEvent } from "@server/types";
import BaseTask, { TaskPriority } from "./BaseTask";
export default class CollectionCreatedNotificationsTask extends BaseTask<
CollectionEvent
> {
public async perform(event: CollectionEvent) {
const collection = await Collection.findByPk(event.collectionId);
// We only send notifications for collections visible to the entire team
if (!collection || collection.isPrivate) {
return;
}
const recipients = await NotificationHelper.getCollectionNotificationRecipients(
collection,
NotificationEventType.CreateCollection
);
for (const recipient of recipients) {
// Suppress notifications for suspended users
if (recipient.isSuspended || !recipient.email) {
continue;
}
await Notification.create({
event: NotificationEventType.CreateCollection,
userId: recipient.id,
collectionId: collection.id,
actorId: collection.createdById,
teamId: collection.teamId,
});
}
}
public get options() {
return {
priority: TaskPriority.Background,
};
}
}