import { type EntityData, type EntityJson, type EntityPatch, type Options, type Selector, type SerializedEntityData } from '@nymphjs/nymph'; import AbleObject from './AbleObject.js'; import UserClass from './User.js'; import type { UserData } from './User.js'; export type GroupEventType = 'checkGroupname' | 'beforeSave' | 'afterSave' | 'beforeDelete' | 'afterDelete'; /** * This is run when the user has entered an otherwise valid groupname into the * signup form. It should return a result, which when false will stop the * process and return the included message, disallowing the groupname. */ export type TilmeldCheckGroupnameCallback = (group: Group & GroupData, data: { groupname: string; }) => Promise<{ result: boolean; message?: string; }>; /** * This is run just before the group is saved, so all checks have passed. * * The transaction is available in `group.$nymph`. */ export type TilmeldBeforeGroupSaveCallback = (group: Group & GroupData) => Promise; /** * This is run before the transaction is committed, and you can perform * additional functions on the transaction, which is available in * `group.$nymph`. */ export type TilmeldAfterGroupSaveCallback = (group: Group & GroupData) => Promise; /** * The transaction is available in `group.$nymph`. */ export type TilmeldBeforeGroupDeleteCallback = (group: Group & GroupData) => Promise; /** * This is run before the transaction is committed, and you can perform * additional functions on the transaction, which is available in * `group.$nymph`. */ export type TilmeldAfterGroupDeleteCallback = (group: Group & GroupData) => Promise; export type GroupData = { /** * The abilities granted to the group. */ abilities?: string[]; /** * The group's groupname. */ groupname?: string; /** * The group's name. */ name?: string; /** * The group's email address. */ email?: string; /** * The group's avatar URL. (Use getAvatar() to support Gravatar.) */ avatar?: string; /** * The group's telephone number. */ phone?: string; /** * The group's parent. */ parent?: Group & GroupData; /** * If generatePrimary is on, this will be the user who generated this group. */ user?: (UserClass & UserData) | null; /** * Whether the group can be used. */ enabled?: boolean; /** * Whether this group is the default primary group for new users. */ defaultPrimary?: boolean; /** * Whether this group is a default secondary group for new users. */ defaultSecondary?: boolean; /** * Whether this group is a default secondary group for unverified users. */ unverifiedSecondary?: boolean; }; /** * A user group data model. * * Written by Hunter Perrin for SciActive. * * @author Hunter Perrin * @copyright SciActive Inc * @see http://nymph.io/ */ export default class Group extends AbleObject { static ETYPE: string; static class: string; private static checkGroupnameCallbacks; private static beforeSaveCallbacks; private static afterSaveCallbacks; private static beforeDeleteCallbacks; private static afterDeleteCallbacks; private static DEFAULT_PRIVATE_DATA; private static DEFAULT_ALLOWLIST_DATA; protected $tags: never[]; protected $clientEnabledMethods: string[]; static clientEnabledStaticMethods: string[]; protected $privateData: string[]; static searchRestrictedData: string[]; protected $allowlistData?: string[] | undefined; protected $allowlistTags?: string[]; /** * This should only be used by the backend. */ private $skipAcWhenSaving; /** * This should only be used by the backend. */ private $skipAcWhenDeleting; /** * Used to save the current groupname for domain admin permissions. */ $originalGroupname?: string; static getFTSText(name: string, value: any): string | null; static factoryGroupname(groupname?: string): Promise; /** * Get all the groups that can be assigned as primary groups. * * @param options The options for an optional search query. * @param selectors The selectors for an optional search query. * @returns An array of the assignable primary groups. */ static getPrimaryGroups(options?: Options, selectors?: Selector[]): Promise<(Group & GroupData)[]>; /** * Get all the groups that can be assigned as secondary groups. * * @param options The options for an optional search query. * @param selectors The selectors for an optional search query. * @returns An array of the assignable secondary groups. */ static getSecondaryGroups(options?: Options, selectors?: Selector[]): Promise<(Group & GroupData)[]>; private static getAssignableGroups; constructor(); $getUniques(): Promise; $getAvatar(): string; $jsonAcceptData(input: EntityJson, allowConflict?: boolean): void; $jsonAcceptPatch(patch: EntityPatch, allowConflict?: boolean): void; private $checkIncomingAbilities; $putData(data: EntityData, sdata?: SerializedEntityData, source?: 'server'): void; /** * Update the data protection arrays for a user. * * @param givenUser User to update protection for. If undefined, will use the currently logged in user. */ $updateDataProtection(givenUser?: UserClass & UserData): void; /** * Check whether the group is a descendant of the given group. * * @param group The group, or the group's GUID. * @returns True or false. */ $isDescendant(givenGroup: (Group & GroupData) | string): Promise; /** * Gets an array of the group's child groups. * * @returns An array of groups. */ $getChildren(): Promise<(Group & GroupData)[]>; /** * Gets an array of the group's descendant groups. * * @param andSelf Include this group in the returned array. * @param andDisabled Include disabled groups. * @returns An array of groups. */ $getDescendants(andSelf?: boolean, andDisabled?: boolean): Promise<(Group & GroupData)[]>; /** * Get the number of parents the group has. * * If the group is a top level group, this will return 0. If it is a child of * a top level group, this will return 1. If it is a grandchild of a top level * group, this will return 2, and so on. * * Levels will max out at 1024 to avoid recursive loops. * * @returns The level of the group. */ $getLevel(): Promise; /** * Gets an array of enabled users in the group. * * @param descendants Include users in all descendant groups too. * @param limit The limit for the query. * @param offset The offset for the query. * @returns An array of users. */ $getUsers(descendants?: boolean, limit?: number, offset?: number): Promise<(UserClass & UserData)[]>; /** * Check that a groupname is valid. * * @returns An object with a boolean 'result' entry and a 'message' entry. */ $checkGroupname(): Promise<{ result: boolean; message: string; }>; /** * Check that an email is unique. * * @returns An object with a boolean 'result' entry and a 'message' entry. */ $checkEmail(): Promise<{ result: boolean; message: string; }>; $save(): Promise; $saveSkipAC(): Promise; $tilmeldSaveSkipAC(): boolean; $delete(): Promise; $deleteSkipAC(): Promise; $tilmeldDeleteSkipAC(): boolean; static on(event: T, callback: T extends 'checkGroupname' ? TilmeldCheckGroupnameCallback : T extends 'beforeSave' ? TilmeldBeforeGroupSaveCallback : T extends 'afterSave' ? TilmeldAfterGroupSaveCallback : T extends 'beforeDelete' ? TilmeldBeforeGroupDeleteCallback : T extends 'afterDelete' ? TilmeldAfterGroupDeleteCallback : never): () => boolean; static off(event: T, callback: T extends 'checkGroupname' ? TilmeldCheckGroupnameCallback : T extends 'beforeSave' ? TilmeldBeforeGroupSaveCallback : T extends 'afterSave' ? TilmeldAfterGroupSaveCallback : T extends 'beforeDelete' ? TilmeldBeforeGroupDeleteCallback : T extends 'afterDelete' ? TilmeldAfterGroupDeleteCallback : never): boolean; }