Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into page-actors
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Ribiere committed Oct 11, 2024
2 parents 639f273 + 85916a9 commit 3737023
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 115 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ down-remove-all:
build:
$(DOCKER_COMP) build

deploy:
$(DOCKER_COMP) up --build -d --remove-orphans
deploy: build-and-up cc

docker-config:
$(DOCKER_COMP) config
Expand Down
4 changes: 2 additions & 2 deletions symfony/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ regenerate-entity:
@$(SYMFONY) make:entity --regenerate

make-run-migration: make-migration run-migration
reset-database: create-database run-migration
reset-database: recreate-database run-migration
rerun-database: reset-database run-fixtures
create-short-migration: create-database run-migration make-migration rerun-migration
create-short-migration: recreate-database run-migration make-migration rerun-migration

init-jwt-keypair:
@$(SYMFONY) lexik:jwt:generate-keypair
1 change: 0 additions & 1 deletion symfony/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ services:
- '../src/Entity/'
- '../src/Kernel.php'
- '../src/Services/State/'
- '../src/DataFixtures/'
- '../src/Services/Serializer/'


Expand Down
7 changes: 1 addition & 6 deletions symfony/config/services/State/state.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@ services:
_defaults:
autowire: true
autoconfigure: true

App\Services\State\:
resource: '../../../src/Services/State/'

App\Services\State\Processor\UserProcessor:
bind:
$processor: '@api_platform.doctrine.orm.state.persist_processor'
resource: '../../../src/Services/State/'
10 changes: 0 additions & 10 deletions symfony/config/services/data_fixtures.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion symfony/fixtures/projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ App\Entity\Project:
website: <url()>
logo: <imageUrl(200, 100)>
created_at: '<dateTimeBetween("-200 days", "now")>'
updated_at: '<dateTimeBetween($created_at, "now")>'
updated_at: '<dateTimeBetween($created_at, "now")>'
5 changes: 4 additions & 1 deletion symfony/fixtures/users.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ App\Entity\User:
email: [email protected]
plainPassword: Test1234
roles: [ 'ROLE_ADMIN' ]
isValidated: true
user_2:
firstName: John
lastName: Editor Doe
email: [email protected]
plainPassword: Test1234
roles: [ 'ROLE_EDITOR_ACTORS', 'ROLE_EDITOR_PROJECTS', "ROLE_EDITOR_RESOURCES", "ROLE_EDITOR_DATA" ]
isValidated: true
user_3:
firstName: Jane
lastName: Doe
email: [email protected]
plainPassword: Test1234
roles: [ 'ROLE_USER' ]
roles: [ 'ROLE_USER' ]
isValidated: true
42 changes: 0 additions & 42 deletions symfony/src/DataFixtures/Processor/UserProcessor.php

This file was deleted.

16 changes: 6 additions & 10 deletions symfony/src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use Doctrine\Common\Collections\Collection;
use App\Services\State\Provider\UserProvider;
use App\Services\State\Processor\UserProcessor;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Attribute\Groups;
use App\Services\State\Provider\CurrentUserProvider;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Serializer\Attribute\SerializedName;

#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: '`user`')]
Expand All @@ -40,15 +39,11 @@
// provider: UserProvider::class // To use if we need to open to every logged user if we need to see user names associated to likes
security: 'is_granted("ROLE_ADMIN")'
),
new Post(
processor: UserProcessor::class
),
new Post(),
new Put(
processor: UserProcessor::class,
security: 'is_granted("'.UserVoter::EDIT.'", object)'
),
new Patch(
processor: UserProcessor::class,
security: 'is_granted("'.UserVoter::EDIT.'", object)'
),
new Delete(security: 'is_granted("'.UserVoter::EDIT.'", object)'),
Expand Down Expand Up @@ -97,11 +92,12 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
/**
* @var string The hashed password
*/
#[ORM\Column]
#[ORM\Column(type: 'string', nullable: true)]
private ?string $password = null;

#[Assert\NotBlank(groups: [self::GROUP_WRITE])]
#[Groups([self::GROUP_WRITE])]
#[SerializedName('password')]
private ?string $plainPassword = null;

/**
Expand All @@ -111,7 +107,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
private Collection $actorsCreated;

#[ORM\Column]
#[Groups([self::GROUP_READ, self::GROUP_GETME,])]
#[Groups([self::GROUP_READ, self::GROUP_GETME])]
private ?bool $isValidated = false;

#[ORM\Column(nullable: true)]
Expand Down Expand Up @@ -195,7 +191,7 @@ public function setRoles(array $roles): static
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
public function getPassword(): ?string
{
return $this->password;
}
Expand Down
26 changes: 26 additions & 0 deletions symfony/src/Event/EventListener/UserListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Event\EventListener;

use App\Entity\User;
use App\Security\PasswordHasher;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;
use Doctrine\ORM\Events;
use Doctrine\Persistence\Event\LifecycleEventArgs;

#[AsEntityListener(event: Events::prePersist, method: 'hashPassword', entity: User::class)]
#[AsEntityListener(event: Events::preUpdate, method: 'hashPassword', entity: User::class)]
class UserListener
{
private PasswordHasher $passwordHasher;

public function __construct(PasswordHasher $passwordHasher)
{
$this->passwordHasher = $passwordHasher;
}

public function hashPassword(User $user, LifecycleEventArgs $event): void
{
$this->passwordHasher->hashPassword($user);
}
}
30 changes: 30 additions & 0 deletions symfony/src/Security/PasswordHasher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Security;

use App\Entity\User;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;

class PasswordHasher
{
private UserPasswordHasherInterface $passwordHasher;

public function __construct(UserPasswordHasherInterface $passwordHasher)
{
$this->passwordHasher = $passwordHasher;
}

public function hashPassword(User $user): void
{
if ($user->getPlainPassword()) {
$user->setPassword(
$this->passwordHasher->hashPassword(
$user,
$user->getPlainPassword()
)
);

$user->eraseCredentials();
}
}
}
40 changes: 0 additions & 40 deletions symfony/src/Services/State/Processor/UserProcessor.php

This file was deleted.

0 comments on commit 3737023

Please sign in to comment.