Add disableMentions option for individual groups (#10459)

* 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>
This commit is contained in:
codegen-sh[bot]andTom Moor authored and GitHub committed 2025-10-23 08:24:22 -04:00
1 parent 76691e8aaa
commit 77d50f8323
18 files changed
+118 -21

No files matched your search

+1
View File
@@ -58,6 +58,7 @@ function MentionMenu({ search, isActive, ...rest }: Props) {
res.data.documents.map(documents.add);
res.data.users.map(users.add);
res.data.collections.map(collections.add);
res.data.groups.map(groups.add);
}, [search, documents, users, collections])
);
+5
View File
@@ -89,6 +89,11 @@ export default class Document extends ArchivableModel implements Searchable {
return this.title;
}
@computed
get searchSuppressed(): boolean {
return this.isDeleted || this.isArchived;
}
/**
* The name of the original data source, if imported.
*/
+11 -1
View File
@@ -3,8 +3,9 @@ import GroupMembership from "./GroupMembership";
import Model from "./base/Model";
import Field from "./decorators/Field";
import { GroupPermission } from "@shared/types";
import { Searchable } from "./interfaces/Searchable";
class Group extends Model {
class Group extends Model implements Searchable {
static modelName = "Group";
@Field
@@ -17,6 +18,10 @@ class Group extends Model {
@observable
memberCount: number;
@Field
@observable
disableMentions: boolean;
/**
* Returns the users that are members of this group.
*/
@@ -31,6 +36,11 @@ class Group extends Model {
return [this.name].filter(Boolean);
}
@computed
get searchSuppressed(): boolean {
return this.disableMentions;
}
@computed
get admins() {
const { groupUsers } = this.store.rootStore;
+5
View File
@@ -105,6 +105,11 @@ class Share extends Model implements Searchable {
return [this.title];
}
@computed
get searchSuppressed(): boolean {
return false;
}
@computed
get sharedCache() {
return (
+5
View File
@@ -68,6 +68,11 @@ class User extends ParanoidModel implements Searchable {
return [this.name, this.email].filter(Boolean);
}
@computed
get searchSuppressed(): boolean {
return this.isDeleted;
}
@computed
get initial(): string {
return (this.name ? this.name[0] : "?").toUpperCase();
+2
View File
@@ -4,4 +4,6 @@
export interface Searchable {
/** The content to be used for search */
get searchContent(): string | string[];
get searchSuppressed(): boolean;
}
@@ -29,6 +29,7 @@ import InputMemberPermissionSelect from "~/components/InputMemberPermissionSelec
import { GroupPermission } from "@shared/types";
import { EmptySelectValue, Permission } from "~/types";
import GroupUser from "~/models/GroupUser";
import Switch from "~/components/Switch";
type Props = {
group: Group;
@@ -103,6 +104,9 @@ export function CreateGroupDialog() {
export function EditGroupDialog({ group, onSubmit }: Props) {
const { t } = useTranslation();
const [name, setName] = React.useState(group.name);
const [disableMentions, setDisableMentions] = React.useState(
group.disableMentions || false
);
const [isSaving, setIsSaving] = React.useState(false);
const handleSubmit = React.useCallback(
async (ev: React.SyntheticEvent) => {
@@ -112,6 +116,7 @@ export function EditGroupDialog({ group, onSubmit }: Props) {
try {
await group.save({
name,
disableMentions,
});
onSubmit();
} catch (err) {
@@ -120,7 +125,7 @@ export function EditGroupDialog({ group, onSubmit }: Props) {
setIsSaving(false);
}
},
[group, onSubmit, name]
[group, onSubmit, name, disableMentions]
);
const handleNameChange = React.useCallback(
@@ -138,7 +143,7 @@ export function EditGroupDialog({ group, onSubmit }: Props) {
often might confuse your team mates.
</Trans>
</Text>
<Flex>
<Flex column>
<Input
type="text"
label={t("Name")}
@@ -148,6 +153,15 @@ export function EditGroupDialog({ group, onSubmit }: Props) {
autoFocus
flex
/>
<Switch
id="mentions"
label={t("Disable mentions")}
note={t(
"Prevent this group from being mentionable in documents or comments"
)}
checked={disableMentions}
onChange={setDisableMentions}
/>
</Flex>
<Button type="submit" disabled={isSaving || !name}>
+2 -13
View File
@@ -101,24 +101,13 @@ export default abstract class Store<T extends Model> {
if (!normalized) {
return this.orderedData
.filter((item) => {
if ("deletedAt" in item && item.deletedAt) {
return false;
}
if ("archivedAt" in item && item.archivedAt) {
return false;
}
return true;
})
.filter((item: T & Searchable) => !item.searchSuppressed)
.slice(0, options?.maxResults);
}
return this.orderedData
.filter((item: T & Searchable) => {
if ("deletedAt" in item && item.deletedAt) {
return false;
}
if ("archivedAt" in item && item.archivedAt) {
if (item.searchSuppressed) {
return false;
}
if ("searchContent" in item) {
@@ -0,0 +1,16 @@
"use strict";
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.addColumn("groups", "disableMentions", {
type: Sequelize.BOOLEAN,
allowNull: false,
defaultValue: false,
});
},
async down(queryInterface, Sequelize) {
await queryInterface.removeColumn("groups", "disableMentions");
},
};
+3
View File
@@ -68,6 +68,9 @@ class Group extends ParanoidModel<
@Column
externalId: string;
@Column(DataType.BOOLEAN)
disableMentions: boolean;
static filterByMember(userId: string | undefined) {
return userId
? this.scope({ method: ["withMembership", userId] })
+1
View File
@@ -6,6 +6,7 @@ export default async function presentGroup(group: Group) {
name: group.name,
externalId: group.externalId,
memberCount: await group.memberCount,
disableMentions: group.disableMentions,
createdAt: group.createdAt,
updatedAt: group.updatedAt,
};
@@ -8,6 +8,7 @@ import { createContext } from "@server/context";
import {
Comment,
Document,
Group,
GroupUser,
Notification,
User,
@@ -96,6 +97,13 @@ export default class CommentCreatedNotificationsTask extends BaseTask<CommentEve
if (mentionedGroup.includes(group.modelId)) {
continue;
}
// Check if the group has mentions disabled
const groupModel = await Group.findByPk(group.modelId);
if (groupModel?.disableMentions) {
continue;
}
const usersFromMentionedGroup = await GroupUser.findAll({
where: {
groupId: group.modelId,
@@ -4,6 +4,7 @@ import { MentionType, NotificationEventType } from "@shared/types";
import {
Comment,
Document,
Group,
GroupUser,
Notification,
User,
@@ -86,6 +87,13 @@ export default class CommentUpdatedNotificationsTask extends BaseTask<CommentEve
if (mentionedGroup.includes(group.modelId)) {
continue;
}
// Check if the group has mentions disabled
const groupModel = await Group.findByPk(group.modelId);
if (groupModel?.disableMentions) {
continue;
}
const usersFromMentionedGroup = await GroupUser.findAll({
where: {
groupId: group.modelId,
@@ -1,6 +1,6 @@
import { MentionType, NotificationEventType } from "@shared/types";
import { createSubscriptionsForDocument } from "@server/commands/subscriptionCreator";
import { Document, Notification, User, GroupUser } from "@server/models";
import { Document, Group, Notification, User, GroupUser } from "@server/models";
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
import NotificationHelper from "@server/models/helpers/NotificationHelper";
import { DocumentEvent } from "@server/types";
@@ -59,6 +59,13 @@ export default class DocumentPublishedNotificationsTask extends BaseTask<Documen
if (mentionedGroup.includes(group.modelId)) {
continue;
}
// Check if the group has mentions disabled
const groupModel = await Group.findByPk(group.modelId);
if (groupModel?.disableMentions) {
continue;
}
const usersFromMentionedGroup = await GroupUser.findAll({
where: {
groupId: group.modelId,
+2 -1
View File
@@ -168,13 +168,14 @@ router.post(
validate(T.GroupsCreateSchema),
transaction(),
async (ctx: APIContext<T.GroupsCreateReq>) => {
const { name, externalId } = ctx.input.body;
const { name, externalId, disableMentions } = ctx.input.body;
const { user } = ctx.state.auth;
authorize(user, "createGroup", user.team);
const group = await Group.createWithCtx(ctx, {
name,
externalId,
disableMentions,
teamId: user.teamId,
createdById: user.id,
});
+4
View File
@@ -51,6 +51,8 @@ export const GroupsCreateSchema = z.object({
name: z.string(),
/** Optionally link this group to an external source. */
externalId: z.string().optional(),
/** Whether mentions are disabled for this group */
disableMentions: z.boolean().optional().default(false),
}),
});
@@ -62,6 +64,8 @@ export const GroupsUpdateSchema = z.object({
name: z.string().optional(),
/** Optionally link this group to an external source. */
externalId: z.string().optional(),
/** Whether mentions are disabled for this group */
disableMentions: z.boolean().optional(),
}),
});
+19 -3
View File
@@ -4,10 +4,10 @@ import { Sequelize } from "sequelize-typescript";
import { StatusFilter } from "@shared/types";
import auth from "@server/middlewares/authentication";
import validate from "@server/middlewares/validate";
import { User } from "@server/models";
import { Group, User } from "@server/models";
import SearchHelper from "@server/models/helpers/SearchHelper";
import { can } from "@server/policies";
import { presentDocument, presentUser } from "@server/presenters";
import { presentDocument, presentGroup, presentUser } from "@server/presenters";
import { APIContext } from "@server/types";
import pagination from "../middlewares/pagination";
import * as T from "./schema";
@@ -24,7 +24,7 @@ router.post(
const { offset, limit } = ctx.state.pagination;
const actor = ctx.state.auth.user;
const [documents, users, collections] = await Promise.all([
const [documents, users, groups, collections] = await Promise.all([
SearchHelper.searchTitlesForUser(actor, {
query,
offset,
@@ -55,6 +55,21 @@ router.post(
offset,
limit,
}),
Group.findAll({
where: {
teamId: actor.teamId,
disableMentions: false,
[Op.and]: query
? Sequelize.literal(
`unaccent(LOWER(name)) like unaccent(LOWER(:query))`
)
: {},
},
order: [["name", "ASC"]],
replacements: { query: `%${query}%` },
offset,
limit,
}),
SearchHelper.searchCollectionsForUser(actor, { query, offset, limit }),
]);
@@ -70,6 +85,7 @@ router.post(
includeDetails: !!can(actor, "readDetails", user),
})
),
groups: await Promise.all(groups.map((group) => presentGroup(group))),
collections,
},
};
@@ -998,6 +998,8 @@
"Groups are for organizing your team. They work best when centered around a function or a responsibility — Support or Engineering for example.": "Groups are for organizing your team. They work best when centered around a function or a responsibility — Support or Engineering for example.",
"You’ll be able to add people to the group next.": "You’ll be able to add people to the group next.",
"You can edit the name of this group at any time, however doing so too often might confuse your team mates.": "You can edit the name of this group at any time, however doing so too often might confuse your team mates.",
"Disable mentions": "Disable mentions",
"Prevent this group from being mentionable in documents or comments": "Prevent this group from being mentionable in documents or comments",
"Are you sure about that? Deleting the <em>{{groupName}}</em> group will cause its members to lose access to collections and documents that it is associated with.": "Are you sure about that? Deleting the <em>{{groupName}}</em> group will cause its members to lose access to collections and documents that it is associated with.",
"Add people to {{groupName}}": "Add people to {{groupName}}",
"{{userName}} was removed from the group": "{{userName}} was removed from the group",