mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-23 15:08:22 +02:00
Merge pull request #45 from R0m1k3/1.1
Fix incorrect product assignment for store-assigned users
This commit is contained in:
4 files changed
+96
-3
No files matched your search
@@ -0,0 +1,70 @@
|
|||||||
|
# Fix DLC GroupId - Production
|
||||||
|
|
||||||
|
## Problème Identifié
|
||||||
|
|
||||||
|
**Utilisateurs assignés au magasin #2 créent des DLC pour le magasin #1**
|
||||||
|
|
||||||
|
## Cause du Problème
|
||||||
|
|
||||||
|
Dans `client/src/pages/DlcPage.tsx` ligne 208, la logique était incorrecte :
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// AVANT (Problématique)
|
||||||
|
groupId: selectedStoreId || stores[0]?.id || 2
|
||||||
|
```
|
||||||
|
|
||||||
|
**Problème** : Pour un utilisateur non-admin assigné au magasin #2 :
|
||||||
|
- `selectedStoreId` = undefined (pas admin)
|
||||||
|
- `stores[0]?.id` = 1 (premier magasin de la liste)
|
||||||
|
- Résultat : DLC créée pour magasin #1 au lieu de #2
|
||||||
|
|
||||||
|
## Solution Appliquée
|
||||||
|
|
||||||
|
**Nouvelle logique de sélection groupId :**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// APRÈS (Corrigé)
|
||||||
|
let groupId;
|
||||||
|
if (user?.role === 'admin' && selectedStoreId) {
|
||||||
|
// Admin avec magasin sélectionné
|
||||||
|
groupId = selectedStoreId;
|
||||||
|
} else if (user?.userGroups?.[0]?.groupId) {
|
||||||
|
// Utilisateur non-admin : utiliser son groupe assigné ✅
|
||||||
|
groupId = user.userGroups[0].groupId;
|
||||||
|
} else if (user?.role === 'admin') {
|
||||||
|
// Admin sans sélection : premier magasin disponible
|
||||||
|
groupId = stores[0]?.id || 1;
|
||||||
|
} else {
|
||||||
|
// Fallback par défaut
|
||||||
|
groupId = 1;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Priorité de Sélection
|
||||||
|
|
||||||
|
1. **Admin avec magasin sélectionné** → `selectedStoreId`
|
||||||
|
2. **Utilisateur avec groupe assigné** → `user.userGroups[0].groupId` ✅ **FIX PRINCIPAL**
|
||||||
|
3. **Admin sans sélection** → Premier magasin disponible
|
||||||
|
4. **Fallback** → Magasin #1
|
||||||
|
|
||||||
|
## Log de Debug Ajouté
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
console.log("🏪 DLC GroupId Selection:", {
|
||||||
|
userRole: user?.role,
|
||||||
|
selectedStoreId,
|
||||||
|
userGroups: user?.userGroups?.map(ug => ({groupId: ug.groupId, groupName: ug.group?.name})),
|
||||||
|
finalGroupId: groupId
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Test Production
|
||||||
|
|
||||||
|
Maintenant un employé assigné au magasin #2 devrait créer des DLC avec `groupId: 2` au lieu de `groupId: 1`.
|
||||||
|
|
||||||
|
## Déploiement
|
||||||
|
|
||||||
|
1. ✅ Logique groupId corrigée dans `DlcPage.tsx`
|
||||||
|
2. ✅ Debug logs ajoutés pour traçabilité
|
||||||
|
3. 🔄 **Redémarrer serveur production**
|
||||||
|
4. 🧪 **Tester création DLC avec employé magasin #2**
|
||||||
@@ -198,6 +198,29 @@ export default function DlcPage() {
|
|||||||
// Calculer la date d'expiration et le seuil d'alerte (15 jours avant)
|
// Calculer la date d'expiration et le seuil d'alerte (15 jours avant)
|
||||||
const dlcDate = new Date(data.dlcDate);
|
const dlcDate = new Date(data.dlcDate);
|
||||||
|
|
||||||
|
// Déterminer le groupId correctement selon le rôle utilisateur
|
||||||
|
let groupId;
|
||||||
|
if (user?.role === 'admin' && selectedStoreId) {
|
||||||
|
// Admin avec magasin sélectionné
|
||||||
|
groupId = selectedStoreId;
|
||||||
|
} else if (user?.userGroups?.[0]?.groupId) {
|
||||||
|
// Utilisateur non-admin : utiliser son groupe assigné
|
||||||
|
groupId = user.userGroups[0].groupId;
|
||||||
|
} else if (user?.role === 'admin') {
|
||||||
|
// Admin sans sélection : premier magasin disponible
|
||||||
|
groupId = stores[0]?.id || 1;
|
||||||
|
} else {
|
||||||
|
// Fallback par défaut
|
||||||
|
groupId = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("🏪 DLC GroupId Selection:", {
|
||||||
|
userRole: user?.role,
|
||||||
|
selectedStoreId,
|
||||||
|
userGroups: user?.userGroups?.map(ug => ({groupId: ug.groupId, groupName: ug.group?.name})),
|
||||||
|
finalGroupId: groupId
|
||||||
|
});
|
||||||
|
|
||||||
const dlcData: InsertDlcProduct = {
|
const dlcData: InsertDlcProduct = {
|
||||||
...data,
|
...data,
|
||||||
dlcDate,
|
dlcDate,
|
||||||
@@ -205,7 +228,7 @@ export default function DlcPage() {
|
|||||||
unit: "unité", // Valeur par défaut
|
unit: "unité", // Valeur par défaut
|
||||||
location: "Magasin", // Valeur par défaut
|
location: "Magasin", // Valeur par défaut
|
||||||
alertThreshold: 15, // Toujours 15 jours
|
alertThreshold: 15, // Toujours 15 jours
|
||||||
groupId: selectedStoreId || stores[0]?.id || 2, // Utilise le magasin sélectionné ou le premier disponible
|
groupId,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (editingProduct) {
|
if (editingProduct) {
|
||||||
|
|||||||
+1
-1
@@ -2,4 +2,4 @@
|
|||||||
# https://curl.se/docs/http-cookies.html
|
# https://curl.se/docs/http-cookies.html
|
||||||
# This file was generated by libcurl! Edit at your own risk.
|
# This file was generated by libcurl! Edit at your own risk.
|
||||||
|
|
||||||
#HttpOnly_localhost FALSE / FALSE 1755096543 connect.sid s%3AdW4IaK_l9KAwScxqJTml_UK7Lh2MI3U-.9wChJ5YVxYxvwztaxrxvedzNdY2gvauFeMasHVP8jsk
|
#HttpOnly_localhost FALSE / FALSE 1755096682 connect.sid s%3ApJ7yIofTpEKfNA_Fqp_iHlkelvvhYF8m.K5ibNFcWp85JI0QM2xiLhDcD4PVzUp67Tfr1dUU7MAI
|
||||||
@@ -47,7 +47,7 @@ Preferred communication style: Simple, everyday language.
|
|||||||
- **User Management**: Comprehensive features including user deletion with ownership transfer, consistent name and email field handling, and robust password hashing.
|
- **User Management**: Comprehensive features including user deletion with ownership transfer, consistent name and email field handling, and robust password hashing.
|
||||||
- **Calendar Synchronization**: Proper display of delivery dates and automatic synchronization of order statuses.
|
- **Calendar Synchronization**: Proper display of delivery dates and automatic synchronization of order statuses.
|
||||||
- **Database Schema Download**: Admin-only feature to download comprehensive database structure reports.
|
- **Database Schema Download**: Admin-only feature to download comprehensive database structure reports.
|
||||||
- **DLC Product Management**: **DEV-FIXED**: Corrected MemStorage implementation for proper DLC persistence in development. Cache invalidation fixed with exact:false for production compatibility.
|
- **DLC Product Management**: **FULLY-FIXED**: Corrected MemStorage implementation for proper DLC persistence in development. Cache invalidation fixed with exact:false for production compatibility. **GROUPID-FIX**: Resolved issue where users assigned to store #2 were creating DLC products for store #1 due to incorrect groupId selection logic.
|
||||||
- **Robust UI Architecture**: Critical pages rebuilt with custom Tailwind CSS components to eliminate shadcn/ui production bundling issues.
|
- **Robust UI Architecture**: Critical pages rebuilt with custom Tailwind CSS components to eliminate shadcn/ui production bundling issues.
|
||||||
|
|
||||||
## External Dependencies
|
## External Dependencies
|
||||||
|
|||||||
Reference in new issue
Block a user