From c4952825fe812d5c21dfa0a57bf1ff404f5a67fb Mon Sep 17 00:00:00 2001 From: Vikas Nale Date: Wed, 2 Apr 2025 15:58:48 +0530 Subject: [PATCH] user profile api returns duplicate FeaturePermissions. This makes permission checks impossible, as multiple permissions return the same feature ID. Instead it will return the permissionID, also now passing the list featureid's in the response --- .../ViewModels/Employee/EmployeeProfile.cs | 11 +++-------- Marco.Pms.Services/Controllers/UserController.cs | 7 +++++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Marco.Pms.Model/ViewModels/Employee/EmployeeProfile.cs b/Marco.Pms.Model/ViewModels/Employee/EmployeeProfile.cs index 33e17b5..54966b5 100644 --- a/Marco.Pms.Model/ViewModels/Employee/EmployeeProfile.cs +++ b/Marco.Pms.Model/ViewModels/Employee/EmployeeProfile.cs @@ -1,15 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Marco.Pms.Model.ViewModels.Employee +namespace Marco.Pms.Model.ViewModels.Employee { public class EmployeeProfile { public EmployeeVM EmployeeInfo { get; set; } public string[] Projects { get; set; } - public string[] FeaturePermissions { get; set; } + public string[] FeaturePermissions { get; set; } + public string[] Features { get; set; } } } diff --git a/Marco.Pms.Services/Controllers/UserController.cs b/Marco.Pms.Services/Controllers/UserController.cs index b808a3c..c8ff79c 100644 --- a/Marco.Pms.Services/Controllers/UserController.cs +++ b/Marco.Pms.Services/Controllers/UserController.cs @@ -43,7 +43,8 @@ namespace MarcoBMS.Services.Controllers List featurePermission = await _rolesHelper.GetFeaturePermissionByEmployeeID(emp.Id); string[] projectsId = []; - if (featurePermission != null && featurePermission.Exists(c => c.FeatureId.ToString() == "53176ebf-c75d-42e5-839f-4508ffac3def")) { + /* User with permission manage project can see all projects */ + if (featurePermission != null && featurePermission.Exists(c => c.Id.ToString() == "172fc9b6-755b-4f62-ab26-55c34a330614")) { List projects = await _projectsHelper.GetAllProjectByTanentID(emp.TenantId); projectsId = projects.Select(c=>c.Id.ToString()).ToArray(); } @@ -59,9 +60,11 @@ namespace MarcoBMS.Services.Controllers { EmployeeInfo = employeeVM, Projects = projectsId, - FeaturePermissions = featurePermission.Select(c => c.FeatureId.ToString()).ToArray(), + FeaturePermissions = featurePermission.Select(c => c.Id.ToString()).Distinct().ToArray(), + Features = featurePermission.Select(c => c.FeatureId.ToString()).Distinct().ToArray(), }; + return Ok(profile); } } -- 2.43.0