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

FIX Export registered methods in enabled members report #444

Merged
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
1 change: 0 additions & 1 deletion src/Exception/AuthenticationFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class AuthenticationFailedException extends Exception
{

}
1 change: 0 additions & 1 deletion src/Exception/EncryptionAdapterException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
*/
class EncryptionAdapterException extends Exception
{

}
1 change: 0 additions & 1 deletion src/Exception/InvalidMethodException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class InvalidMethodException extends LogicException
{

}
1 change: 0 additions & 1 deletion src/Exception/MemberNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
*/
class MemberNotFoundException extends Exception
{

}
1 change: 0 additions & 1 deletion src/Exception/RegistrationFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class RegistrationFailedException extends LogicException
{

}
20 changes: 20 additions & 0 deletions src/Extension/MemberExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ public function setDefaultRegisteredMethod(RegisteredMethod $registeredMethod):
return $this->owner;
}

/**
* @return string
*/
public function getDefaultRegisteredMethodName(): string
{
$method = $this->getDefaultRegisteredMethod();
return $method ? $method->getMethod()->getName() : '';
}

/**
* @return string
*/
public function getRegisteredMethodNames(): string
{
$arr = array_map(function ($method) {
return $method->getMethod()->getName();
}, $this->owner->RegisteredMFAMethods()->toArray());
return implode(', ', $arr);
}

public function updateCMSFields(FieldList $fields): FieldList
{
$fields->removeByName(['DefaultRegisteredMethodID', 'HasSkippedMFARegistration', 'RegisteredMFAMethods']);
Expand Down
12 changes: 6 additions & 6 deletions src/Report/EnabledMembers.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,11 @@ public function sourceRecords($params): DataList
public function columns(): array
{
$columns = singleton(Member::class)->summaryFields() + [
'registeredMethods' => [
'title' => _t(__CLASS__ . '.COLUMN_METHODS_REGISTERED', 'Registered methods'),
'formatting' => [$this, 'formatMethodsColumn']
'RegisteredMethodNames' => [
'title' => _t(__CLASS__ . '.COLUMN_METHODS_REGISTERED', 'Registered methods')
],
'defaultMethodName' => [
'title' => _t(__CLASS__ . '.COLUMN_METHOD_DEFAULT', 'Default method'),
'formatting' => [$this, 'formatDefaultMethodColumn']
'DefaultRegisteredMethodName' => [
'title' => _t(__CLASS__ . '.COLUMN_METHOD_DEFAULT', 'Default method')
],
'HasSkippedMFARegistration' => [
'title' => _t(__CLASS__ . '.COLUMN_SKIPPED_REGISTRATION', 'Skipped registration'),
Expand Down Expand Up @@ -153,6 +151,7 @@ public function parameterFields(): FieldList
* @param null $_
* @param Member $record
* @return string
* @deprecated Will be removed in 5.0 use MemberExtension::getRegisteredMethodNames() instead
*/
public function formatMethodsColumn($_, Member $record): string
{
Expand All @@ -170,6 +169,7 @@ public function formatMethodsColumn($_, Member $record): string
* @param null $_
* @param Member&MemberExtension $record
* @return string
* @deprecated Will be removed in 5.0 use MemberExtension::getDefaultRegisteredMethodName() instead
*/
public function formatDefaultMethodColumn($_, Member $record): string
{
Expand Down
1 change: 0 additions & 1 deletion src/State/AvailableMethodDetailsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@
*/
interface AvailableMethodDetailsInterface extends JsonSerializable
{

}
1 change: 0 additions & 1 deletion src/State/RegisteredMethodDetailsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@
*/
interface RegisteredMethodDetailsInterface extends JsonSerializable
{

}
23 changes: 23 additions & 0 deletions tests/php/Extension/MemberExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,27 @@ public function testSetDefaultRegisteredMethodThrowsExceptionWhenSettingSomeoneE
$anotherMember = $this->objFromFixture(Member::class, 'squib');
$anotherMember->setDefaultRegisteredMethod($registeredMethod);
}

public function testGetDefaultRegisteredMethodName()
{
$member = $this->createMemberWithRegisteredMethods();
$this->assertSame('Recovery codes', $member->getDefaultRegisteredMethodName());
}

public function testGetRegisteredMethodNames()
{
$member = $this->createMemberWithRegisteredMethods();
$this->assertSame('Recovery codes, MemberExtensionTestMethod2', $member->getRegisteredMethodNames());
}

private function createMemberWithRegisteredMethods(): Member
{
$manager = RegisteredMethodManager::singleton();
$member = $this->objFromFixture(Member::class, 'squib');
$method = new Method();
$method2 = new MemberExtensionTestMethod2();
$manager->registerForMember($member, $method, ['foo' => 'bar']);
$manager->registerForMember($member, $method2, ['abc' => 'xyz']);
return $member;
}
}
22 changes: 22 additions & 0 deletions tests/php/Extension/MemberExtensionTestMethod2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace SilverStripe\MFA\Tests\Extension;

use SilverStripe\MFA\BackupCode\Method;

/**
* This needs to be a separate class rather than an anonymous class
* because Injector in php 7.3 doesn't work with an anonmyous classes
* in this context
*/
class MemberExtensionTestMethod2 extends Method
{
public function getName(): string
{
return 'MemberExtensionTestMethod2';
}
public function getURLSegment(): string
{
return 'MemberExtensionTestMethod2';
}
}
1 change: 0 additions & 1 deletion tests/php/Stub/DuplicatedBasicMath/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
*/
class Method extends BasicMathMethod
{

}
1 change: 0 additions & 1 deletion tests/php/Stub/Null/RegisterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class RegisterHandler implements RegisterHandlerInterface, TestOnly
{

/**
* Stores any data required to handle a registration process with a method, and returns relevant state to be applied
* to the front-end application managing the process.
Expand Down