Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
## Résumé
Implémentation complète du système RBAC (Role-Based Access Control) pour Coltura.
### Backend
- Entités Permission et Role avec API Platform CRUD
- PermissionVoter : vérification des permissions effectives (rôles + directes), admin bypass
- Endpoints `PATCH /users/{id}/rbac` pour assigner rôles, permissions directes et isAdmin
- AdminHeadcountGuard : protection contre la suppression du dernier admin
- Commande `app:sync-permissions` pour synchroniser les permissions déclarées par les modules
- Filtrage sidebar par permission RBAC (`permission` key optionnelle dans sidebar.php)
- 115 tests PHPUnit (fonctionnels + unitaires)
### Frontend
- Composable `usePermissions()` avec `can()`, `canAny()`, `canAll()` et admin bypass
- Page `/admin/roles` : DataTable, création/édition via drawer, suppression avec confirmation
- Page `/admin/users` : DataTable, drawer RBAC avec rôles, permissions directes, résumé effectif
- PermissionGroup : checkboxes groupées par module avec "tout sélectionner"
- EffectivePermissions : résumé lecture seule avec badges source ("via Rôle X" / "Direct")
- Warning auto-édition, toggle isAdmin
- Tests Vitest pour usePermissions
### Permissions déclarées
- `core.users.view` — Voir les utilisateurs
- `core.users.manage` — Gérer les utilisateurs
- `core.roles.view` — Voir les rôles RBAC
- `core.roles.manage` — Gérer les rôles et permissions
- `GET /api/permissions` accessible à tout utilisateur authentifié (catalogue read-only)
## Tickets Lesstime
- ERP-23 (#343) — Entités Permission et Role
- ERP-24 (#344) — API CRUD Roles & Permissions
- ERP-25 (#345) — Voter Symfony + usePermissions
- ERP-26 (#346) — Interface Admin : Gestion des Rôles
- ERP-27 (#347) — Interface Admin : Permissions Utilisateur
## Test plan
- [ ] `make db-reset` puis vérifier les fixtures (admin/alice/bob, rôles système)
- [ ] Login admin : sidebar affiche Gestion des rôles + Utilisateurs
- [ ] Login alice : sidebar masque ces onglets (pas de permission)
- [ ] Page /admin/roles : CRUD rôles, permissions groupées, protection rôles système
- [ ] Page /admin/users : assignation rôles + permissions directes, résumé effectif
- [ ] Warning auto-édition quand admin modifie ses propres droits
- [ ] `make test` : 115 tests PHPUnit passent
- [ ] `cd frontend && npm run test` : tests Vitest passent
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Matthieu <mtholot19@gmail.com>
Co-authored-by: tristan <tristan@yuno.malio.fr>
Reviewed-on: #7
Co-authored-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr>
Co-committed-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr>
155 lines
4.7 KiB
Makefile
155 lines
4.7 KiB
Makefile
# Permet d'utiliser un .env.docker.local pour override
|
|
ENV_DEFAULT = infra/dev/.env.docker
|
|
ENV_LOCAL = infra/dev/.env.docker.local
|
|
ENV_FILE := $(if $(wildcard $(ENV_LOCAL)),$(ENV_LOCAL),$(ENV_DEFAULT))
|
|
|
|
# Permet d'avoir les variables du fichier .env.docker.local
|
|
include $(ENV_DEFAULT)
|
|
-include $(ENV_LOCAL)
|
|
|
|
PHP_CONTAINER = php-$(DOCKER_APP_NAME)-fpm
|
|
SYMFONY_CONSOLE = $(EXEC_PHP) php bin/console
|
|
|
|
DOCKER_COMPOSE = docker compose --env-file $(ENV_FILE)
|
|
DOCKER = docker
|
|
|
|
EXEC_PHP = $(DOCKER) exec -t -u $(APP_USER) $(PHP_CONTAINER)
|
|
EXEC_PHP_CS_FIXER = $(EXEC_PHP) php vendor/bin/php-cs-fixer
|
|
EXEC_PHP_ROOT = $(DOCKER) exec -t -u root $(PHP_CONTAINER)
|
|
EXEC_PHP_INTERACTIVE = $(DOCKER) exec -it -u $(APP_USER) $(PHP_CONTAINER)
|
|
EXEC_PHP_INTERACTIVE_ROOT = $(DOCKER) exec -it -u root $(PHP_CONTAINER)
|
|
FILES =
|
|
|
|
#========================================================================================
|
|
|
|
env-init:
|
|
@cp --update=none $(ENV_DEFAULT) $(ENV_LOCAL)
|
|
|
|
# Lance le container
|
|
start: env-init
|
|
@echo "**** START CONTAINERS ****"
|
|
CURRENT_UID=$(shell id -u) CURRENT_GID=$(shell id -g) $(DOCKER_COMPOSE) up -d
|
|
|
|
# Éteint le container
|
|
stop:
|
|
$(DOCKER_COMPOSE) stop
|
|
|
|
restart: env-init
|
|
$(DOCKER_COMPOSE) down
|
|
CURRENT_UID=$(shell id -u) CURRENT_GID=$(shell id -g) $(DOCKER_COMPOSE) up -d
|
|
|
|
install: copy-git-hook composer-install cache-clear node-use build-nuxtJS migration-migrate test-db-setup
|
|
|
|
# Supprime tout est réinstalle tout (Attention ça supprime la bdd aussi)
|
|
reset: delete_built_dir remove_orphans build-without-cache start wait install
|
|
|
|
composer-install:
|
|
$(EXEC_PHP) composer install
|
|
$(SYMFONY_CONSOLE) lexik:jwt:generate-keypair --skip-if-exists
|
|
|
|
build-nuxtJS:
|
|
$(EXEC_PHP) sh -lc "cd frontend && npm install && npm run build:dist"
|
|
|
|
dev-nuxt:
|
|
$(EXEC_PHP) sh -c "cd frontend && npm run dev"
|
|
|
|
nuxt-lint:
|
|
$(EXEC_PHP) sh -c "cd frontend && npm run lint"
|
|
|
|
nuxt-lint-fix:
|
|
$(EXEC_PHP) sh -c "cd frontend && npm run lint:fix"
|
|
|
|
# Lance les tests unitaires frontend (Vitest)
|
|
nuxt-test:
|
|
$(EXEC_PHP) sh -c "cd frontend && npm run test"
|
|
|
|
delete_built_dir:
|
|
CURRENT_UID=$(shell id -u) CURRENT_GID=$(shell id -g) $(DOCKER_COMPOSE) up -d
|
|
$(DOCKER) exec -u root $(PHP_CONTAINER) rm -rf vendor/
|
|
$(DOCKER) exec -u root $(PHP_CONTAINER) rm -rf frontend/node_modules
|
|
|
|
remove_orphans:
|
|
$(DOCKER_COMPOSE) kill
|
|
$(DOCKER_COMPOSE) down --volumes --remove-orphans
|
|
|
|
build-without-cache:
|
|
$(DOCKER_COMPOSE) build \
|
|
--build-arg="DOCKER_PHP_VERSION=$(DOCKER_PHP_VERSION)" \
|
|
--build-arg="DOCKER_NODE_VERSION=$(DOCKER_NODE_VERSION)" \
|
|
--build-arg="CURRENT_UID=$(shell id -u)" \
|
|
--build-arg="CURRENT_GID=$(shell id -g)" \
|
|
--no-cache
|
|
|
|
migration-migrate:
|
|
$(SYMFONY_CONSOLE) doctrine:migrations:migrate --no-interaction
|
|
|
|
# Cree et initialise la base de test utilisee par PHPUnit
|
|
# (le suffixe "_test" est applique automatiquement par Doctrine en APP_ENV=test)
|
|
# Ordre : fixtures -> sync-permissions, car fixtures:load purge la table permission
|
|
test-db-setup:
|
|
$(SYMFONY_CONSOLE) doctrine:database:create --env=test --if-not-exists
|
|
$(SYMFONY_CONSOLE) doctrine:migrations:migrate --env=test --no-interaction
|
|
$(SYMFONY_CONSOLE) --env=test --no-interaction doctrine:fixtures:load
|
|
$(SYMFONY_CONSOLE) --env=test --no-interaction app:sync-permissions
|
|
|
|
fixtures:
|
|
$(SYMFONY_CONSOLE) --no-interaction doctrine:fixtures:load
|
|
|
|
# Synchronise le catalogue de permissions RBAC avec les declarations
|
|
# des modules actifs (CoreModule::permissions() etc.). Idempotent.
|
|
sync-permissions:
|
|
$(SYMFONY_CONSOLE) --no-interaction app:sync-permissions
|
|
|
|
# Attention, supprime votre bdd local
|
|
db-reset:
|
|
$(DOCKER_COMPOSE) down -v
|
|
$(DOCKER_COMPOSE) up -d
|
|
$(MAKE) wait
|
|
$(SYMFONY_CONSOLE) doctrine:database:create --if-not-exists
|
|
$(MAKE) migration-migrate
|
|
$(MAKE) fixtures
|
|
$(MAKE) sync-permissions
|
|
$(MAKE) test-db-setup
|
|
|
|
# Restart la bdd
|
|
db-restart:
|
|
$(DOCKER_COMPOSE) down
|
|
$(DOCKER_COMPOSE) up -d
|
|
|
|
cache-clear:
|
|
$(SYMFONY_CONSOLE) cache:clear
|
|
|
|
copy-git-hook:
|
|
$(EXEC_PHP) cp pre-commit .git/hooks/
|
|
$(EXEC_PHP) cp commit-msg .git/hooks/
|
|
$(EXEC_PHP) chmod a+x .git/hooks/pre-commit
|
|
$(EXEC_PHP) chmod a+x .git/hooks/commit-msg
|
|
|
|
shell:
|
|
$(EXEC_PHP_INTERACTIVE) bash
|
|
|
|
shell-root:
|
|
$(EXEC_PHP_INTERACTIVE_ROOT) bash
|
|
|
|
# Suivi temps réel des logs dev
|
|
logs-dev:
|
|
$(EXEC_PHP_INTERACTIVE) sh -lc "tail -f var/log/dev.log"
|
|
|
|
# Force la version node
|
|
node-use:
|
|
bash -lc 'source "$$HOME/.nvm/nvm.sh" && nvm install && nvm use'
|
|
|
|
# Utilisé par le pre-commit pour fix les fichiers modifiés
|
|
php-cs-fixer-allow-risky:
|
|
@echo "Fixing files: $(FILES)"
|
|
$(EXEC_PHP_CS_FIXER) fix --config=.php-cs-fixer.dist.php --allow-risky=yes $(FILES)
|
|
|
|
test:
|
|
$(EXEC_PHP) php -d memory_limit="512M" vendor/bin/phpunit $(FILES)
|
|
|
|
# Lance l'ensemble des tests (PHPUnit back + Vitest front)
|
|
test-all: test nuxt-test
|
|
|
|
wait:
|
|
sleep 10
|