diff --git a/app/src/common/urls.js b/app/src/common/urls.js index 6d277a057c..ee010d5439 100644 --- a/app/src/common/urls.js +++ b/app/src/common/urls.js @@ -311,4 +311,5 @@ export const URLS = { clusterByLaunchId: (activeProject, launchId, query) => `${urlBase}${activeProject}/launch/cluster/${launchId}${getQueryParams(query)}`, onboarding: (page = 'GENERAL') => `${urlBase}onboarding?page=${page}`, + ssoSettings: () => `${urlBase}settings`, }; diff --git a/app/src/components/inputs/inputUserSearch/inputUserSearch.jsx b/app/src/components/inputs/inputUserSearch/inputUserSearch.jsx index 4d1cba8509..d7095786ea 100644 --- a/app/src/components/inputs/inputUserSearch/inputUserSearch.jsx +++ b/app/src/components/inputs/inputUserSearch/inputUserSearch.jsx @@ -65,7 +65,7 @@ export const InputUserSearch = ({ error, touched, placeholder, - ssoUsersOnly, + creatable, }) => ( ); @@ -93,8 +93,9 @@ InputUserSearch.propTypes = { value: PropTypes.object, error: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]), touched: PropTypes.bool, - ssoUsersOnly: PropTypes.bool, + creatable: PropTypes.bool, }; + InputUserSearch.defaultProps = { isAdmin: false, projectId: '', @@ -103,5 +104,5 @@ InputUserSearch.defaultProps = { value: null, error: false, touched: false, - ssoUsersOnly: false, + creatable: true, }; diff --git a/app/src/pages/admin/serverSettingsPage/serverSettingsTabs/authConfigurationTab/forms/ssoUsersForm/ssoUsersForm.jsx b/app/src/pages/admin/serverSettingsPage/serverSettingsTabs/authConfigurationTab/forms/ssoUsersForm/ssoUsersForm.jsx index 138ad90ad2..6aa6b98abe 100644 --- a/app/src/pages/admin/serverSettingsPage/serverSettingsTabs/authConfigurationTab/forms/ssoUsersForm/ssoUsersForm.jsx +++ b/app/src/pages/admin/serverSettingsPage/serverSettingsTabs/authConfigurationTab/forms/ssoUsersForm/ssoUsersForm.jsx @@ -15,10 +15,9 @@ */ import React, { useEffect, useState } from 'react'; -import PropTypes from 'prop-types'; import { defineMessages, useIntl } from 'react-intl'; import classNames from 'classnames/bind'; -import { connect } from 'react-redux'; +import { useSelector, useDispatch } from 'react-redux'; import { InputBigSwitcher } from 'components/inputs/inputBigSwitcher'; import { SectionHeader } from 'components/main/sectionHeader'; import { ADMIN_SERVER_SETTINGS_PAGE_EVENTS } from 'components/main/analytics/events'; @@ -26,7 +25,7 @@ import { ssoUsersOnlySelector, fetchAppInfoAction } from 'controllers/appInfo'; import { showSuccessNotification, showErrorNotification } from 'controllers/notification'; import formStyles from 'pages/admin/serverSettingsPage/common/formController/formController.scss'; import { fetch } from 'common/utils/fetch'; -import { tokenSelector } from 'controllers/auth'; +import { URLS } from 'common/urls'; import styles from './ssoUsersForm.scss'; const formCx = classNames.bind(formStyles); @@ -60,20 +59,16 @@ const messages = defineMessages({ }, }); -const SsoUsersFormComponent = ({ - enabled: enabledFromStore, - fetchAppInfo, - token, - dispatchShowSuccessNotification, - dispatchShowErrorNotification, -}) => { +export const SsoUsersForm = () => { const { formatMessage } = useIntl(); + const dispatch = useDispatch(); + const enabledFromStore = useSelector(ssoUsersOnlySelector); const [enabled, setEnabled] = useState(enabledFromStore); const inputId = 'ssoUsersToggle'; useEffect(() => { - fetchAppInfo(); - }, [fetchAppInfo]); + dispatch(fetchAppInfoAction()); + }, [dispatch]); useEffect(() => { setEnabled(enabledFromStore); @@ -83,25 +78,22 @@ const SsoUsersFormComponent = ({ formatMessage(enabled ? messages.ssoOnlyDescription : messages.manualInvitesDescription); const handleToggle = async (value) => { + setEnabled(value); + try { - await fetch('/api/v1/settings', { + await fetch(URLS.ssoSettings(), { method: 'PUT', - headers: { - 'Content-Type': 'application/json', - Authorization: token, - }, data: { key: 'server.users.sso', value: value.toString(), }, }); - await fetchAppInfo(); - setEnabled(value); - dispatchShowSuccessNotification(formatMessage(messages.successNotification)); + await dispatch(fetchAppInfoAction()); + dispatch(showSuccessNotification({ message: formatMessage(messages.successNotification) })); } catch (error) { - dispatchShowErrorNotification(formatMessage(messages.errorNotification)); setEnabled(!value); + dispatch(showErrorNotification({ message: formatMessage(messages.errorNotification) })); } }; @@ -134,28 +126,3 @@ const SsoUsersFormComponent = ({ ); }; - -SsoUsersFormComponent.propTypes = { - enabled: PropTypes.bool, - fetchAppInfo: PropTypes.func.isRequired, - token: PropTypes.string.isRequired, - dispatchShowSuccessNotification: PropTypes.func.isRequired, - dispatchShowErrorNotification: PropTypes.func.isRequired, -}; - -SsoUsersFormComponent.defaultProps = { - enabled: false, -}; - -const mapStateToProps = (state) => ({ - enabled: ssoUsersOnlySelector(state), - token: tokenSelector(state), -}); - -const mapDispatchToProps = (dispatch) => ({ - fetchAppInfo: () => dispatch(fetchAppInfoAction()), - dispatchShowSuccessNotification: (message) => dispatch(showSuccessNotification({ message })), - dispatchShowErrorNotification: (message) => dispatch(showErrorNotification({ message })), -}); - -export const SsoUsersForm = connect(mapStateToProps, mapDispatchToProps)(SsoUsersFormComponent); diff --git a/app/src/pages/common/membersPage/modals/inviteUserModal/inviteUserModal.jsx b/app/src/pages/common/membersPage/modals/inviteUserModal/inviteUserModal.jsx index f1fe9046c3..7277031742 100644 --- a/app/src/pages/common/membersPage/modals/inviteUserModal/inviteUserModal.jsx +++ b/app/src/pages/common/membersPage/modals/inviteUserModal/inviteUserModal.jsx @@ -170,7 +170,7 @@ export class InviteUserModal extends Component { } = this.props; const data = {}; - if (userData.user.externalUser && !this.props.ssoUsersOnly) { + if (userData.user.externalUser) { data.defaultProject = selectedProject; data.email = userData.user.userLogin; data.role = userData.role; @@ -237,7 +237,6 @@ export class InviteUserModal extends Component { selectedProject, areUserSuggestionsAllowed, data: { isProjectSelector }, - ssoUsersOnly, } = this.props; const userData = { ...data, @@ -248,11 +247,6 @@ export class InviteUserModal extends Component { const foundUser = foundUsers?.content.find(({ email }) => email === data.email); if (foundUser) { userData.user = makeOptions(data.project, false)({ content: [foundUser] })[0]; - } else if (!ssoUsersOnly) { - userData.user = { - userLogin: data.email, - externalUser: true, - }; } } @@ -260,7 +254,7 @@ export class InviteUserModal extends Component { if (res?.errorOccurred) { return; } - if (userData.user.externalUser && !ssoUsersOnly) { + if (userData.user.externalUser) { this.props.showModalAction({ id: 'externalUserInvitationModal', data: { email: res.email, link: res.backLink }, @@ -296,7 +290,6 @@ export class InviteUserModal extends Component { }; const cancelButton = { - // Add this definition text: intl.formatMessage(COMMON_LOCALE_KEYS.CANCEL), eventInfo: MEMBERS_PAGE_EVENTS.CANCEL_BTN_INVITE_USER_MODAL, }; @@ -315,7 +308,7 @@ export class InviteUserModal extends Component { {intl.formatMessage(ssoUsersOnly ? messages.descriptionAssign : messages.description)}

- {isProjectSelector || areUserSuggestionsAllowed || ssoUsersOnly ? ( + {isProjectSelector || areUserSuggestionsAllowed ? (