Skip to content

Commit

Permalink
feat: Add flag to disable teams mention via troubleshoot (#30372)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Sep 12, 2023
1 parent 711bb92 commit 7137a19
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-bottles-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

feat: Add flag to disable teams mention via troubleshoot page
12 changes: 11 additions & 1 deletion apps/meteor/app/mentions/server/getMentionedTeamMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { Team } from '@rocket.chat/core-services';
import type { IMessage } from '@rocket.chat/core-typings';

import { callbacks } from '../../../lib/callbacks';
import { settings } from '../../settings/server';

interface IExtraDataForNotification {
userMentions: any[];
otherMentions: any[];
message: IMessage;
}

callbacks.add('beforeGetMentions', async (mentionIds: string[], extra?: IExtraDataForNotification) => {
const beforeGetMentions = async (mentionIds: string[], extra?: IExtraDataForNotification) => {
const { otherMentions } = extra ?? {};

const teamIds = otherMentions?.filter(({ type }) => type === 'team').map(({ _id }) => _id);
Expand All @@ -22,4 +23,13 @@ callbacks.add('beforeGetMentions', async (mentionIds: string[], extra?: IExtraDa
mentionIds.push(...new Set(members.map(({ userId }) => userId).filter((userId) => !mentionIds.includes(userId))));

return mentionIds;
};

settings.watch<boolean>('Troubleshoot_Disable_Teams_Mention', (value) => {
if (value) {
callbacks.remove('beforeGetMentions', 'before-get-mentions-get-teams');
return;
}

callbacks.add('beforeGetMentions', beforeGetMentions, callbacks.priority.MEDIUM, 'before-get-mentions-get-teams');
});
4 changes: 4 additions & 0 deletions apps/meteor/app/mentions/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export class MentionQueries {
type: 'user' as const,
}));

if (settings.get<boolean>('Troubleshoot_Disable_Teams_Mention')) {
return taggedUsers;
}

const taggedTeams = teams.map((team) => ({
...team,
type: 'team' as const,
Expand Down
2 changes: 2 additions & 0 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -5178,6 +5178,8 @@
"Troubleshoot_Disable_Statistics_Generator_Alert": "This setting stops the processing all statistics making the info page outdated until someone clicks on the refresh button and may cause other missing information around the system!",
"Troubleshoot_Disable_Workspace_Sync": "Disable Workspace Sync",
"Troubleshoot_Disable_Workspace_Sync_Alert": "This setting stops the sync of this server with Rocket.Chat's cloud and may cause issues with marketplace and enteprise licenses!",
"Troubleshoot_Disable_Teams_Mention": "Disable Teams mention",
"Troubleshoot_Disable_Teams_Mention_Alert": "This setting disables the teams mention feature. User's won't be able to mention a Team by name in a message and get its members notified.",
"True": "True",
"Try_now": "Try now",
"Try_searching_in_the_marketplace_instead": "Try searching in the Marketplace instead",
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/lib/spotlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class Spotlight {
}

async _searchTeams(userId, { text, options, users, mentions }) {
if (!mentions) {
if (!mentions || settings.get('Troubleshoot_Disable_Teams_Mention')) {
return users;
}

Expand Down
4 changes: 4 additions & 0 deletions apps/meteor/server/settings/troubleshoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ export const createTroubleshootSettings = () =>
type: 'boolean',
i18nDescription: 'Troubleshoot_Disable_Workspace_Sync_Alert',
});
await this.add('Troubleshoot_Disable_Teams_Mention', false, {
type: 'boolean',
i18nDescription: 'Troubleshoot_Disable_Teams_Mention_Alert',
});
});

0 comments on commit 7137a19

Please sign in to comment.