From 25eafb1c6eb7f15c538742b26464223b7e5c4b7e Mon Sep 17 00:00:00 2001 From: frakarr Date: Tue, 9 Dec 2025 14:15:43 +0100 Subject: [PATCH] feat: Refine notice filtering and Docker setup Implement granular notice filtering logic based on user roles and notice targeting. Update Dockerfiles and .dockerignore for a cleaner build process. --- .dockerignore | Bin 89 -> 136 bytes Dockerfile | 15 --------------- nginx.conf | 38 -------------------------------------- pages/FamilyList.tsx | 23 ++++++++++++++++++++--- server/Dockerfile | 13 ------------- 5 files changed, 20 insertions(+), 69 deletions(-) diff --git a/.dockerignore b/.dockerignore index 21edd644e3803ddbc480cea5c66a3986704aed4a..276bbec6497998dcc0f46046911191732494e1c2 100644 GIT binary patch literal 136 zcmaFAfA9PKd*gsOOBP6k196$QE)xfkW&~m&VlV*`UO=o}2_$5I7=nu6EC?gh8A8j! Y#jB35hO;3I6nmJ|<8rux;vj?K0B1~FyZ`_I literal 89 zcmW;Eu?>JQ3`EiXcEM9*0|r1SK2SswBO4;IJ&5KPulU`ROEbMI16tyO?BxslfTVeu hFLOdIAM`0(J1rr4m6ObVyOIkP-QN;sugEA5H)O diff --git a/Dockerfile b/Dockerfile index bb87fa8..e69de29 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +0,0 @@ -# Stage 1: Build Frontend -FROM node:18-alpine as build -WORKDIR /app -COPY package*.json ./ -RUN npm install -COPY . . -RUN npm run build - -# Stage 2: Serve with Nginx -FROM nginx:alpine -COPY --from=build /app/dist /usr/share/nginx/html -# Copy the nginx configuration file (using the .txt extension as provided in source) -COPY nginx.txt /etc/nginx/nginx.conf -EXPOSE 80 -CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx.conf b/nginx.conf index f8625d9..e69de29 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,38 +0,0 @@ -worker_processes 1; - -events { worker_connections 1024; } - -http { - include mime.types; - default_type application/octet-stream; - sendfile on; - keepalive_timeout 65; - - server { - listen 80; - root /usr/share/nginx/html; - index index.html; - - # Limite upload per allegati (es. foto/video ticket) - Allineato con il backend - client_max_body_size 50M; - - # Compressione Gzip - gzip on; - gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; - - # Gestione SPA (React Router) - location / { - try_files $uri $uri/ /index.html; - } - - # Proxy API verso il backend - location /api/ { - proxy_pass http://backend:3001; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_cache_bypass $http_upgrade; - } - } -} diff --git a/pages/FamilyList.tsx b/pages/FamilyList.tsx index 3e2bbe8..81a9aa3 100644 --- a/pages/FamilyList.tsx +++ b/pages/FamilyList.tsx @@ -30,12 +30,29 @@ export const FamilyList: React.FC = () => { setSettings(appSettings); if (condo && currentUser && appSettings.features.notices) { - const condoNotices = allNotices.filter(n => n.condoId === condo.id && n.active); + // Filter notices logic: + // 1. Must belong to current condo and be active + // 2. If Admin/PowerUser -> See everything + // 3. If standard User -> See Public notices (no target) OR Targeted notices containing their familyId + const isPrivileged = currentUser.role === 'admin' || currentUser.role === 'poweruser'; + + const condoNotices = allNotices.filter(n => { + if (n.condoId !== condo.id || !n.active) return false; + + if (isPrivileged) return true; + + // Check targeting + const hasTargets = n.targetFamilyIds && n.targetFamilyIds.length > 0; + if (!hasTargets) return true; // Public to all + + return currentUser.familyId && n.targetFamilyIds?.includes(currentUser.familyId); + }); + setNotices(condoNotices); // Check which ones are read const readStatuses = await Promise.all(condoNotices.map(n => CondoService.getNoticeReadStatus(n.id))); - const readIds = []; + const readIds: string[] = []; readStatuses.forEach((reads, idx) => { if (reads.find(r => r.userId === currentUser.id)) { readIds.push(condoNotices[idx].id); @@ -182,4 +199,4 @@ export const FamilyList: React.FC = () => { ); -}; \ No newline at end of file +}; diff --git a/server/Dockerfile b/server/Dockerfile index 9a6d3cb..e69de29 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,13 +0,0 @@ -FROM node:18-alpine -WORKDIR /app - -# Set production environment -ENV NODE_ENV=production - -COPY package*.json ./ -RUN npm install --production - -COPY . . - -EXPOSE 3001 -CMD ["node", "server.js"]