Skip to content

Commit

Permalink
fix: added condition for spid user link redirect (#776)
Browse files Browse the repository at this point in the history
* fix: added condition for spid user link redirect

* chore: added customization info
  • Loading branch information
sabrina-bongiovanni authored Sep 24, 2024
1 parent 5e43695 commit 8ab726b
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
14 changes: 14 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
75 changes: 75 additions & 0 deletions src/customizations/volto/components/theme/View/LinkView.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<Container id="page-document">
<h1 className="documentFirstHeading">{title}</h1>
{content.description && (
<p className="documentDescription">{description}</p>
)}
{remoteUrl && (
<p>
<FormattedMessage
id="The link address is:"
defaultMessage="The link address is:"
/>{' '}
<UniversalLink
href={remoteUrl}
openLinkInNewTab={
openExternalLinkInNewTab && !isInternalURL(remoteUrl)
}
>
{flattenToAppURL(remoteUrl)}
</UniversalLink>
</p>
)}
</Container>
);
};

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;

0 comments on commit 8ab726b

Please sign in to comment.