diff --git a/RELEASE.md b/RELEASE.md index 9ad7bfccc..5dbfc7cf4 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -41,6 +41,20 @@ - ... --> +## Versione X.X.X (dd/mm/yyyy) + +### Migliorie + +- Gli utenti SPID vengono ora direttamente rediretti al link finale quando viene utilizzato un CT di tipo Collegamento + +### Novità + +- ... + +### Fix + +- ... + ## Versione 11.23.1 (19/09/2024) ### Migliorie diff --git a/src/customizations/volto/components/theme/View/LinkView.jsx b/src/customizations/volto/components/theme/View/LinkView.jsx new file mode 100644 index 000000000..53b938691 --- /dev/null +++ b/src/customizations/volto/components/theme/View/LinkView.jsx @@ -0,0 +1,75 @@ +// CUSTOMIZATION: +// - Added condition to check if user is SPID user (16-18 and 21) + +import { useEffect } from 'react'; +import { useSelector } from 'react-redux'; +import PropTypes from 'prop-types'; +import { useHistory } from 'react-router-dom'; +import { isInternalURL, flattenToAppURL } from '@plone/volto/helpers'; +import { Container as SemanticContainer } from 'semantic-ui-react'; +import { UniversalLink } from '@plone/volto/components'; +import { FormattedMessage } from 'react-intl'; +import config from '@plone/volto/registry'; + +const LinkView = ({ token, content }) => { + const history = useHistory(); + const userIsSpidUser = useSelector( + (state) => state.users.user.roles.length === 0, + ); + + useEffect(() => { + if (!token || userIsSpidUser) { + const { remoteUrl } = content; + if (isInternalURL(remoteUrl)) { + history.replace(flattenToAppURL(remoteUrl)); + } else if (!__SERVER__) { + window.location.href = flattenToAppURL(remoteUrl); + } + } + }, [content, history, token, userIsSpidUser]); + const { title, description, remoteUrl } = content; + const { openExternalLinkInNewTab } = config.settings; + const Container = + config.getComponent({ name: 'Container' }).component || SemanticContainer; + + return ( + +

{title}

+ {content.description && ( +

{description}

+ )} + {remoteUrl && ( +

+ {' '} + + {flattenToAppURL(remoteUrl)} + +

+ )} +
+ ); +}; + +LinkView.propTypes = { + content: PropTypes.shape({ + title: PropTypes.string, + description: PropTypes.string, + remoteUrl: PropTypes.string, + }), + token: PropTypes.string, +}; + +LinkView.defaultProps = { + content: null, + token: null, +}; + +export default LinkView;