fix: Custom OAuth services can't be fully removed (#30212)

Co-authored-by: Hugo Costa <20212776+hugocostadev@users.noreply.github.com>
pull/30202/head^2
Matheus Barbosa Silva 2 years ago committed by GitHub
parent b8f3d5014f
commit 459c8574ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      .changeset/fifty-cars-divide.md
  2. 1
      apps/meteor/app/lib/server/methods/removeOAuthService.ts
  3. 12
      apps/meteor/client/views/admin/settings/groups/OAuthGroupPage.tsx

@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---
Fixed issue with custom OAuth services' settings not being be fully removed

@ -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`),
]);
},
});

@ -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';
@ -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();
@ -57,6 +60,10 @@ function OAuthGroupPage({ _id, ...group }: OAuthGroupPageProps): ReactElement {
setModal(<CreateOAuthModal onConfirm={onConfirm} onClose={(): void => setModal(null)} />);
};
useEffect(() => {
setSettingSections(sections);
}, [sections]);
const removeCustomOauthFactory =
(id: string): (() => void) =>
(): void => {
@ -64,6 +71,7 @@ function OAuthGroupPage({ _id, ...group }: OAuthGroupPageProps): ReactElement {
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 {
@ -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();

Loading…
Cancel
Save