Skip to content

Commit a707bf7

Browse files
Benoit NgoNgob
Benoit Ngo
authored andcommitted
Bug fixing (password not hashed on update), fixing CI and refactoring user component
1 parent f1b4121 commit a707bf7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+580
-565
lines changed

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ blogs: ## Display logs of back
5454
flogs: sync-env ## Display logs of front
5555
docker compose logs front -f
5656
.PHONY: init-dev
57+
## We add `; \` to ignore error. `cp -n .env.dist .env;` could not work if .env exist already, it wont be replaced
5758
init-dev: sync-env ## Init dev env
58-
cp -n docker-compose.override.yml.template docker-compose.override.yml
59-
if uname | grep -ivq "linux"; then \
60-
echo "Add $(BASE_DOMAIN) and $(API_DOMAIN) and samltest.$(BASE_DOMAIN) to your /etc/hosts"; \
61-
if grep -q $(BASE_DOMAIN) /etc/hosts ; then echo "not adding to /etc/hosts" ; else echo "\n127.0.0.1 $(BASE_DOMAIN) $(API_DOMAIN) samltest.$(BASE_DOMAIN)" | sudo tee -a /etc/hosts ; fi \
59+
cp -n .env.dist .env; \
60+
cp -n docker-compose.override.yml.template docker-compose.override.yml; \
61+
if uname | grep -iq "linux\|darwin"; then \
62+
echo "Add $(BASE_DOMAIN) and $(API_DOMAIN) mail.${BASE_DOMAIN} and samltest.$(BASE_DOMAIN) to your /etc/hosts"; \
63+
if grep -q $(BASE_DOMAIN) /etc/hosts ; then echo "not adding to /etc/hosts" ; else printf "\n127.0.0.1 $(BASE_DOMAIN) $(API_DOMAIN) samltest.$(BASE_DOMAIN) mail.${BASE_DOMAIN}\n" | sudo tee -a /etc/hosts ; fi \
6264
fi
6365
#
6466
# Theses are usefull when you use docker

apps/back/Dockerfile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# syntax=docker.io/docker/dockerfile:1.4
2-
ARG IMAGE_VERSION=php:8.1-v4
2+
ARG IMAGE_VERSION=php:8.2-v4
33
ARG APP_ENV=prod
44
ARG APP_SOURCE_FILE='./'
55
ARG PHP_EXTENSIONS="apcu mysqli pdo_mysql intl gd xdebug"
@@ -51,11 +51,12 @@ ENV PHP_INI_REALPATH_CACHE_TTL="600"
5151
RUN composer install --no-dev --no-scripts --no-interaction --optimize-autoloader
5252

5353
# This need to be here to prevent docker to recompile composer layers at each build
54-
COPY --link --chown=docker:docker ./config/ /var/www/html/config/
55-
COPY --link --chown=docker:docker ./migrations/ /var/www/html/migrations/
56-
COPY --link --chown=docker:docker ./phpstan/ /var/www/html/phpstan/
57-
COPY --link --chown=docker:docker ./public/ /var/www/html/public/
58-
COPY --link --chown=docker:docker ./src/ /var/www/html/src/
59-
COPY --link --chown=docker:docker ./migrations/ /var/www/html/migrations/
54+
COPY --link --chown=1000:1000 ./templates/ /var/www/html/templates/
55+
COPY --link --chown=1000:1000 ./public/ /var/www/html/public/
56+
COPY --link --chown=1000:1000 ./phpstan/ /var/www/html/phpstan/
57+
COPY --link --chown=1000:1000 ./config/ /var/www/html/config/
58+
COPY --link --chown=1000:1000 ./migrations/ /var/www/html/migrations/
59+
COPY --link --chown=1000:1000 ./src/ /var/www/html/src/
60+
6061
RUN composer dump-autoload --no-dev --classmap-authoritative
6162
USER docker

apps/back/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
"doctrine/annotations": "^1.0",
1111
"doctrine/doctrine-bundle": "^2.7",
1212
"doctrine/doctrine-migrations-bundle": "^3.2",
13-
"doctrine/orm": "^2.13",
13+
"doctrine/orm": "^2.14",
1414
"onelogin/php-saml": "^4.1",
1515
"phpdocumentor/reflection-docblock": "^5.3",
1616
"phpstan/phpdoc-parser": "^1.13",
1717
"ramsey/uuid": "^4.5",
18-
"sensio/framework-extra-bundle": "^6.2",
1918
"symfony/apache-pack": "^1.0",
2019
"symfony/console": "6.3.*",
2120
"symfony/dotenv": "6.3.*",

apps/back/composer.lock

Lines changed: 1 addition & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/back/config/bundles.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
77
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
88
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
9-
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
109
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
11-
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
1210
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
1311
DAMA\DoctrineTestBundle\DAMADoctrineTestBundle::class => ['test' => true],
1412
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],

apps/back/config/packages/security.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ security:
1919
provider: app_user_provider
2020
json_login:
2121
check_path: api_login
22-
# custom_authenticators:
23-
# - 'App\Authenticator\Saml2Authenticator'
22+
# custom_authenticators:
23+
# - 'App\Authenticator\Saml2Authenticator'
2424

2525
# activate differents ways to authenticate
2626
# https://symfony.com/doc/current/security.html#the-firewall
@@ -46,7 +46,7 @@ security:
4646
ROLE_USER:
4747
- ROLE_RIGHT_ACCESS
4848

49-
# this shall be removed for kb
49+
5050
when@test:
5151
security:
5252
password_hashers:

apps/back/config/packages/sensio_framework_extra.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

apps/back/config/services.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Put parameters here that don't need to change on each machine where the app is deployed
55
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
66
parameters:
7+
app.mail.host: "%env(MAIL_HOST)%"
78
app.url.base: "%env(APP_URL)%"
89
app.url.prefix: "%env(APP_PREFIX)%"
910
# app.url.webapp: "%env(APP_URL_WEBAPP)%"
@@ -38,7 +39,8 @@ services:
3839
_defaults:
3940
autowire: true # Automatically injects dependencies in your services.
4041
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
41-
42+
bind:
43+
$mailHost: "%app.mail.host%"
4244
# makes classes in src/ available to be used as services
4345
# this creates a service per class whose id is the fully-qualified class name
4446
App\:

apps/back/migrations/Version20230208155959.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

apps/back/phpmd.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<description>
1010
My custom rule set that checks my code...
1111
</description>
12+
<!-- Defining another value for the same key in an array literal overrides the previous key/value, which makes it effectively an unused code. -->
13+
<rule ref="rulesets/design.xml/EmptyCatchBlock" />
1214

1315
<!-- Defining another value for the same key in an array literal overrides the previous key/value, which makes it effectively an unused code. -->
1416
<rule ref="rulesets/cleancode.xml/DuplicatedArrayKey" />
@@ -47,6 +49,14 @@
4749
</properties>
4850
</rule>
4951

52+
<!-- Prevent else to ensure early return -->
53+
<rule ref="rulesets/cleancode.xml/ErrorControlOperator"/>
54+
55+
<!-- Prevent assignment in if -->
56+
<rule ref="rulesets/cleancode.xml/IfStatementAssignment"/>
57+
58+
<!-- Prevent else to ensure early return -->
59+
<rule ref="rulesets/cleancode.xml/ElseExpression"/>
5060

5161
<!-- Prevent var_dump and debug functions -->
5262
<rule ref="rulesets/design.xml/DevelopmentCodeFragment"/>
@@ -57,6 +67,20 @@
5767
<!-- Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'. -->
5868
<rule ref="rulesets/naming.xml/BooleanGetMethodName"/>
5969

70+
<!-- Prevent short name -->
71+
<rule ref="rulesets/naming.xml/ShortVariable">
72+
<properties>
73+
<property name="exceptions">
74+
<value>
75+
e,url,log,id
76+
</value>
77+
</property>
78+
</properties>
79+
</rule>
80+
81+
<!-- Class/Interface constant names should always be defined in uppercase. -->
82+
<rule ref="rulesets/naming.xml/ConstantNamingConventions"/>
83+
6084
<!-- Prevent unused code -->
6185
<rule ref="rulesets/unusedcode.xml">
6286
<!--- Should be used (and ignored in some specific case) but would require to understand WHY parameter have to be used -->

apps/back/phpstan.neon

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,59 +15,8 @@ parameters:
1515
excludePaths:
1616
- src/Kernel.php
1717
includes:
18-
- vendor/symplify/astral/config/services.neon
1918
- vendor/symplify/phpstan-extensions/config/config.neon
20-
# for cognitive rules
21-
- vendor/symplify/phpstan-rules/packages/cognitive-complexity/config/cognitive-complexity-services.neon
22-
- vendor/symplify/phpstan-rules/config/services/services.neon
2319
- vendor/phpstan/phpstan-doctrine/extension.neon
2420
- vendor/phpstan/phpstan-doctrine/rules.neon
25-
# - vendor/symplify/phpstan-rules/packages/symfony/config/services.neon
2621

27-
services:
28-
# Must check https://github.com/symplify/phpstan-rules/blob/master/docs/rules_overview.md
29-
# Method that return a boolean must start with is**
30-
-
31-
class: Symplify\PHPStanRules\Rules\BoolishClassMethodPrefixRule
32-
tags: [phpstan.rules.rule]
33-
34-
35-
# TODO @BEN retest that
36-
# Method parameters must be compatible with its parent
37-
# -
38-
# class: Symplify\PHPStanRules\Rules\CheckParentChildMethodParameterTypeCompatibleRule
39-
# tags: [phpstan.rules.rule]
40-
41-
42-
43-
# Prevent else / elseif
44-
-
45-
class: Symplify\PHPStanRules\ObjectCalisthenics\Rules\NoElseAndElseIfRule
46-
tags: [phpstan.rules.rule]
47-
# Maximum complexity of a function
48-
-
49-
class: Symplify\PHPStanRules\CognitiveComplexity\Rules\FunctionLikeCognitiveComplexityRule
50-
tags: [phpstan.rules.rule]
51-
arguments:
52-
maxMethodCognitiveComplexity: 16
53-
54-
# TODO @BEN retest that
55-
# Prevent Setter Method (promote behavior name)
56-
# -
57-
# class: Symplify\PHPStanRules\ObjectCalisthenics\Rules\NoSetterClassMethodRule
58-
# tags: [phpstan.rules.rule]
59-
60-
61-
# TODO @BEN retest that
62-
# Forbid assignement in IF
63-
# -
64-
# class: Symplify\PHPStanRules\Rules\ForbiddenAssignInIfRule
65-
# tags: [phpstan.rules.rule]
66-
# Forbid short name like $i
67-
-
68-
class: Symplify\PHPStanRules\ObjectCalisthenics\Rules\NoShortNameRule
69-
tags: [phpstan.rules.rule]
70-
arguments:
71-
minNameLength: 3
72-
allowedShortNames: ['id']
7322
## May have to add static forbidden

apps/back/src/Controller/AuthController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
use App\Entity\User;
88
use OneLogin\Saml2\Auth;
9-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
109
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1110
use Symfony\Component\HttpFoundation\JsonResponse;
1211
use Symfony\Component\HttpFoundation\RedirectResponse;
1312
use Symfony\Component\HttpFoundation\Response;
1413
use Symfony\Component\Routing\Annotation\Route;
1514
use Symfony\Component\Security\Http\Attribute\CurrentUser;
15+
use Symfony\Component\Security\Http\Attribute\IsGranted;
1616

1717
class AuthController extends AbstractController
1818
{
@@ -30,7 +30,7 @@ public function samlLogin(): Response
3030
}
3131

3232
#[Route('/login', name: 'api_login', methods: ['POST'])]
33-
public function login(#[CurrentUser] ?User $user): JsonResponse
33+
public function login(#[CurrentUser] User|null $user): JsonResponse
3434
{
3535
return new JsonResponse($user);
3636
}

apps/back/src/Controller/HealthCheckController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace App\Controller;
66

7-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
87
use Symfony\Component\HttpFoundation\JsonResponse;
98
use Symfony\Component\Routing\Annotation\Route;
9+
use Symfony\Component\Security\Http\Attribute\IsGranted;
1010

1111
class HealthCheckController
1212
{

0 commit comments

Comments
 (0)