import Column from "@entity-access/entity-access/dist/decorators/Column.js"; import type { UserRole } from "./UserRole.js"; import Table from "@entity-access/entity-access/dist/decorators/Table.js"; import type LoginSession from "./LoginSession.js"; import type DomainUser from "./DomainUser.js"; import type UserMailbox from "./UserMailbox.js"; import Index from "@entity-access/entity-access/dist/decorators/Index.js"; import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; import type UserAuthFactor from "./UserAuthFactor.js"; import type AppFile from "./AppFile.js"; import type { AppFileAccess, AppFileVersion } from "./AppFile.js"; import type UserPin from "./UserPin.js"; import type Contact from "./Contact.js"; import type { Email } from "./Email.js"; import type { WebSiteVersion } from "./WebSiteVersion.js"; import { JsonProperty, IgnoreJsonProperty, ReadOnlyJsonProperty } from "@entity-access/server-pages/dist/services/ModelService.js"; import type UserPushSubscription from "./UserSubscriptions.js"; import type AccessToken from "./AccessToken.js"; import { RelateTo } from "@entity-access/entity-access/dist/decorators/Relate.js"; import type { HostedZoneUser } from "./HostedZoneUser.js"; import type { StoreAccount } from "./StoreAccount.js"; import type UserGroupMember from "./UserGroupMember.js"; import type AppPassword from "./AppPassword.js"; import type Signature from "./Signature.js"; // import WebSite from "./WebSite.js"; export class ChangePassword { @JsonProperty() public oldPassword?: string; @JsonProperty() public newPassword: string; @JsonProperty() public forceChangePasswordOnLogin: boolean; } export const userStatuses = ["active", "blocked", "locked", "change-password", "external"] as const; export type userStatusType = typeof userStatuses[number]; @Table("Users") @Index({ name: "IX_Unique_UserName_V2", columns: [ { name: (x) => x.userName, descending: false }, { name: (x) => x.storeID, descending: false } ], unique: true, dropNames: ["IX_Unique_UserName"] }) @Index({ name: "IX_Unique_External_UID", columns: [{ name: (x) => x.externalUID, descending: false },], unique :true, filter: (x) => x.externalUID !== null }) @Index({ name: "IX_Unique_Users_PhoneNumber", columns: [ { name: (x) => x.uniquePhoneNumber, descending: false } ], unique: true, filter: (x) => x.uniquePhoneNumber !== null }) export class User { @Column({ key: true, dataType: "BigInt" , generated: "identity" }) public userID: number; @Column({ dataType: "Char" , length: 200 }) public userName: string; @Column({ dataType: "Char" , length: 200 }) public displayName: string; @Column({ dataType: "Char" }) @IgnoreJsonProperty public passwordHash: string; @Column({ dataType: "Char" , length: 20}) @IgnoreJsonProperty public passwordSalt: string; @Column({ dataType: "Char", length: 400, nullable: true}) public externalUID: string; @Column({ dataType: "AsciiChar", length: 15, default: () => "active", enum: userStatuses}) @ReadOnlyJsonProperty public status: userStatusType; @Column({ dataType: "Boolean", default: () => false}) public isExternal: boolean; @Column({ }) @JsonProperty({ readonly: true }) public multiFactor: boolean; @Column({}) public dateUpdated: DateTime; @Column({ dataType: "BigInt", default: () => 0, }) @ReadOnlyJsonProperty public storage: number; /** This is for external user who can signup and can have only one unique phone number */ @Column({ dataType: "Char", length: 20, nullable: true }) @IgnoreJsonProperty public uniquePhoneNumber: string; @Column({ dataType: "Char", length: 200, nullable: true }) public contactEmail: string; /** Used by Store only */ @Column({ dataType: "Char", length: 200, nullable: true }) public contactPhone: string; @Column({ dataType: "BigInt", default: () => 0 }) public maxStorage: number; @Column({ dataType: "BigInt", default: () => 0 }) public maxWebSites: number; @Column({ dataType: "BigInt", default: () => 0 }) public maxExternalInboxes: number; @Column({ dataType: "Int", nullable: true }) public maxMailboxes: number; @Column({ dataType: "Int", nullable: true }) public maxDrives: number; @Column({ dataType: "BigInt", default: () => 0 }) public maxChildUsers: number; @Column({ dataType: "BigInt", nullable: true}) @RelateTo(User, { property: (x) => x.parent, inverseProperty: (x) => x.children }) public parentID: number; @Column({ dataType: "BigInt", nullable: true}) // @RelateTo(WebSite, { // property: (x) => x.store, // inverseProperty: (x) => x.storeUsers // }) public storeID: number; @Column({ dataType: "Boolean", default: () => false }) public isGroup: boolean; @Column({ dataType: "DateTime", nullable: true}) public loginLockedTill: DateTime; @JsonProperty({ help: "Save this to change password"}) public changePassword: ChangePassword; @JsonProperty({}) public createFolder: boolean; @JsonProperty({}) public createWebSite: boolean; @JsonProperty({}) public domainName: string; @JsonProperty({}) public phoneNumber: string; @JsonProperty({}) public createWebSiteTemplateID: string; @JsonProperty({}) public autoEnableMF: boolean; public parent: User; public children: User[]; public roles: UserRole[]; public sessions: LoginSession[]; public domainUsers: DomainUser[]; public userMailboxes: UserMailbox[]; public authFactors: UserAuthFactor[]; public createdFiles: AppFile[]; public fileAccessList: AppFileAccess[]; public versions: AppFileVersion[]; public pins: UserPin[]; public contacts: Contact[]; public sentEmails: Email[]; public publishedWebSiteVersions: WebSiteVersion[]; public userPushSubscriptions: UserPushSubscription[]; public accessTokens: AccessToken[]; // storeOrders: StoreBill[]; // store: WebSite; closedEmails: Email[]; hostedZones: HostedZoneUser[]; storeAccounts: StoreAccount[]; groups: UserGroupMember[]; groupMembers: UserGroupMember[]; appPasswords: AppPassword[]; signatures: Signature[]; // [GraphService.toGraph]() { // return { // ... this, // password: void 0, // passwordHash: void 0, // passwordSalt: void 0 // }; // } }