Skip to content

Commit

Permalink
Merge pull request #34 from sandstorm/feature/add-creation-date-to-se…
Browse files Browse the repository at this point in the history
…cond-factor-and-default-sorting-in-backend-module
  • Loading branch information
JamesAlias authored Sep 26, 2024
2 parents c5c4792 + 0b2458c commit 3e3d492
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Classes/Domain/Model/SecondFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sandstorm\NeosTwoFactorAuthentication\Domain\Model;

use DateTime;
use Neos\Flow\Http\InvalidArgumentException;
use Neos\Flow\Security\Account;
use Doctrine\ORM\Mapping as ORM;
Expand Down Expand Up @@ -38,6 +39,15 @@ class SecondFactor
*/
protected string $secret;

/**
* Introduced with version 1.4.0
* Nullable for backwards compatibility. Null values will be shown as '-' in backend module.
*
* @var DateTime|null
* @ORM\Column(type="datetime", nullable=true)
*/
protected DateTime|null $creationDate;

/**
* @return Account
*/
Expand Down Expand Up @@ -94,6 +104,16 @@ public function setSecret(string $secret): void
$this->secret = $secret;
}

public function getCreationDate(): DateTime|null
{
return $this->creationDate;
}

public function setCreationDate(DateTime $creationDate): void
{
$this->creationDate = $creationDate;
}

public function __toString(): string
{
return $this->account->getAccountIdentifier() . " with " . self::typeToString($this->type);
Expand Down
6 changes: 6 additions & 0 deletions Classes/Domain/Repository/SecondFactorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
*/
class SecondFactorRepository extends Repository
{
protected $defaultOrderings = [
'account' => 'ASC',
'creationDate' => 'DESC'
];

/**
* @throws IllegalObjectTypeException
*/
Expand All @@ -25,6 +30,7 @@ public function createSecondFactorForAccount(string $secret, Account $account):
$secondFactor->setAccount($account);
$secondFactor->setSecret($secret);
$secondFactor->setType(SecondFactor::TYPE_TOTP);
$secondFactor->setCreationDate(new \DateTime());
$this->add($secondFactor);
$this->persistenceManager->persistAll();
}
Expand Down
41 changes: 41 additions & 0 deletions Migrations/Mysql/Version20240812091514.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Neos\Flow\Persistence\Doctrine\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240812091514 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySqlPlatform,'."
);

$this->addSql('ALTER TABLE sandstorm_neostwofactorauthentication_domain_model_secondfactor ADD creationdate DATETIME DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySqlPlatform,'."
);

$this->addSql('ALTER TABLE sandstorm_neostwofactorauthentication_domain_model_secondfactor DROP creationdate');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ prototype(Sandstorm.NeosTwoFactorAuthentication:Component.SecondFactorList) < pr
<tr>
<th>{I18n.id('module.index.list.header.name').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()}</th>
<th>{I18n.id('module.index.list.header.type').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()}</th>
<th>{I18n.id('module.index.list.header.creationDate').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()}</th>
<th>&nbsp;</th>
</tr>
</thead>
Expand Down Expand Up @@ -42,6 +43,7 @@ prototype(Sandstorm.NeosTwoFactorAuthentication:Component.SecondFactorList.Entry
<tr>
<td>{props.factorAndPerson.user.name.fullName} ({props.factorAndPerson.secondFactor.account.accountIdentifier})</td>
<td>{props.factorAndPerson.secondFactor.typeAsName}</td>
<td>{props.factorAndPerson.secondFactor.creationDate == null ? '-' : Date.format(props.factorAndPerson.secondFactor.creationDate, 'Y-m-d H:i')}</td>
<td>
<button class="neos-button neos-button-danger" data-toggle="modal"
href={'#user-' + props.iterator.index} title={I18n.id('module.index.list.action.delete').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()} data-neos-toggle="tooltip">
Expand Down
4 changes: 4 additions & 0 deletions Resources/Private/Translations/de/Backend.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<source>Type</source>
<target>Typ</target>
</trans-unit>
<trans-unit id="module.index.list.header.creationDate" xml:space="preserve">
<source>Creation Date</source>
<target>Erstellungsdatum</target>
</trans-unit>
<trans-unit id="module.index.list.action.delete" xml:space="preserve">
<source>Delete second factor</source>
<target>Zweiten Faktor löschen</target>
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Translations/en/Backend.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<trans-unit id="module.index.list.header.type" xml:space="preserve">
<source>Type</source>
</trans-unit>
<trans-unit id="module.index.list.header.creationDate" xml:space="preserve">
<source>Creation Date</source>
</trans-unit>
<trans-unit id="module.index.list.action.delete" xml:space="preserve">
<source>Delete second factor</source>
</trans-unit>
Expand Down

0 comments on commit 3e3d492

Please sign in to comment.