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: incorrect created date shown on backup method #572

Open
wants to merge 4 commits into
base: 5
Choose a base branch
from
Open
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
18 changes: 13 additions & 5 deletions src/FormField/RegisteredMFAMethodListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

class RegisteredMFAMethodListField extends FormField
{
/**
* @var Member
*/
private $member;

/**
* {@inheritDoc}
*
Expand Down Expand Up @@ -44,21 +49,21 @@ public function getSchemaDataDefaults()
$generator = SchemaGenerator::create();

if (!$this->value && $this->getForm() && $this->getForm()->getRecord() instanceof Member) {
$member = $this->getForm()->getRecord();
$this->member = $this->getForm()->getRecord();
} else {
$member = DataObject::get_by_id(Member::class, $this->value);
$this->member = DataObject::get_by_id(Member::class, $this->value);
}
Comment on lines 51 to 55
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this again, I think it would be better to convert this part into a private method that returns the member record, and can be called from both getSchemaDataDefaults() and getBackupMethod().

That way we never have to fall back on ?? Security::getCurrentUser() if getBackupMethod() is called first.


return array_merge($defaults, [
'schema' => $generator->getSchema($member) + [
'schema' => $generator->getSchema($this->member) + [
'endpoints' => [
'register' => $adminController->Link('register/{urlSegment}'),
'remove' => $adminController->Link('method/{urlSegment}'),
'setDefault' => $adminController->Link('method/{urlSegment}/default'),
],
// We need all available methods so we can re-register pre-existing methods
'allAvailableMethods' => $generator->getAvailableMethods(),
'backupCreationDate' => $this->getBackupMethod()
'backupCreatedDate' => $this->getBackupMethod()
? $this->getBackupMethod()->Created
: null,
'resetEndpoint' => SecurityAdmin::singleton()->Link("users/reset/{$this->value}"),
Expand All @@ -75,6 +80,9 @@ public function getSchemaDataDefaults()
protected function getBackupMethod(): ?RegisteredMethod
{
$backupMethod = MethodRegistry::singleton()->getBackupMethod();
return RegisteredMethodManager::singleton()->getFromMember(Security::getCurrentUser(), $backupMethod);
return RegisteredMethodManager::singleton()->getFromMember(
$this->member ?? Security::getCurrentUser(),
$backupMethod
);
}
}