mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +03:00
* Add disableMentions option for groups - Add database migration to add disableMentions column to groups table - Update server-side Group model with new field - Add disableMentions to group create/update API schemas and endpoints - Update client-side Group model with new field - Add checkbox to EditGroupDialog for disabling mentions - Filter out groups with disableMentions=true from mention suggestions - Prevent notifications for groups with disabled mentions * Fix TypeScript error in GroupDialogs checkbox handler - Add properly typed handleDisableMentionsChange callback - Replace inline onChange handler with typed callback - Fixes TS2339 error: Property 'checked' does not exist on type 'EventTarget' * UI tweaks * Add groups to suggestions endpoint * Remove mentionableData --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom@getoutline.com>
110 lines
2.3 KiB
TypeScript
110 lines
2.3 KiB
TypeScript
import { InferAttributes, InferCreationAttributes, Op } from "sequelize";
|
|
import {
|
|
BelongsTo,
|
|
Column,
|
|
ForeignKey,
|
|
Table,
|
|
HasMany,
|
|
BelongsToMany,
|
|
DataType,
|
|
Scopes,
|
|
} from "sequelize-typescript";
|
|
import GroupMembership from "./GroupMembership";
|
|
import GroupUser from "./GroupUser";
|
|
import Team from "./Team";
|
|
import User from "./User";
|
|
import ParanoidModel from "./base/ParanoidModel";
|
|
import { CounterCache } from "./decorators/CounterCache";
|
|
import Fix from "./decorators/Fix";
|
|
import Length from "./validators/Length";
|
|
import NotContainsUrl from "./validators/NotContainsUrl";
|
|
|
|
@Scopes(() => ({
|
|
withMembership: (userId: string) => ({
|
|
include: [
|
|
{
|
|
association: "groupUsers",
|
|
required: true,
|
|
where: {
|
|
userId,
|
|
},
|
|
},
|
|
],
|
|
}),
|
|
}))
|
|
@Table({
|
|
tableName: "groups",
|
|
modelName: "group",
|
|
validate: {
|
|
async isUniqueNameInTeam() {
|
|
const foundItem = await Group.findOne({
|
|
where: {
|
|
teamId: this.teamId,
|
|
name: {
|
|
[Op.iLike]: this.name,
|
|
},
|
|
id: {
|
|
[Op.not]: this.id,
|
|
},
|
|
},
|
|
});
|
|
|
|
if (foundItem) {
|
|
throw new Error("The name of this group is already in use");
|
|
}
|
|
},
|
|
},
|
|
})
|
|
@Fix
|
|
class Group extends ParanoidModel<
|
|
InferAttributes<Group>,
|
|
Partial<InferCreationAttributes<Group>>
|
|
> {
|
|
@Length({ min: 0, max: 255, msg: "name must be be 255 characters or less" })
|
|
@NotContainsUrl
|
|
@Column
|
|
name: string;
|
|
|
|
@Column
|
|
externalId: string;
|
|
|
|
@Column(DataType.BOOLEAN)
|
|
disableMentions: boolean;
|
|
|
|
static filterByMember(userId: string | undefined) {
|
|
return userId
|
|
? this.scope({ method: ["withMembership", userId] })
|
|
: this.scope("defaultScope");
|
|
}
|
|
|
|
// associations
|
|
|
|
@HasMany(() => GroupUser, "groupId")
|
|
groupUsers: GroupUser[];
|
|
|
|
@HasMany(() => GroupMembership, "groupId")
|
|
groupMemberships: GroupMembership[];
|
|
|
|
@BelongsTo(() => Team, "teamId")
|
|
team: Team;
|
|
|
|
@ForeignKey(() => Team)
|
|
@Column(DataType.UUID)
|
|
teamId: string;
|
|
|
|
@BelongsTo(() => User, "createdById")
|
|
createdBy: User;
|
|
|
|
@ForeignKey(() => User)
|
|
@Column(DataType.UUID)
|
|
createdById: string;
|
|
|
|
@BelongsToMany(() => User, () => GroupUser)
|
|
users: User[];
|
|
|
|
@CounterCache(() => GroupUser, { as: "members", foreignKey: "groupId" })
|
|
memberCount: Promise<number>;
|
|
}
|
|
|
|
export default Group;
|