Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OF#3680] Handle multiple cosign auth methods for cosign #639

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 41 additions & 19 deletions src/components/LoginOptions/LoginOptions.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export default {
};

export const Display = {
render: ({loginAsYourselfOptions, loginAsGemachtigdeOptions}) => (
render: ({loginAsYourselfOptions, loginAsGemachtigdeOptions, cosignLoginOptions}) => (
<LoginOptionsDisplay
loginAsYourselfOptions={loginAsYourselfOptions}
loginAsGemachtigdeOptions={loginAsGemachtigdeOptions}
cosignLoginOptions={cosignLoginOptions}
/>
),
args: {
Expand Down Expand Up @@ -76,18 +77,37 @@ export const Display = {
url: '#',
},
],
cosignLoginOptions: [
{
identifier: 'digid',
label: 'DigiD',
logo: {
appearance: 'dark',
href: 'https://www.digid.nl/',
title: 'DigiD',
imageSrc: './digid.png',
},
url: '#',
},
{
identifier: 'eHerkenning',
label: 'eHerkenning',
logo: {
appearance: 'light',
href: 'https://www.eherkenning.nl/',
title: 'eHerkenning',
imageSrc: './eherkenning.png',
},
url: '#',
},
],
},
};

const render = ({
loginRequired = false,
loginOptions = [],
cosignLoginInfo = undefined,
onFormStart,
}) =>
const render = ({loginRequired = false, loginOptions = [], cosignLoginOptions = [], onFormStart}) =>
console.log(onFormStart) || (
<LoginOptions
form={buildForm({loginRequired, loginOptions, cosignLoginInfo})}
form={buildForm({loginRequired, loginOptions, cosignLoginOptions})}
onFormStart={onFormStart}
/>
);
Expand Down Expand Up @@ -214,17 +234,19 @@ export const WithCoSignOption = {
isForGemachtigde: false,
},
],
cosignLoginInfo: {
identifier: 'digid',
label: 'DigiD',
url: '#',
logo: {
title: 'DigiD simulatie',
imageSrc: './digid.png',
href: 'https://www.digid.nl/',
appearance: 'dark',
cosignLoginOptions: [
{
identifier: 'digid',
label: 'DigiD',
url: '#',
logo: {
title: 'DigiD simulatie',
imageSrc: './digid.png',
href: 'https://www.digid.nl/',
appearance: 'dark',
},
isForGemachtigde: false,
},
isForGemachtigde: false,
},
],
},
};
12 changes: 8 additions & 4 deletions src/components/LoginOptions/LoginOptionsDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
const LoginOptionsDisplay = ({
loginAsYourselfOptions,
loginAsGemachtigdeOptions,
cosignLoginInfo,
cosignLoginOptions,
}) => {
return (
<div className={getBEMClassName('login-options')}>
Expand All @@ -36,7 +36,7 @@
</>
)}

{cosignLoginInfo && (
{cosignLoginOptions?.length > 0 && (
<div className={getBEMClassName('login-options__cosign')}>
<h2 className={getBEMClassName('login-options__caption')}>
<FormattedMessage
Expand All @@ -45,7 +45,11 @@
/>
</h2>

<LoginButton key={cosignLoginInfo.identifier} option={cosignLoginInfo} />
<div className={getBEMClassName('login-options__list')}>
{cosignLoginOptions.map(option => (

Check warning on line 49 in src/components/LoginOptions/LoginOptionsDisplay.js

View check run for this annotation

Codecov / codecov/patch

src/components/LoginOptions/LoginOptionsDisplay.js#L49

Added line #L49 was not covered by tests
<LoginButton key={option.identifier} option={option} />
))}
</div>
</div>
)}
</div>
Expand All @@ -55,7 +59,7 @@
LoginOptionsDisplay.propTypes = {
loginAsYourselfOptions: PropTypes.arrayOf(FormattedLoginOption).isRequired,
loginAsGemachtigdeOptions: PropTypes.arrayOf(FormattedLoginOption).isRequired,
cosignLoginInfo: FormattedLoginOption,
cosignLoginOptions: PropTypes.arrayOf(FormattedLoginOption),
};

export default LoginOptionsDisplay;
29 changes: 17 additions & 12 deletions src/components/LoginOptions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const LoginOptions = ({form, onFormStart}) => {

const loginAsYourselfOptions = [];
const loginAsGemachtigdeOptions = [];
const cosignLoginOptions = [];

form.loginOptions.forEach(option => {
let readyOption = {...option};
Expand All @@ -33,6 +34,21 @@ const LoginOptions = ({form, onFormStart}) => {
}
});

if (form.cosignLoginOptions) {
form.cosignLoginOptions.forEach(option => {
cosignLoginOptions.push({
...option,
label: (
<FormattedMessage
description="Login button label"
defaultMessage="Login with {provider}"
values={{provider: option.label}}
/>
),
});
});
}

if (!form.loginRequired) {
loginAsYourselfOptions.push({
identifier: 'anonymous',
Expand All @@ -51,23 +67,12 @@ const LoginOptions = ({form, onFormStart}) => {
},
};

let cosignInfo = form.cosignLoginInfo && {
...form.cosignLoginInfo,
label: (
<FormattedMessage
description="Login button label"
defaultMessage="Login with {provider}"
values={{provider: form.cosignLoginInfo.label}}
/>
),
};

return (
<Container {...containerProps}>
<LoginDisplayComponent
loginAsYourselfOptions={loginAsYourselfOptions}
loginAsGemachtigdeOptions={loginAsGemachtigdeOptions}
cosignLoginInfo={cosignInfo}
cosignLoginOptions={cosignLoginOptions}
/>
</Container>
);
Expand Down
4 changes: 3 additions & 1 deletion src/components/LoginOptions/tests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ afterEach(() => {
});

it('Login not required, options wrapped in form tag', () => {
const form = buildForm({loginRequired: false, loginOptions: []});
const form = buildForm({loginRequired: false, loginOptions: [], cosignLoginOptions: []});
const onFormStart = jest.fn(e => e.preventDefault());

act(() => {
Expand Down Expand Up @@ -67,6 +67,7 @@ it('Login required, options not wrapped in form tag', () => {
isForGemachtigde: false,
},
],
cosignLoginOptions: [],
});
const onFormStart = jest.fn(e => e.preventDefault());

Expand Down Expand Up @@ -114,6 +115,7 @@ it('Login button has the right URL after cancelling log in', () => {
isForGemachtigde: false,
},
],
cosignLoginOptions: [],
});

const onFormStart = jest.fn(e => e.preventDefault());
Expand Down
1 change: 0 additions & 1 deletion src/formio/components/Cosign.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default class Cosign extends Email {
{
label: 'Co-sign',
type: 'cosign',
authPlugin: 'digid', // default
input: false,
},
...extend
Expand Down
2 changes: 0 additions & 2 deletions src/formio/components/Cosign.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default {
type: 'cosign',
label: 'Co-signer email address',
validateOn: 'blur',
authPlugin: 'digid',
extraComponentProperties: {},
evalContext: {},
},
Expand All @@ -19,7 +18,6 @@ export default {
label: {type: {required: true}},
type: {table: {disable: true}},
validateOn: {table: {disable: true}},
authPlugin: {table: {disable: true}},
extraComponentProperties: {
description: `Any additional Form.io component properties, recursively merged into the
component definition.`,
Expand Down
2 changes: 1 addition & 1 deletion src/types/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Form = PropTypes.shape({
name: PropTypes.string.isRequired,
loginRequired: PropTypes.bool.isRequired,
loginOptions: PropTypes.arrayOf(LoginOption).isRequired,
cosignLoginInfo: LoginOption,
cosignLoginOptions: PropTypes.arrayOf(LoginOption),
product: PropTypes.string,
slug: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
Expand Down
8 changes: 3 additions & 5 deletions src/types/FormattedLoginOption.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import PropTypes from 'prop-types';

import LoginOptionLogo from './LoginOptionLogo';

const FormattedLoginOption = PropTypes.shape({
identifier: PropTypes.string.isRequired,
label: PropTypes.node.isRequired,
url: PropTypes.string,
logo: PropTypes.shape({
title: PropTypes.string.isRequired,
imageSrc: PropTypes.string.isRequired,
href: PropTypes.string,
}),
logo: LoginOptionLogo,
isForGemachtigde: PropTypes.bool,
});

Expand Down
12 changes: 12 additions & 0 deletions src/types/LoginOptionLogo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import PropTypes from 'prop-types';

import {LOGO_APPEARANCES} from 'components/LoginButton/LoginButtonIcon';

const LoginOptionLogo = PropTypes.shape({
title: PropTypes.string.isRequired,
imageSrc: PropTypes.string.isRequired,
href: PropTypes.string,
appearance: PropTypes.oneOf(LOGO_APPEARANCES),
});

export default LoginOptionLogo;
Loading