Skip to content

Commit

Permalink
fix: Custom OAuth services can't be fully removed (#30212)
Browse files Browse the repository at this point in the history
Co-authored-by: Hugo Costa <20212776+hugocostadev@users.noreply.github.com>
  • Loading branch information
matheusbsilva137 and hugocostadev committed Sep 1, 2023
1 parent b8f3d50 commit 459c857
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-cars-divide.md
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed issue with custom OAuth services' settings not being be fully removed
1 change: 1 addition & 0 deletions apps/meteor/app/lib/server/methods/removeOAuthService.ts
Expand Up @@ -61,6 +61,7 @@ Meteor.methods<ServerMethods>({
Settings.removeById(`Accounts_OAuth_Custom-${name}-channels_admin`),
Settings.removeById(`Accounts_OAuth_Custom-${name}-map_channels`),
Settings.removeById(`Accounts_OAuth_Custom-${name}-groups_channel_map`),
Settings.removeById(`Accounts_OAuth_Custom-${name}-merge_users_distinct_services`),
]);
},
});
12 changes: 10 additions & 2 deletions apps/meteor/client/views/admin/settings/groups/OAuthGroupPage.tsx
@@ -1,8 +1,9 @@
import type { ISetting } from '@rocket.chat/core-typings';
import { Button } from '@rocket.chat/fuselage';
import { capitalize } from '@rocket.chat/string-helpers';
import { useToastMessageDispatch, useAbsoluteUrl, useMethod, useTranslation, useSetModal } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import React, { memo } from 'react';
import React, { memo, useEffect, useState } from 'react';

import { strRight } from '../../../../../lib/utils/stringUtils';
import GenericModal from '../../../../components/GenericModal';
Expand All @@ -18,6 +19,8 @@ function OAuthGroupPage({ _id, ...group }: OAuthGroupPageProps): ReactElement {
const solo = sections.length === 1;
const t = useTranslation();

const [settingSections, setSettingSections] = useState(sections);

const sectionIsCustomOAuth = (sectionName: string): string | boolean => sectionName && /^Custom OAuth:\s.+/.test(sectionName);

const getAbsoluteUrl = useAbsoluteUrl();
Expand Down Expand Up @@ -57,13 +60,18 @@ function OAuthGroupPage({ _id, ...group }: OAuthGroupPageProps): ReactElement {
setModal(<CreateOAuthModal onConfirm={onConfirm} onClose={(): void => setModal(null)} />);
};

useEffect(() => {
setSettingSections(sections);
}, [sections]);

const removeCustomOauthFactory =
(id: string): (() => void) =>
(): void => {
const handleConfirm = async (): Promise<void> => {
try {
await removeOAuthService(id);
dispatchToastMessage({ type: 'success', message: t('Custom_OAuth_has_been_removed') });
setSettingSections(settingSections.filter((section) => section !== `Custom OAuth: ${capitalize(id)}`));
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
} finally {
Expand Down Expand Up @@ -94,7 +102,7 @@ function OAuthGroupPage({ _id, ...group }: OAuthGroupPageProps): ReactElement {
</>
}
>
{sections.map((sectionName) => {
{settingSections.map((sectionName) => {
if (sectionIsCustomOAuth(sectionName)) {
const id = strRight(sectionName, 'Custom OAuth: ').toLowerCase();

Expand Down

0 comments on commit 459c857

Please sign in to comment.