mirror of
https://github.com/outline/outline.git
synced 2026-11-25 23:24:06 +03:00
- Collections can have owners, who also own every document in the collection, shown first in document bylines - Owner is a role in the collection share panel and invite picker for individual users, adding an owner gives them the manage permission - Lowering an owner's permission or removing their access removes the ownership - ownerIds on collections.create, collections.update and the MCP collection tools - The document owner filter includes documents in owned collections - Access requests go to document and collection owners together - Collection owners are subscribed to the collection and notified when they are added - Deleted users are removed from collection owners - Renames the personal collection policy helper to isPersonalCollectionOwner
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { NotificationEventType } from "@shared/types";
|
|
import { Collection, Notification, User } from "@server/models";
|
|
import { can } from "@server/policies";
|
|
import type { CollectionOwnerEvent } from "@server/types";
|
|
import { BaseTask, TaskPriority } from "./base/BaseTask";
|
|
|
|
/**
|
|
* Notification task that notifies a user when they are made an owner of a
|
|
* collection.
|
|
*/
|
|
export default class CollectionAddOwnerNotificationsTask extends BaseTask<CollectionOwnerEvent> {
|
|
public async perform(event: CollectionOwnerEvent) {
|
|
const recipient = await User.findByPk(event.userId);
|
|
if (
|
|
!recipient ||
|
|
recipient.isSuspended ||
|
|
!recipient.subscribedToEventType(
|
|
NotificationEventType.AddOwnerToCollection
|
|
)
|
|
) {
|
|
return;
|
|
}
|
|
|
|
const collection = await Collection.findByPk(event.collectionId, {
|
|
userId: recipient.id,
|
|
});
|
|
if (
|
|
!collection?.ownerIds?.includes(recipient.id) ||
|
|
!can(recipient, "read", collection)
|
|
) {
|
|
return;
|
|
}
|
|
|
|
await Notification.create({
|
|
event: NotificationEventType.AddOwnerToCollection,
|
|
userId: recipient.id,
|
|
actorId: event.actorId,
|
|
teamId: event.teamId,
|
|
collectionId: collection.id,
|
|
});
|
|
}
|
|
|
|
public get options() {
|
|
return {
|
|
priority: TaskPriority.Background,
|
|
};
|
|
}
|
|
}
|