2024-06-18 06:01:37 -04:00
|
|
|
import { ElementType } from 'react'
|
2022-04-25 07:04:44 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import importOverleafModules from '../../../../macros/import-overleaf-module.macro'
|
|
|
|
import { useSSOContext, SSOSubscription } from '../context/sso-context'
|
|
|
|
import { SSOLinkingWidget } from './linking/sso-widget'
|
2022-04-27 12:13:42 -04:00
|
|
|
import getMeta from '../../../utils/meta'
|
2023-10-06 04:15:16 -04:00
|
|
|
import { useBroadcastUser } from '@/shared/hooks/user-channel/use-broadcast-user'
|
2024-05-15 10:31:00 -04:00
|
|
|
import OLNotification from '@/features/ui/components/ol/ol-notification'
|
2022-04-25 07:04:44 -04:00
|
|
|
|
2024-06-18 06:01:37 -04:00
|
|
|
const availableIntegrationLinkingWidgets = importOverleafModules(
|
|
|
|
'integrationLinkingWidgets'
|
|
|
|
) as any[]
|
|
|
|
const availableReferenceLinkingWidgets = importOverleafModules(
|
|
|
|
'referenceLinkingWidgets'
|
|
|
|
) as any[]
|
|
|
|
const availableLangFeedbackLinkingWidgets = importOverleafModules(
|
|
|
|
'langFeedbackLinkingWidgets'
|
|
|
|
) as any[]
|
|
|
|
|
2022-04-25 07:04:44 -04:00
|
|
|
function LinkingSection() {
|
2023-10-06 04:15:16 -04:00
|
|
|
useBroadcastUser()
|
2022-04-25 07:04:44 -04:00
|
|
|
const { t } = useTranslation()
|
|
|
|
const { subscriptions } = useSSOContext()
|
2024-06-18 06:01:37 -04:00
|
|
|
const ssoErrorMessage = getMeta('ol-ssoErrorMessage')
|
|
|
|
const projectSyncSuccessMessage = getMeta('ol-projectSyncSuccessMessage')
|
|
|
|
|
|
|
|
// hide linking widgets in CI
|
|
|
|
const integrationLinkingWidgets = getMeta('ol-hideLinkingWidgets')
|
|
|
|
? []
|
|
|
|
: availableIntegrationLinkingWidgets
|
|
|
|
const referenceLinkingWidgets = getMeta('ol-hideLinkingWidgets')
|
|
|
|
? []
|
|
|
|
: availableReferenceLinkingWidgets
|
|
|
|
const langFeedbackLinkingWidgets = getMeta('ol-hideLinkingWidgets')
|
|
|
|
? []
|
|
|
|
: availableLangFeedbackLinkingWidgets
|
2022-04-27 12:13:42 -04:00
|
|
|
|
2023-05-17 04:59:51 -04:00
|
|
|
const oauth2ServerComponents = importOverleafModules('oauth2Server') as {
|
|
|
|
import: { default: ElementType }
|
|
|
|
path: string
|
|
|
|
}[]
|
|
|
|
|
2024-02-21 10:22:02 -05:00
|
|
|
const renderSyncSection =
|
|
|
|
getMeta('ol-isSaas') || getMeta('ol-gitBridgeEnabled')
|
|
|
|
|
2024-08-23 07:48:24 -04:00
|
|
|
const allIntegrationLinkingWidgets = integrationLinkingWidgets.concat(
|
|
|
|
oauth2ServerComponents
|
|
|
|
)
|
2023-05-17 04:59:51 -04:00
|
|
|
|
2024-09-05 09:02:32 -04:00
|
|
|
const haslangFeedbackLinkingWidgets = langFeedbackLinkingWidgets.length
|
2024-02-21 10:22:02 -05:00
|
|
|
const hasIntegrationLinkingSection =
|
|
|
|
renderSyncSection && allIntegrationLinkingWidgets.length
|
2022-04-25 07:04:44 -04:00
|
|
|
const hasReferencesLinkingSection = referenceLinkingWidgets.length
|
2023-07-14 05:12:12 -04:00
|
|
|
|
|
|
|
// Filter out SSO providers that are not allowed to be linked by
|
|
|
|
// managed users. Allow unlinking them if they are already linked.
|
|
|
|
const hideGoogleSSO = getMeta('ol-cannot-link-google-sso')
|
|
|
|
const hideOtherThirdPartySSO = getMeta('ol-cannot-link-other-third-party-sso')
|
|
|
|
|
|
|
|
for (const providerId in subscriptions) {
|
|
|
|
const isLinked = subscriptions[providerId].linked
|
|
|
|
if (providerId === 'google') {
|
|
|
|
if (hideGoogleSSO && !isLinked) {
|
|
|
|
delete subscriptions[providerId]
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (hideOtherThirdPartySSO && !isLinked) {
|
|
|
|
delete subscriptions[providerId]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-25 07:04:44 -04:00
|
|
|
const hasSSOLinkingSection = Object.keys(subscriptions).length > 0
|
|
|
|
|
|
|
|
if (
|
2023-12-07 09:29:45 -05:00
|
|
|
!haslangFeedbackLinkingWidgets &&
|
2022-04-25 07:04:44 -04:00
|
|
|
!hasIntegrationLinkingSection &&
|
|
|
|
!hasReferencesLinkingSection &&
|
|
|
|
!hasSSOLinkingSection
|
|
|
|
) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-08-06 11:04:30 -04:00
|
|
|
<h3 id="integrations">{t('integrations')}</h3>
|
2022-04-26 11:20:09 -04:00
|
|
|
<p className="small">{t('linked_accounts_explained')}</p>
|
2023-12-07 09:29:45 -05:00
|
|
|
{haslangFeedbackLinkingWidgets ? (
|
|
|
|
<>
|
2024-08-06 11:04:30 -04:00
|
|
|
<h3 id="language-feedback" className="text-capitalize">
|
2023-12-07 09:29:45 -05:00
|
|
|
{t('language_feedback')}
|
|
|
|
</h3>
|
|
|
|
<div className="settings-widgets-container">
|
|
|
|
{langFeedbackLinkingWidgets.map(
|
|
|
|
({ import: { default: widget }, path }, widgetIndex) => (
|
|
|
|
<ModuleLinkingWidget
|
|
|
|
key={path}
|
|
|
|
ModuleComponent={widget}
|
|
|
|
isLast={widgetIndex === langFeedbackLinkingWidgets.length - 1}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) : null}
|
2022-04-25 07:04:44 -04:00
|
|
|
{hasIntegrationLinkingSection ? (
|
|
|
|
<>
|
2022-04-26 11:20:09 -04:00
|
|
|
<h3 id="project-sync" className="text-capitalize">
|
2022-05-16 04:02:50 -04:00
|
|
|
{t('project_synchronisation')}
|
2022-04-26 11:20:09 -04:00
|
|
|
</h3>
|
2022-05-16 04:02:32 -04:00
|
|
|
{projectSyncSuccessMessage ? (
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLNotification
|
2024-04-23 06:25:05 -04:00
|
|
|
type="success"
|
|
|
|
content={projectSyncSuccessMessage}
|
|
|
|
/>
|
2022-05-16 04:02:32 -04:00
|
|
|
) : null}
|
2022-04-25 07:04:44 -04:00
|
|
|
<div className="settings-widgets-container">
|
2023-05-17 04:59:51 -04:00
|
|
|
{allIntegrationLinkingWidgets.map(
|
2022-04-25 07:04:44 -04:00
|
|
|
({ import: importObject, path }, widgetIndex) => (
|
|
|
|
<ModuleLinkingWidget
|
|
|
|
key={Object.keys(importObject)[0]}
|
|
|
|
ModuleComponent={Object.values(importObject)[0]}
|
2023-05-17 04:59:51 -04:00
|
|
|
isLast={
|
|
|
|
widgetIndex === allIntegrationLinkingWidgets.length - 1
|
|
|
|
}
|
2022-04-25 07:04:44 -04:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
{hasReferencesLinkingSection ? (
|
|
|
|
<>
|
2022-04-26 11:20:09 -04:00
|
|
|
<h3 id="references" className="text-capitalize">
|
2022-05-24 03:47:08 -04:00
|
|
|
{t('reference_managers')}
|
2022-04-26 11:20:09 -04:00
|
|
|
</h3>
|
2022-04-25 07:04:44 -04:00
|
|
|
<div className="settings-widgets-container">
|
|
|
|
{referenceLinkingWidgets.map(
|
|
|
|
({ import: importObject, path }, widgetIndex) => (
|
|
|
|
<ModuleLinkingWidget
|
|
|
|
key={Object.keys(importObject)[0]}
|
|
|
|
ModuleComponent={Object.values(importObject)[0]}
|
|
|
|
isLast={widgetIndex === referenceLinkingWidgets.length - 1}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
{hasSSOLinkingSection ? (
|
|
|
|
<>
|
2022-04-26 11:20:09 -04:00
|
|
|
<h3 id="linked-accounts" className="text-capitalize">
|
|
|
|
{t('linked_accounts')}
|
|
|
|
</h3>
|
2022-05-16 04:02:17 -04:00
|
|
|
{ssoErrorMessage ? (
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLNotification
|
2024-04-23 06:25:05 -04:00
|
|
|
type="error"
|
|
|
|
content={`${t('sso_link_error')}: ${ssoErrorMessage}`}
|
|
|
|
/>
|
2022-05-16 04:02:17 -04:00
|
|
|
) : null}
|
2022-04-25 07:04:44 -04:00
|
|
|
<div className="settings-widgets-container">
|
|
|
|
{Object.values(subscriptions).map(
|
|
|
|
(subscription, subscriptionIndex) => (
|
|
|
|
<SSOLinkingWidgetContainer
|
|
|
|
key={subscription.providerId}
|
|
|
|
subscription={subscription}
|
|
|
|
isLast={
|
|
|
|
subscriptionIndex === Object.keys(subscriptions).length - 1
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) : null}
|
2023-12-07 09:29:45 -05:00
|
|
|
{haslangFeedbackLinkingWidgets ||
|
|
|
|
hasIntegrationLinkingSection ||
|
2022-04-25 07:04:44 -04:00
|
|
|
hasReferencesLinkingSection ||
|
|
|
|
hasSSOLinkingSection ? (
|
|
|
|
<hr />
|
|
|
|
) : null}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
type LinkingWidgetProps = {
|
|
|
|
ModuleComponent: any
|
|
|
|
isLast: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
function ModuleLinkingWidget({ ModuleComponent, isLast }: LinkingWidgetProps) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ModuleComponent />
|
|
|
|
{isLast ? null : <hr />}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
type SSOLinkingWidgetContainerProps = {
|
|
|
|
subscription: SSOSubscription
|
|
|
|
isLast: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
function SSOLinkingWidgetContainer({
|
|
|
|
subscription,
|
|
|
|
isLast,
|
|
|
|
}: SSOLinkingWidgetContainerProps) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { unlink } = useSSOContext()
|
|
|
|
|
2022-05-26 05:39:07 -04:00
|
|
|
let description = ''
|
2022-04-26 11:20:09 -04:00
|
|
|
switch (subscription.providerId) {
|
|
|
|
case 'collabratec':
|
|
|
|
description = t('linked_collabratec_description')
|
|
|
|
break
|
|
|
|
case 'google':
|
2022-05-24 03:47:08 -04:00
|
|
|
description = `${t('login_with_service', {
|
2022-04-26 11:20:09 -04:00
|
|
|
service: subscription.provider.name,
|
2022-05-24 03:47:08 -04:00
|
|
|
})}.`
|
2022-04-26 11:20:09 -04:00
|
|
|
break
|
|
|
|
case 'orcid':
|
|
|
|
description = t('oauth_orcid_description')
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2022-04-25 07:04:44 -04:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<SSOLinkingWidget
|
|
|
|
providerId={subscription.providerId}
|
|
|
|
title={subscription.provider.name}
|
2022-04-26 11:20:09 -04:00
|
|
|
description={description}
|
2022-04-25 07:04:44 -04:00
|
|
|
helpPath={subscription.provider.descriptionOptions?.link}
|
|
|
|
linked={subscription.linked}
|
|
|
|
linkPath={subscription.provider.linkPath}
|
|
|
|
onUnlink={() => unlink(subscription.providerId)}
|
|
|
|
/>
|
|
|
|
{isLast ? null : <hr />}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LinkingSection
|