Skip to content

Commit

Permalink
Merge pull request #242 from creative-commoners/pulls/4.0/helptext
Browse files Browse the repository at this point in the history
API alter user help link default translations
  • Loading branch information
robbieaverill authored Jul 2, 2019
2 parents 5edaadb + e3c8b98 commit c15efc1
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 27 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle-cms.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/lang/src/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"MultiFactorAuthentication.FIND_OUT_MORE": "Find out more",
"MultiFactorAuthentication.HOW_MFA_WORKS": "How multi-factor authentication works",
"MultiFactorAuthentication.TITLE": "Add extra security to your account",
"MultiFactorAuthentication.HOW_IT_WORKS": "How it works",
"MultiFactorAuthentication.EXTRA_LAYER_IMAGE_ALT": "Shields indicating additional protection",
Expand Down
18 changes: 10 additions & 8 deletions client/src/components/BackupCodes/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Register extends Component {
*/
renderDescription() {
const { ss: { i18n } } = window;
const { method } = this.props;
const { method: { supportLink, supportText } } = this.props;

return (
<p>
Expand All @@ -114,13 +114,15 @@ class Register extends Component {
'somewhere safe, as they will not be viewable after leaving this page.'
)}
&nbsp;
<a
href={method.supportLink}
target="_blank"
rel="noopener noreferrer"
>
{i18n._t('MFARegister.HELP', 'Find out more')}
</a>
{supportLink &&
<a
href={supportLink}
target="_blank"
rel="noopener noreferrer"
>
{supportText || i18n._t('MFARegister.RECOVERY_HELP', 'Learn more about recovery codes.')}
</a>
}
</p>
);
}
Expand Down
11 changes: 11 additions & 0 deletions client/src/components/BackupCodes/Verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,24 @@ class Verify extends Component {
*/
renderDescription() {
const { ss: { i18n } } = window;
const { method } = this.props;

return (
<p>
{i18n._t(
'MFABackupCodesVerify.DESCRIPTION',
'Use one of the recovery codes you received'
)}
&nbsp;
{method && method.supportLink &&
<a
href={method.supportLink}
target="_blank"
rel="noopener noreferrer"
>
{i18n._t('MFARegister.RECOVERY_HELP', 'How to use recovery codes.')}
</a>
}
</p>
);
}
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/BackupCodes/tests/Register-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('Register - Recovery Codes', () => {
<Register
method={mockMethod}
codes={['123', '456']}
copyFeedbackDuration={30}
copyFeedbackDuration={300}
/>
);

Expand All @@ -100,13 +100,13 @@ describe('Register - Recovery Codes', () => {
copyLink.simulate('click', { preventDefault });
expect(preventDefault.mock.calls).toHaveLength(2);
wrapper.update();
}, 15);
}, 150);

setTimeout(() => {
expect(wrapper.find('.mfa-register-backup-codes__copy-to-clipboard').text())
.toBe('Copied!');
done();
}, 30);
}, 400);
});

it('will call the given onComplete function when pressing the "finish" button', () => {
Expand Down
8 changes: 4 additions & 4 deletions client/src/components/Register/Introduction.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ const Introduction = ({ canSkip, onContinue, onSkip, resources, showTitle }) =>
) }
&nbsp;
{
resources.user_docs_url &&
<a href={resources.user_docs_url}>
{ i18n._t('MultiFactorAuthentication.FIND_OUT_MORE', fallbacks['MultiFactorAuthentication.FIND_OUT_MORE']) }
resources.user_help_link &&
<a href={resources.user_help_link}>
{ i18n._t('MultiFactorAuthentication.HOW_MFA_WORKS', fallbacks['MultiFactorAuthentication.HOW_MFA_WORKS']) }
</a>
}
</p>
Expand Down Expand Up @@ -122,7 +122,7 @@ Introduction.propTypes = {
onContinue: PropTypes.func.isRequired,
onSkip: PropTypes.func,
resources: PropTypes.shape({
user_docs_url: PropTypes.string,
user_help_link: PropTypes.string,
extra_factor_image_url: PropTypes.string,
unique_image_url: PropTypes.string,
}).isRequired,
Expand Down
7 changes: 4 additions & 3 deletions client/src/components/Register/MethodTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ class MethodTile extends Component {
*/
renderSupportLink(method) {
const { ss: { i18n } } = window;
const { supportLink, supportText } = method;

if (!method.supportLink) {
if (!supportLink) {
return null;
}

return (
<a
href={method.supportLink}
href={supportLink}
target="_blank"
rel="noopener noreferrer"
className="mfa-method-tile__support-link"
>
{i18n._t('MFARegister.HELP', 'Find out more.')}
{supportText || i18n._t('MFARegister.HELP', 'Find out more.')}
</a>
);
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Register/tests/Introduction-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Introduction', () => {
<Introduction
onContinue={handleContinueMock}
resources={{
user_docs_url: '#',
user_help_link: '#',
}}
/>
);
Expand Down
3 changes: 2 additions & 1 deletion lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ en:
COULD_NOT_DELETE: 'Could not delete the specified method from the user'
COULD_NOT_SET_DEFAULT: 'Could not set the default method for the user'
CSRF_FAILURE: 'Request timed out, please try again'
INVALID_METHOD: 'No such registered method is available'
INVALID_METHOD: 'No such method is available'
INVALID_REGISTERED_METHOD: 'No such registered method is available'
INVALID_SESSION: 'Invalid session. Please refresh and try again.'
MENUTITLE: SilverStripe\MFA\Controller\AdminRegistrationController
SilverStripe\MFA\Email\AccountReset:
Expand Down
3 changes: 2 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

<!-- base rules are PSR-12 -->
<rule ref="PSR12" >
<!-- Current exclusions -->
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
<!-- tests/Behat/Context/LoginContext returns if the parent class does not exist early, which triggers a warning -->
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
</rule>
</ruleset>
10 changes: 10 additions & 0 deletions src/BackupCode/RegisterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ public function getSupportLink(): string
return (string) $this->config()->get('user_help_link');
}

/**
* Provide a localised string to describe the support link {@see getSupportLink} about this MFA Method.
*
* @return string
*/
public function getSupportText(): string
{
return _t(__CLASS__ . '.SUPPORT_LINK_DESCRIPTION', 'Learn about recovery codes.');
}

/**
* Get the key that a React UI component is registered under (with @silverstripe/react-injector on the front-end)
*
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/AdminRegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function setDefaultRegisteredMethod(HTTPRequest $request): HTTPResponse
$registeredMethod = $registeredMethodManager->getFromMember($member, $method);
if (!$registeredMethod) {
return $this->jsonResponse(
['errors' => [_t(__CLASS__ . '.INVALID_METHOD', 'No such registered method is available')]],
['errors' => [_t(__CLASS__ . '.INVALID_REGISTERED_METHOD', 'No such registered method is available')]],
400
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/FormField/RegisteredMFAMethodListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class RegisteredMFAMethodListField extends FormField
*/
public function __construct(string $name, ?string $title, Member $value)
{
return parent::__construct($name, $title, $value);
parent::__construct($name, $title, $value);
}

public function setValue($value, $data = null)
Expand Down
7 changes: 7 additions & 0 deletions src/Method/Handler/RegisterHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public function getDescription(): string;
*/
public function getSupportLink(): string;

/**
* Provide a localised string to describe the support link {@see getSupportLink} about this MFA Method.
*
* @return string
*/
public function getSupportText(): string;

/**
* Get the key that a React UI component is registered under (with @silverstripe/react-injector on the front-end)
*
Expand Down
2 changes: 1 addition & 1 deletion src/Service/SchemaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected function getResources()
$module = ModuleLoader::getModule('silverstripe/mfa');

return [
'user_docs_url' => Config::inst()->get(LoginHandler::class, 'user_docs_url'),
'user_help_link' => Config::inst()->get(LoginHandler::class, 'user_help_link'),
'extra_factor_image_url' => $module->getResource('client/dist/images/extra-protection.svg')->getURL(),
'unique_image_url' => $module->getResource('client/dist/images/unique.svg')->getURL(),
'more_options_image_url' => $module->getResource('client/dist/images/more-options.svg')->getURL(),
Expand Down
1 change: 1 addition & 0 deletions src/State/AvailableMethodDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function jsonSerialize()
'name' => $this->method->getRegisterHandler()->getName(),
'description' => $this->method->getRegisterHandler()->getDescription(),
'supportLink' => $this->method->getRegisterHandler()->getSupportLink(),
'supportText' => $this->method->getRegisterHandler()->getSupportText(),
'thumbnail' => $this->method->getThumbnail(),
'component' => $this->method->getRegisterHandler()->getComponent(),
'isAvailable' => $this->method->isAvailable(),
Expand Down
10 changes: 10 additions & 0 deletions tests/php/Stub/BasicMath/MethodRegisterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public function getSupportLink(): string
return 'https://google.com';
}

/**
* Provide a localised string to describe the support link {@see getSupportLink} about this MFA Method.
*
* @return string
*/
public function getSupportText(): string
{
return 'What is math?';
}

/**
* Get the key that a React UI component is registered under (with @silverstripe/react-injector on the front-end)
*
Expand Down
10 changes: 10 additions & 0 deletions tests/php/Stub/Null/RegisterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ public function getSupportLink(): string
// TODO: Implement getSupportLink() method.
}

/**
* Provide a localised string to describe the support link {@see getSupportLink} about this MFA Method.
*
* @return string
*/
public function getSupportText(): string
{
// TODO: Implement getSupportText() method.
}

/**
* Get the key that a React UI component is registered under (with @silverstripe/react-injector on the front-end)
*
Expand Down

0 comments on commit c15efc1

Please sign in to comment.