-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [Adherent] Add public id * Adjust tests
- Loading branch information
Showing
8 changed files
with
96 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ Feature: | |
""" | ||
{ | ||
"uuid": "e6977a4d-2646-5f6c-9c82-88e58dca8458", | ||
"id": "C9E-7BB", | ||
"email_address": "[email protected]", | ||
"first_name": "Carl", | ||
"last_name": "Mirabeau", | ||
|
@@ -783,6 +784,7 @@ Feature: | |
""" | ||
{ | ||
"uuid": "313bd28f-efc8-57c9-8ab7-2106c8be9699", | ||
"id": "B6H-873", | ||
"first_name": "Simple", | ||
"last_name": "User", | ||
"certified": false, | ||
|
@@ -1323,6 +1325,7 @@ Feature: | |
"party_membership": "exclusive", | ||
"other_party_membership": false, | ||
"uuid": "b4219d47-3138-5efd-9762-2ef9f9495084", | ||
"id": "G86-5E4", | ||
"first_name": "Gisele", | ||
"last_name": "Berthoux", | ||
"committee_membership": { | ||
|
@@ -1434,6 +1437,7 @@ Feature: | |
"party_membership": "exclusive", | ||
"other_party_membership": false, | ||
"uuid": "b4219d47-3138-5efd-9762-2ef9f9495084", | ||
"id": "G86-5E4", | ||
"first_name": "Gisele", | ||
"last_name": "Berthoux", | ||
"committee_membership": { | ||
|
@@ -1519,6 +1523,7 @@ Feature: | |
"party_membership": "exclusive", | ||
"other_party_membership": false, | ||
"uuid": "b4219d47-3138-5efd-9762-2ef9f9495084", | ||
"id": "G86-5E4", | ||
"first_name": "Gisele", | ||
"last_name": "Berthoux", | ||
"committee_membership": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ Feature: | |
And the JSON should be equal to: | ||
""" | ||
{ | ||
"id": "e69785", | ||
"id": "C9E-7BB", | ||
"uuid": "e6977a4d-2646-5f6c-9c82-88e58dca8458", | ||
"email_address": "[email protected]", | ||
"email_subscribed": true, | ||
|
@@ -67,7 +67,7 @@ Feature: | |
And the JSON should be equal to: | ||
""" | ||
{ | ||
"id": "a04686", | ||
"id": "D5C-399", | ||
"nickname": "kikouslove", | ||
"email_address": "[email protected]", | ||
"uuid": "a046adbe-9c7b-56a9-a676-6151a6785dda", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20250108110304 extends AbstractMigration | ||
{ | ||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE adherents ADD public_id VARCHAR(7) DEFAULT NULL'); | ||
$this->addSql('CREATE UNIQUE INDEX UNIQ_562C7DA3B5B48B91 ON adherents (public_id)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('DROP INDEX UNIQ_562C7DA3B5B48B91 ON adherents'); | ||
$this->addSql('ALTER TABLE adherents DROP public_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Component\Serializer\Attribute\Groups; | ||
use Symfony\Component\Serializer\Attribute\SerializedName; | ||
|
||
trait PublicIdTrait | ||
{ | ||
#[ORM\Column(length: 7, unique: true, nullable: true)] | ||
protected ?string $publicId = null; | ||
|
||
#[Groups(['jemarche_user_profile', 'profile_read'])] | ||
#[SerializedName('id')] | ||
public function getPublicId(): ?string | ||
{ | ||
return $this->publicId; | ||
} | ||
|
||
public function setPublicId(string $publicId): void | ||
{ | ||
$this->publicId = $publicId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Utils; | ||
|
||
use Ramsey\Uuid\UuidInterface; | ||
|
||
class PublicIdGenerator | ||
{ | ||
private const string ALLOWED_CHARACTERS = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'; | ||
private const int SEGMENT_LENGTH = 3; | ||
|
||
public static function generatePublicIdFromUuid(UuidInterface $uuid): string | ||
{ | ||
$hash = md5($uuid->toString()); | ||
$segment1 = ''; | ||
$segment2 = ''; | ||
|
||
for ($i = 0; $i < self::SEGMENT_LENGTH; ++$i) { | ||
$segment1 .= self::convertHexToAllowedCharacter($hash[$i]); | ||
$segment2 .= self::convertHexToAllowedCharacter($hash[$i + self::SEGMENT_LENGTH]); | ||
} | ||
|
||
return "$segment1-$segment2"; | ||
} | ||
|
||
private static function convertHexToAllowedCharacter(string $hexCharacter): string | ||
{ | ||
return self::ALLOWED_CHARACTERS[hexdec($hexCharacter) % \strlen(self::ALLOWED_CHARACTERS)]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% extends '@SonataAdmin/CRUD/base_list_field.html.twig' %} | ||
|
||
{% block field %} | ||
{{ object.id }} | ||
<br /> | ||
<b>{{ object.publicId }}</b> | ||
{% endblock %} |