* fix: rename to group_permissions * fix: delete null collectionId records before setting non null constraint * fix: use scope with collectionId not null * fix: update model with documentId * fix: rename to GroupPermission * fix: rename collection_users to user_permissions * fix: teamPermanentDeleter test * fix: use scope with collectionId not null * fix: update model with documentId * fix: rename to UserPermission * fix: create views upon table rename for zero downtime * fix: remove comments
81 lines
1.6 KiB
TypeScript
81 lines
1.6 KiB
TypeScript
import { Op } from "sequelize";
|
|
import {
|
|
Column,
|
|
ForeignKey,
|
|
BelongsTo,
|
|
Default,
|
|
IsIn,
|
|
Table,
|
|
DataType,
|
|
Scopes,
|
|
} from "sequelize-typescript";
|
|
import { CollectionPermission } from "@shared/types";
|
|
import Collection from "./Collection";
|
|
import Document from "./Document";
|
|
import User from "./User";
|
|
import Model from "./base/Model";
|
|
import Fix from "./decorators/Fix";
|
|
|
|
@Scopes(() => ({
|
|
withUser: {
|
|
include: [
|
|
{
|
|
association: "user",
|
|
},
|
|
],
|
|
},
|
|
withCollection: {
|
|
include: [
|
|
{
|
|
model: Collection,
|
|
as: "collection",
|
|
where: {
|
|
collectionId: {
|
|
[Op.ne]: null,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
}))
|
|
@Table({ tableName: "user_permissions", modelName: "user_permission" })
|
|
@Fix
|
|
class UserPermission extends Model {
|
|
@Default(CollectionPermission.ReadWrite)
|
|
@IsIn([Object.values(CollectionPermission)])
|
|
@Column(DataType.STRING)
|
|
permission: CollectionPermission;
|
|
|
|
// associations
|
|
|
|
@BelongsTo(() => Collection, "collectionId")
|
|
collection?: Collection | null;
|
|
|
|
@ForeignKey(() => Collection)
|
|
@Column(DataType.UUID)
|
|
collectionId?: string | null;
|
|
|
|
@BelongsTo(() => Document, "documentId")
|
|
document?: Document | null;
|
|
|
|
@ForeignKey(() => Document)
|
|
@Column(DataType.UUID)
|
|
documentId?: string | null;
|
|
|
|
@BelongsTo(() => User, "userId")
|
|
user: User;
|
|
|
|
@ForeignKey(() => User)
|
|
@Column(DataType.UUID)
|
|
userId: string;
|
|
|
|
@BelongsTo(() => User, "createdById")
|
|
createdBy: User;
|
|
|
|
@ForeignKey(() => User)
|
|
@Column(DataType.UUID)
|
|
createdById: string;
|
|
}
|
|
|
|
export default UserPermission;
|