mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) move home server into core
Summary: This moves enough server material into core to run a home server. The data engine is not yet incorporated (though in manual testing it works when ported). Test Plan: existing tests pass Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2552
This commit is contained in:
54
app/gen-server/entity/User.ts
Normal file
54
app/gen-server/entity/User.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import {BaseEntity, Column, Entity, JoinTable, ManyToMany, OneToMany, OneToOne,
|
||||
PrimaryGeneratedColumn} from "typeorm";
|
||||
|
||||
import {Group} from "./Group";
|
||||
import {Login} from "./Login";
|
||||
import {Organization} from "./Organization";
|
||||
|
||||
@Entity({name: 'users'})
|
||||
export class User extends BaseEntity {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
public id: number;
|
||||
|
||||
@Column()
|
||||
public name: string;
|
||||
|
||||
@Column({name: 'api_key', type: String, nullable: true})
|
||||
// Found how to make a type nullable in this discussion: https://github.com/typeorm/typeorm/issues/2567
|
||||
// todo: adds constraint for api_key not to equal ''
|
||||
public apiKey: string | null;
|
||||
|
||||
@Column({name: 'picture', type: String, nullable: true})
|
||||
public picture: string | null;
|
||||
|
||||
@Column({name: 'first_login_at', type: Date, nullable: true})
|
||||
public firstLoginAt: Date | null;
|
||||
|
||||
@OneToOne(type => Organization, organization => organization.owner)
|
||||
public personalOrg: Organization;
|
||||
|
||||
@OneToMany(type => Login, login => login.user)
|
||||
public logins: Login[];
|
||||
|
||||
@ManyToMany(type => Group)
|
||||
@JoinTable({
|
||||
name: 'group_users',
|
||||
joinColumn: {name: 'user_id'},
|
||||
inverseJoinColumn: {name: 'group_id'}
|
||||
})
|
||||
public groups: Group[];
|
||||
|
||||
@Column({name: 'is_first_time_user', default: false})
|
||||
public isFirstTimeUser: boolean;
|
||||
|
||||
/**
|
||||
* Get user's email. Returns undefined if logins has not been joined, or no login
|
||||
* is available
|
||||
*/
|
||||
public get loginEmail(): string|undefined {
|
||||
const login = this.logins && this.logins[0];
|
||||
if (!login) { return undefined; }
|
||||
return login.email;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user