mirror of
https://github.com/outline/outline.git
synced 2026-11-22 14:01:41 +03:00
* Upgrade Mobx * fix: Enforce MobX action boundaries * fix: Wrap static observable updates in actions * Remove iteration tests
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
import { observable } from "mobx";
|
|
import type { CollectionPermission, DocumentPermission } from "@shared/types";
|
|
import Collection from "./Collection";
|
|
import Document from "./Document";
|
|
import Group from "./Group";
|
|
import Relation from "./decorators/Relation";
|
|
import NavigableModel from "./base/NavigableModel";
|
|
|
|
/**
|
|
* Represents a groups's membership to a collection or document.
|
|
*/
|
|
class GroupMembership extends NavigableModel {
|
|
static modelName = "GroupMembership";
|
|
|
|
constructor(fields: Record<string, unknown>, store: NavigableModel["store"]) {
|
|
super(fields, store);
|
|
this.initialize(fields);
|
|
}
|
|
|
|
/** The group ID that this membership is granted to. */
|
|
groupId: string;
|
|
|
|
/** The group that this membership is granted to. */
|
|
@Relation(() => Group, { onDelete: "cascade" })
|
|
group: Group;
|
|
|
|
/** The document that this membership grants the group access to. */
|
|
@Relation(() => Document, { onDelete: "cascade" })
|
|
document: Document | undefined;
|
|
|
|
/** The collection ID that this membership grants the group access to. */
|
|
collectionId: string | undefined;
|
|
|
|
/** The collection that this membership grants the group access to. */
|
|
@Relation(() => Collection, { onDelete: "cascade" })
|
|
collection: Collection | undefined;
|
|
|
|
/** The source ID points to the root membership from which this inherits */
|
|
sourceId?: string;
|
|
|
|
/** The source points to the root membership from which this inherits */
|
|
@Relation(() => GroupMembership, { onDelete: "cascade" })
|
|
source?: GroupMembership;
|
|
|
|
/** The permission level granted to the group. */
|
|
@observable
|
|
permission: CollectionPermission | DocumentPermission;
|
|
|
|
// methods
|
|
/**
|
|
* Fetches the child documents structure from the server.
|
|
*/
|
|
async fetchDocuments(options: { force?: boolean } = {}) {
|
|
if (!this.documentId) {
|
|
return;
|
|
}
|
|
|
|
await super.fetchDocuments({
|
|
path: "/documents.documents",
|
|
params: { id: this.documentId },
|
|
...options,
|
|
});
|
|
}
|
|
}
|
|
|
|
export default GroupMembership;
|