From 962061b7e4f45df2f06436cd9d41a87e9780ee00 Mon Sep 17 00:00:00 2001 From: Jonathan Senning Date: Fri, 28 Jun 2024 17:08:07 -0400 Subject: [PATCH 1/6] Changed ProfileItem; Encapsulated some profile information --- Gordon360/Controllers/ProfilesController.cs | 3 +- Gordon360/Documentation/Gordon360.xml | 3 +- .../ViewModels/CombinedProfileViewModel.cs | 27 +++++------------ Gordon360/Services/ProfileService.cs | 30 ++++++++----------- Gordon360/Services/ServiceInterfaces.cs | 2 +- Gordon360/Static Classes/ProfileItem.cs | 4 +-- 6 files changed, 27 insertions(+), 42 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index eae502e87..6aca8ae35 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -46,6 +46,7 @@ public class ProfilesController(IProfileService profileService, return Ok(null); } + //var profile = profileService.ComposeProfile(student, alumni, faculty, customInfo); var profile = (CombinedProfileViewModel) profileService.ComposeProfile(student, alumni, faculty, customInfo); return Ok(profile); @@ -104,7 +105,7 @@ public class ProfilesController(IProfileService profileService, var profile = profileService.ComposeProfile(student, alumni, faculty, _customInfo); - var cleaned_profile = profileService.ImposePrivacySettings(username, viewerGroups, profile); + var cleaned_profile = profileService.ImposePrivacySettings(viewerGroups, profile); return Ok(cleaned_profile); } diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index cc6f79ce7..e99440fdd 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -2201,11 +2201,10 @@ - + convert combined profile to public profile based on individual privacy settings - username of the person being searched list of AuthGroups the logged-in user belongs to combined profile of the person being searched public profile of the person based on individual privacy settings diff --git a/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs b/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs index 879ccc996..5664774c4 100644 --- a/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs @@ -18,21 +18,16 @@ public class CombinedProfileViewModel public string Gender { get; set; } public string HomeStreet1 { get; set; } public string HomeStreet2 { get; set; } - public string HomeCity { get; set; } - //public ProfileItem HomeCity { get; set; } - public string HomeState { get; set; } - //public ProfileItem HomeState { get; set; } + public ProfileItem HomeCity { get; set; } + public ProfileItem HomeState { get; set; } public string HomePostalCode { get; set; } - public string HomeCountry { get; set; } - //public ProfileItem HomeCountry { get; set; } - //public string HomePhone { get; set; } + public ProfileItem HomeCountry { get; set; } public ProfileItem HomePhone { get; set; } public string HomeFax { get; set; } public string AD_Username { get; set; } public Nullable show_pic { get; set; } public Nullable preferred_photo { get; set; } - public string Country { get; set; } - //public ProfileItem Country { get; set; } + public ProfileItem Country { get; set; } public string Barcode { get; set; } public string Facebook { get; set; } public string Twitter { get; set; } @@ -129,21 +124,16 @@ public static implicit operator CombinedProfileViewModel(ProfileViewModel vm) Gender = vm.Gender, HomeStreet1 = vm.HomeStreet1, HomeStreet2 = vm.HomeStreet2, - //HomeCity = vm.HomeCity is null || vm.HomeCity == "" ? null : new ProfileItem(vm.HomeCity, false), - HomeCity = vm.HomeCity, - //HomeState = vm.HomeState is null || vm.HomeState == "" ? null : new ProfileItem(vm.HomeState, false), - HomeState = vm.HomeState, + HomeCity = vm.HomeCity is null || vm.HomeCity == "" ? null : new ProfileItem(vm.HomeCity, false), + HomeState = vm.HomeState is null || vm.HomeState == "" ? null : new ProfileItem(vm.HomeState, false), HomePostalCode = vm.HomePostalCode, - //HomeCountry = vm.HomeCountry is null || vm.HomeCountry == "" ? null : new ProfileItem(vm.HomeCountry, false), - HomeCountry = vm.HomeCountry, + HomeCountry = vm.HomeCountry is null || vm.HomeCountry == "" ? null : new ProfileItem(vm.HomeCountry, false), HomePhone = vm.HomePhone is null || vm.HomePhone == "" ? null : new ProfileItem(vm.HomePhone, false), - //HomePhone = vm.HomePhone, HomeFax = vm.HomeFax, AD_Username = vm.AD_Username, show_pic = vm.show_pic, preferred_photo = vm.preferred_photo, - //Country = vm.Country is null || vm.Country == "" ? null : new ProfileItem(vm.Country, false), - Country = vm.Country, + Country = vm.Country is null || vm.Country == "" ? null : new ProfileItem(vm.Country, false), Barcode = vm.Barcode, Facebook = vm.Facebook, Twitter = vm.Twitter, @@ -208,7 +198,6 @@ public static implicit operator CombinedProfileViewModel(ProfileViewModel vm) // FacStaff and Alumni Only JobTitle = vm.JobTitle, -// SpouseName = new ProfileItem(vm.SpouseName, false), SpouseName = vm.SpouseName is null || vm.SpouseName == "" ? null : new ProfileItem(vm.SpouseName, false), // FacStaff and Student Only diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 3f654f983..8937a2cde 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -276,12 +276,11 @@ public async Task UpdateCustomProfileAsync(string username, string type, CUSTOM_ /// /// convert combined profile to public profile based on individual privacy settings /// - /// username of the person being searched /// list of AuthGroups the logged-in user belongs to /// combined profile of the person being searched /// public profile of the person based on individual privacy settings public CombinedProfileViewModel ImposePrivacySettings - (string username, IEnumerable viewerGroups, ProfileViewModel profile) + (IEnumerable viewerGroups, ProfileViewModel profile) { CombinedProfileViewModel public_profile = (CombinedProfileViewModel) profile; @@ -292,8 +291,7 @@ public CombinedProfileViewModel ImposePrivacySettings } // select all privacy settings -// var account = accountService.GetAccountByUsername(public_profile.AD_Username); - var account = accountService.GetAccountByUsername(username); + var account = accountService.GetAccountByUsername(public_profile.AD_Username); var privacy = context.UserPrivacy_Settings.Where(up_s => up_s.gordon_id == account.GordonID); Type cpvm = new CombinedProfileViewModel().GetType(); @@ -311,10 +309,17 @@ public CombinedProfileViewModel ImposePrivacySettings else if (public_profile.PersonType.Contains("stu")) { // Information remains visible, but marked as private - PropertyInfo prop = cpvm.GetProperty(row.Field); - ProfileItem profile_item = (ProfileItem) prop.GetValue(public_profile); - profile_item.isPrivate = true; - prop.SetValue(public_profile, profile_item); + try + { + PropertyInfo prop = cpvm.GetProperty(row.Field); + ProfileItem profile_item = (ProfileItem) prop.GetValue(public_profile); + profile_item.isPrivate = true; + prop.SetValue(public_profile, profile_item); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } } } } @@ -331,15 +336,6 @@ public CombinedProfileViewModel ImposePrivacySettings } } - // Make profile item private - //cpvm.GetProperty("SpouseName").SetValue(public_profile, null); - - // Mark profile item as private - // PropertyInfo prop = cpvm.GetProperty("SpouseName"); - // ProfileItem profile_item = (ProfileItem) prop.GetValue(public_profile); - // profile_item.isPrivate = true; - // prop.SetValue(public_profile, profile_item); - return public_profile; } diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index 54647b6f4..8ddf5b5e3 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -36,7 +36,7 @@ public interface IProfileService Task UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom); Task UpdateOfficeHoursAsync(string username, string newHours); CombinedProfileViewModel ImposePrivacySettings - (string username, IEnumerable viewerGroups, ProfileViewModel profile); + (IEnumerable viewerGroups, ProfileViewModel profile); PublicFacultyStaffProfileViewModel ToPublicFacultyStaffProfileViewModel (string username, string currentUserType, FacultyStaffProfileViewModel fac); PublicStudentProfileViewModel ToPublicStudentProfileViewModel diff --git a/Gordon360/Static Classes/ProfileItem.cs b/Gordon360/Static Classes/ProfileItem.cs index 20f5efc6b..a0995f762 100644 --- a/Gordon360/Static Classes/ProfileItem.cs +++ b/Gordon360/Static Classes/ProfileItem.cs @@ -5,9 +5,9 @@ namespace Gordon360.Static.Methods; /// public record ProfileItem{ public ProfileItem (object d, bool p) { - data = d; + value = d; isPrivate = p; } - public object data { get; set; } + public object value { get; set; } public bool isPrivate { get; set ;} } \ No newline at end of file From 9f9dd59d8bfa36a6b79c272e50be4b59ad533c46 Mon Sep 17 00:00:00 2001 From: Jonathan Senning Date: Sun, 30 Jun 2024 16:43:31 -0400 Subject: [PATCH 2/6] Converted names to ProfileItems --- .../ViewModels/CombinedProfileViewModel.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs b/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs index 5664774c4..861ca0b43 100644 --- a/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs @@ -8,12 +8,12 @@ public class CombinedProfileViewModel { public string ID { get; set; } public string Title { get; set; } - public string FirstName { get; set; } - public string MiddleName { get; set; } - public string LastName { get; set; } - public string Suffix { get; set; } - public string MaidenName { get; set; } - public string NickName { get; set; } + public ProfileItem FirstName { get; set; } + public ProfileItem MiddleName { get; set; } + public ProfileItem LastName { get; set; } + public ProfileItem Suffix { get; set; } + public ProfileItem MaidenName { get; set; } + public ProfileItem NickName { get; set; } public string Email { get; set; } public string Gender { get; set; } public string HomeStreet1 { get; set; } @@ -114,12 +114,13 @@ public static implicit operator CombinedProfileViewModel(ProfileViewModel vm) // All Profiles ID = vm.ID, Title = vm.Title, - FirstName = vm.FirstName, - MiddleName = vm.MiddleName, - LastName = vm.LastName, - Suffix = vm.Suffix, - MaidenName = vm.MaidenName, - NickName = vm.NickName, + //FirstName = vm.FirstName, + FirstName = vm.FirstName is null || vm.FirstName == "" ? null : new ProfileItem(vm.FirstName, false), + MiddleName = vm.MiddleName is null || vm.MiddleName == "" ? null : new ProfileItem(vm.MiddleName, false), + LastName = vm.LastName is null || vm.LastName == "" ? null : new ProfileItem(vm.LastName, false), + Suffix = vm.Suffix is null || vm.Suffix == "" ? null : new ProfileItem(vm.Suffix, false), + MaidenName = vm.MaidenName is null || vm.MaidenName == "" ? null : new ProfileItem(vm.MaidenName, false), + NickName = vm.NickName is null || vm.NickName == "" ? null : new ProfileItem(vm.NickName, false), Email = vm.Email, Gender = vm.Gender, HomeStreet1 = vm.HomeStreet1, From eeb400a794fcd0e4ec3a09fa962cb6dfd2360547 Mon Sep 17 00:00:00 2001 From: Jonathan Senning Date: Sun, 30 Jun 2024 17:16:00 -0400 Subject: [PATCH 3/6] a bit of cleanup --- Gordon360/Models/ViewModels/CombinedProfileViewModel.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs b/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs index 861ca0b43..940cadd24 100644 --- a/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs @@ -24,7 +24,7 @@ public class CombinedProfileViewModel public ProfileItem HomeCountry { get; set; } public ProfileItem HomePhone { get; set; } public string HomeFax { get; set; } - public string AD_Username { get; set; } + public string AD_Username { get; set; } // Leave as string public Nullable show_pic { get; set; } public Nullable preferred_photo { get; set; } public ProfileItem Country { get; set; } @@ -105,7 +105,7 @@ public class CombinedProfileViewModel public string KeepPrivate { get; set; } // ProfileViewModel Only - public string PersonType { get; set; } + public string PersonType { get; set; } // Leave as string public static implicit operator CombinedProfileViewModel(ProfileViewModel vm) { @@ -114,7 +114,6 @@ public static implicit operator CombinedProfileViewModel(ProfileViewModel vm) // All Profiles ID = vm.ID, Title = vm.Title, - //FirstName = vm.FirstName, FirstName = vm.FirstName is null || vm.FirstName == "" ? null : new ProfileItem(vm.FirstName, false), MiddleName = vm.MiddleName is null || vm.MiddleName == "" ? null : new ProfileItem(vm.MiddleName, false), LastName = vm.LastName is null || vm.LastName == "" ? null : new ProfileItem(vm.LastName, false), From 4ca53194f9465371f85e8ddf531b993c3679b633 Mon Sep 17 00:00:00 2001 From: Tsion T Tezera Date: Mon, 1 Jul 2024 17:09:44 -0400 Subject: [PATCH 4/6] removed homephone from student public view --- .../ViewModels/PublicStudentProfileViewModel.cs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/Gordon360/Models/ViewModels/PublicStudentProfileViewModel.cs b/Gordon360/Models/ViewModels/PublicStudentProfileViewModel.cs index e7ca1df86..e3e4b23df 100644 --- a/Gordon360/Models/ViewModels/PublicStudentProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/PublicStudentProfileViewModel.cs @@ -53,7 +53,6 @@ public static implicit operator PublicStudentProfileViewModel(StudentProfileView AD_Username = stu.AD_Username ?? "", // Just in case some random record has a null email field OnOffCampus = stu.OnOffCampus ?? "", Mail_Location = stu.Mail_Location ?? "", - HomePhone = stu.HomePhone ?? "", HomeCity = stu.HomeCity ?? "", HomeState = stu.HomeState ?? "", HomeCountry = stu.HomeCountry ?? "", @@ -77,15 +76,7 @@ public static implicit operator PublicStudentProfileViewModel(StudentProfileView Minor2Description = stu.Minor2Description ?? "", Minor3Description = stu.Minor3Description ?? "" }; - if (vm.KeepPrivate.Contains("S")) - { - vm.HomeCity = "Private as requested."; - vm.HomeState = ""; - vm.HomeCountry = ""; - vm.Country = ""; - vm.OnOffCampus = "P"; - vm.Hall = ""; - } + if (vm.KeepPrivate.Contains("Y") || vm.KeepPrivate.Contains("P")) { return null; From 649514ccee84721451b59ebea8779e78285b568b Mon Sep 17 00:00:00 2001 From: Jonathan Senning Date: Tue, 2 Jul 2024 07:36:57 -0400 Subject: [PATCH 5/6] Removed HomeFax from ViewModels; several new ProfileItems --- .../ViewModels/AlumniProfileViewModel.cs | 2 -- .../ViewModels/CombinedProfileViewModel.cs | 18 ++++++++---------- .../ViewModels/FacultyStaffProfileViewModel.cs | 2 -- .../ViewModels/StudentProfileViewModel.cs | 2 -- Gordon360/Services/ProfileService.cs | 4 ++-- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/Gordon360/Models/ViewModels/AlumniProfileViewModel.cs b/Gordon360/Models/ViewModels/AlumniProfileViewModel.cs index 636631853..4aef72b4d 100644 --- a/Gordon360/Models/ViewModels/AlumniProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/AlumniProfileViewModel.cs @@ -20,7 +20,6 @@ public record AlumniProfileViewModel string HomePostalCode, string HomeCountry, string HomePhone, - string HomeFax, string HomeEmail, string JobTitle, string MaritalStatus, @@ -69,7 +68,6 @@ public record AlumniProfileViewModel alu.HomePostalCode ?? "", alu.HomeCountry ?? "", alu.HomePhone ?? "", - alu.HomeFax ?? "", alu.HomeEmail ?? "", alu.JobTitle ?? "", alu.MaritalStatus ?? "", diff --git a/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs b/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs index 940cadd24..2430d64c7 100644 --- a/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/CombinedProfileViewModel.cs @@ -16,14 +16,13 @@ public class CombinedProfileViewModel public ProfileItem NickName { get; set; } public string Email { get; set; } public string Gender { get; set; } - public string HomeStreet1 { get; set; } - public string HomeStreet2 { get; set; } + public ProfileItem HomeStreet1 { get; set; } + public ProfileItem HomeStreet2 { get; set; } public ProfileItem HomeCity { get; set; } public ProfileItem HomeState { get; set; } - public string HomePostalCode { get; set; } + public ProfileItem HomePostalCode { get; set; } public ProfileItem HomeCountry { get; set; } public ProfileItem HomePhone { get; set; } - public string HomeFax { get; set; } public string AD_Username { get; set; } // Leave as string public Nullable show_pic { get; set; } public Nullable preferred_photo { get; set; } @@ -68,7 +67,7 @@ public class CombinedProfileViewModel // Alumni Only public string WebUpdate { get; set; } - public string HomeEmail { get; set; } + public ProfileItem HomeEmail { get; set; } public string MaritalStatus { get; set; } public string College { get; set; } public string ClassYear { get; set; } @@ -122,14 +121,13 @@ public static implicit operator CombinedProfileViewModel(ProfileViewModel vm) NickName = vm.NickName is null || vm.NickName == "" ? null : new ProfileItem(vm.NickName, false), Email = vm.Email, Gender = vm.Gender, - HomeStreet1 = vm.HomeStreet1, - HomeStreet2 = vm.HomeStreet2, + HomeStreet1 = vm.HomeStreet1 is null || vm.HomeStreet1 == "" ? null : new ProfileItem(vm.HomeStreet1, false), + HomeStreet2 = vm.HomeStreet2 is null || vm.HomeStreet2 == "" ? null : new ProfileItem(vm.HomeStreet2, false), HomeCity = vm.HomeCity is null || vm.HomeCity == "" ? null : new ProfileItem(vm.HomeCity, false), HomeState = vm.HomeState is null || vm.HomeState == "" ? null : new ProfileItem(vm.HomeState, false), - HomePostalCode = vm.HomePostalCode, + HomePostalCode = vm.HomePostalCode is null || vm.HomePostalCode == "" ? null : new ProfileItem(vm.HomePostalCode, false), HomeCountry = vm.HomeCountry is null || vm.HomeCountry == "" ? null : new ProfileItem(vm.HomeCountry, false), HomePhone = vm.HomePhone is null || vm.HomePhone == "" ? null : new ProfileItem(vm.HomePhone, false), - HomeFax = vm.HomeFax, AD_Username = vm.AD_Username, show_pic = vm.show_pic, preferred_photo = vm.preferred_photo, @@ -174,7 +172,7 @@ public static implicit operator CombinedProfileViewModel(ProfileViewModel vm) // Alumni Only WebUpdate = vm. WebUpdate, - HomeEmail = vm.HomeEmail, + HomeEmail = vm.HomeEmail is null || vm.HomeEmail == "" ? null : new ProfileItem(vm.HomeEmail, false), MaritalStatus = vm.MaritalStatus, College = vm.College, ClassYear = vm.ClassYear, diff --git a/Gordon360/Models/ViewModels/FacultyStaffProfileViewModel.cs b/Gordon360/Models/ViewModels/FacultyStaffProfileViewModel.cs index 5fada4198..c9b17e982 100644 --- a/Gordon360/Models/ViewModels/FacultyStaffProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/FacultyStaffProfileViewModel.cs @@ -25,7 +25,6 @@ public record FacultyStaffProfileViewModel string HomePostalCode, string HomeCountry, string HomePhone, - string HomeFax, string MobilePhone, string KeepPrivate, string JobTitle, @@ -73,7 +72,6 @@ public record FacultyStaffProfileViewModel fac.HomePostalCode ?? "", fac.HomeCountry ?? "", fac.HomePhone ?? "", - fac.HomeFax ?? "", fac.MobilePhone ?? "", fac.KeepPrivate ?? "", fac.JobTitle ?? "", diff --git a/Gordon360/Models/ViewModels/StudentProfileViewModel.cs b/Gordon360/Models/ViewModels/StudentProfileViewModel.cs index 703cb0512..88016da24 100644 --- a/Gordon360/Models/ViewModels/StudentProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/StudentProfileViewModel.cs @@ -33,7 +33,6 @@ public record StudentProfileViewModel string HomePostalCode, string HomeCountry, string HomePhone, - string HomeFax, string Cohort, string Class, string KeepPrivate, @@ -106,7 +105,6 @@ public record StudentProfileViewModel stu.HomePostalCode ?? "", stu.HomeCountry ?? "", stu.HomePhone ?? "", - stu.HomeFax ?? "", stu.Cohort ?? "", stu.Class ?? "", stu.KeepPrivate ?? "", diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 8937a2cde..02629cdcc 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -8,7 +8,7 @@ using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; -using System.IO; +using System.Diagnostics; using System.Data; using System.Linq; using System.Net; @@ -318,7 +318,7 @@ public CombinedProfileViewModel ImposePrivacySettings } catch (Exception e) { - Console.WriteLine(e.Message); + Debug.WriteLine(e.Message); } } } From 0e8fcfbee3ddfbfaba0a2c62dc971d172b923fdc Mon Sep 17 00:00:00 2001 From: Jonathan Senning Date: Tue, 2 Jul 2024 11:58:46 -0400 Subject: [PATCH 6/6] refactored ImposePrivacySettings --- Gordon360/Controllers/ProfilesController.cs | 4 +- Gordon360/Documentation/Gordon360.xml | 18 -- .../PublicAlumniProfileViewModel.cs | 8 +- Gordon360/Services/ProfileService.cs | 214 +++++++++--------- Gordon360/Services/ServiceInterfaces.cs | 7 +- 5 files changed, 117 insertions(+), 134 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index 6aca8ae35..66e67a393 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -105,9 +105,9 @@ public class ProfilesController(IProfileService profileService, var profile = profileService.ComposeProfile(student, alumni, faculty, _customInfo); - var cleaned_profile = profileService.ImposePrivacySettings(viewerGroups, profile); + var visible_profile = profileService.ImposePrivacySettings(viewerGroups, profile); - return Ok(cleaned_profile); + return Ok(visible_profile); } ///Get the advisor(s) of a particular student diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index e99440fdd..8db6d9eb4 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -2209,24 +2209,6 @@ combined profile of the person being searched public profile of the person based on individual privacy settings - - - convert original fac/staff profile to public fac/staff profile based on individual privacy settings - - username of the fac/staff being searched - personnel type of the logged-in user (fac, stu, alu) - original profile of the fac/staff being searched - public profile of the fac/staff based on individual privacy settings - - - - convert original student profile to public student profile based on individual privacy settings - - username of the student being searched - personnel type of the logged-in user - original profile of the student being searched - public profile of the student based on individual privacy settings - get privacy setting for particular user diff --git a/Gordon360/Models/ViewModels/PublicAlumniProfileViewModel.cs b/Gordon360/Models/ViewModels/PublicAlumniProfileViewModel.cs index 03ec5e47a..359bd3dd5 100644 --- a/Gordon360/Models/ViewModels/PublicAlumniProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/PublicAlumniProfileViewModel.cs @@ -75,10 +75,10 @@ public static implicit operator PublicAlumniProfileViewModel(AlumniProfileViewMo } else if (!vm.ShareAddress.Contains("Y")) { - vm.HomeCity = "Private as requested."; - vm.HomeCountry = ""; - vm.HomeState = ""; - vm.Country = ""; + vm.HomeCity = null; + vm.HomeCountry = null; + vm.HomeState = null; + vm.Country = null; } return vm; } diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 02629cdcc..b12eaee5d 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -8,7 +8,6 @@ using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Data; using System.Linq; using System.Net; @@ -22,6 +21,13 @@ namespace Gordon360.Services; public class ProfileService(CCTContext context, IConfiguration config, IAccountService accountService, webSQLContext webSQLContext) : IProfileService { + // These three-character strings are valid substrings for the PersonType + // field in the profile. These are used in the UI and so cannot be changed + // here unless the correspondin change is made in the UI. + const string FACSTAFF_PROFILE = "fac"; + const string STUDENT_PROFILE = "stu"; + const string ALUMNI_PROFILE = "alu"; + /// /// get student profile info /// @@ -282,123 +288,100 @@ public async Task UpdateCustomProfileAsync(string username, string type, CUSTOM_ public CombinedProfileViewModel ImposePrivacySettings (IEnumerable viewerGroups, ProfileViewModel profile) { - CombinedProfileViewModel public_profile = (CombinedProfileViewModel) profile; + // Convert profile from record to class so we can modify its elements + CombinedProfileViewModel restricted_profile = (CombinedProfileViewModel) profile; - // SiteAdmin and Police see full profile - if (viewerGroups.Contains(AuthGroup.SiteAdmin) || viewerGroups.Contains(AuthGroup.Police)) - { - return public_profile; - } + // Privacy settings are generally heirarchical from bypassing all + // privacy settings to honoring all privacy settings: + // SiteAdmin & Police -> FacStaff -> Students -> Alumni - // select all privacy settings - var account = accountService.GetAccountByUsername(public_profile.AD_Username); + // Find the account belonging to person whose profile we are accessing and get their + // privacy settings + var account = accountService.GetAccountByUsername(restricted_profile.AD_Username); var privacy = context.UserPrivacy_Settings.Where(up_s => up_s.gordon_id == account.GordonID); - Type cpvm = new CombinedProfileViewModel().GetType(); - if (viewerGroups.Contains(AuthGroup.FacStaff)) + // Determing the viewer and profile user types + bool viewerIsSiteAdmin = viewerGroups.Contains(AuthGroup.SiteAdmin); + bool viewerIsPolice = viewerGroups.Contains(AuthGroup.Police); + bool viewerIsFacStaff = viewerGroups.Contains(AuthGroup.FacStaff); + bool viewerIsStudent = viewerGroups.Contains(AuthGroup.Student); + bool viewerIsAlumni = viewerGroups.Contains(AuthGroup.Alumni); + bool profileIsFacStaff = restricted_profile.PersonType.Contains(FACSTAFF_PROFILE); + bool profileIsStudent = restricted_profile.PersonType.Contains(STUDENT_PROFILE); + bool profileIsAlumni = restricted_profile.PersonType.Contains(ALUMNI_PROFILE); + + foreach (UserPrivacy_Settings row in privacy) { - foreach (UserPrivacy_Settings row in privacy) + if ((viewerIsSiteAdmin || viewerIsPolice) && row.Visibility != "Public") { - if (row.Visibility == "Private") - { - if (public_profile.PersonType.Contains("fac")) - { - // Remove information from profile - cpvm.GetProperty(row.Field).SetValue(public_profile, null); - } - else if (public_profile.PersonType.Contains("stu")) - { - // Information remains visible, but marked as private - try - { - PropertyInfo prop = cpvm.GetProperty(row.Field); - ProfileItem profile_item = (ProfileItem) prop.GetValue(public_profile); - profile_item.isPrivate = true; - prop.SetValue(public_profile, profile_item); - } - catch (Exception e) - { - Debug.WriteLine(e.Message); - } - } - } + MarkAsPrivate(restricted_profile, row.Field); } - } - else if (viewerGroups.Contains(AuthGroup.Student) || viewerGroups.Contains(AuthGroup.Alumni)) - { - foreach (UserPrivacy_Settings row in privacy) + else if (viewerIsFacStaff) { - if (row.Visibility == "Private" || row.Visibility == "FacStaff") + if (profileIsFacStaff && row.Visibility == "Private") { - // Remove information from profile - cpvm.GetProperty(row.Field).SetValue(public_profile, null); + MakePrivate(restricted_profile, row.Field); + } + else if ((profileIsStudent || profileIsAlumni) && row.Visibility != "Public") + { + MarkAsPrivate(restricted_profile, row.Field); } } - } - - return public_profile; - } - - /// - /// convert original fac/staff profile to public fac/staff profile based on individual privacy settings - /// - /// username of the fac/staff being searched - /// personnel type of the logged-in user (fac, stu, alu) - /// original profile of the fac/staff being searched - /// public profile of the fac/staff based on individual privacy settings - public PublicFacultyStaffProfileViewModel ToPublicFacultyStaffProfileViewModel - (string username, string currentUserType, FacultyStaffProfileViewModel fac) - { - PublicFacultyStaffProfileViewModel publicFac = (PublicFacultyStaffProfileViewModel)fac; - var account = accountService.GetAccountByUsername(username); - - // select all privacy settings - var privacy = context.UserPrivacy_Settings.Where(up_s => up_s.gordon_id == account.GordonID); - // get type of viewmodel for reflection property setting - Type fs_vm = new PublicFacultyStaffProfileViewModel().GetType(); - - foreach (UserPrivacy_Settings row in privacy) - { - if (row.Visibility == "Private" || (row.Visibility == "FacStaff" && currentUserType != "fac")) - { - fs_vm.GetProperty(row.Field).SetValue(publicFac, "Private as requested."); - } - } - - return publicFac; - } - - /// - /// convert original student profile to public student profile based on individual privacy settings - /// - /// username of the student being searched - /// personnel type of the logged-in user - /// original profile of the student being searched - /// public profile of the student based on individual privacy settings - public PublicStudentProfileViewModel ToPublicStudentProfileViewModel - (string username, string currentUserType, StudentProfileViewModel stu) - { - PublicStudentProfileViewModel publicStu = (PublicStudentProfileViewModel)stu; - var account = accountService.GetAccountByUsername(username); - - // select all privacy settings - var privacy = context.UserPrivacy_Settings.Where(up_s => up_s.gordon_id == account.GordonID); - // get type of viewmodel for reflection property setting - Type s_vm = new PublicStudentProfileViewModel().GetType(); - - foreach (UserPrivacy_Settings row in privacy) - { - if (row.Visibility == "Private" || (row.Visibility == "FacStaff" && currentUserType != "fac")) + else if (viewerIsStudent && row.Visibility != "Public") { - s_vm.GetProperty(row.Field).SetValue(publicStu, "Private as requested."); + MakePrivate(restricted_profile, row.Field); } - if (row.Field == "MobilePhone") + else if (viewerIsAlumni && row.Visibility != "Public") { - s_vm.GetProperty("IsMobilePhonePrivate").SetValue(publicStu, row.Visibility != "Public"); + MakePrivate(restricted_profile, row.Field); } } - return publicStu; + // if (viewerIsSiteAdmin || viewerIsPolice) + // { + // foreach (UserPrivacy_Settings row in privacy) + // { + // if (row.Visibility != "Public") + // { + // MarkAsPrivate(restricted_profile, row.Field); + // } + // } + // } + // else if (viewerIsFacStaff) + // { + // foreach (UserPrivacy_Settings row in privacy) + // { + // if (row.Visibility == "Private") + // { + // if (profileIsFacStaff) + // { + // MakePrivate(restricted_profile, row.Field); + // } + // else if (profileIsStudent) + // { + // MarkAsPrivate(restricted_profile, row.Field); + // } + // } + // if (row.Visibility == "FacStaff" && profileIsStudent) + // { + // MarkAsPrivate(restricted_profile, row.Field); + // } + // // no other adjustments necessary for FacStaff viewers + // } + // } + // else if (viewerIsStudent || viewerIsAlumni) + // { + // foreach (UserPrivacy_Settings row in privacy) + // { + // if (row.Visibility != "Public") + // { + // // Remove information from profile + // MakePrivate(restricted_profile, row.Field); + // } + // } + // } + + return restricted_profile; } /// @@ -588,19 +571,19 @@ public async Task UpdateImagePrivacyAsync(string username, string value) if (student != null) { MergeProfile(profile, JObject.FromObject(student)); - personType += "stu"; + personType += STUDENT_PROFILE; } if (alumni != null) { MergeProfile(profile, JObject.FromObject(alumni)); - personType += "alu"; + personType += ALUMNI_PROFILE; } if (faculty != null) { MergeProfile(profile, JObject.FromObject(faculty)); - personType += "fac"; + personType += FACSTAFF_PROFILE; } if (customInfo != null) @@ -675,4 +658,27 @@ public IEnumerable GetMailStopsAsync() return webSQLContext.Mailstops.Select(m => m.code) .OrderBy(d => d); } + + private static void MarkAsPrivate(CombinedProfileViewModel profile, string field) + { + Type cpvm = new CombinedProfileViewModel().GetType(); + try + { + PropertyInfo prop = cpvm.GetProperty(field); + ProfileItem profile_item = (ProfileItem) prop.GetValue(profile); + profile_item.isPrivate = true; + prop.SetValue(profile, profile_item); + } + catch (Exception) + { + // silently fail return -1; + } + //return 0; + } + + private static void MakePrivate(CombinedProfileViewModel profile, string field) + { + Type cpvm = new CombinedProfileViewModel().GetType(); + cpvm.GetProperty(field).SetValue(profile, null); + } } \ No newline at end of file diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index 8ddf5b5e3..8cf237aad 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -35,12 +35,7 @@ public interface IProfileService Task UpdateMobilePhoneNumberAsync(string username, string newMobilePhoneNumber); Task UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom); Task UpdateOfficeHoursAsync(string username, string newHours); - CombinedProfileViewModel ImposePrivacySettings - (IEnumerable viewerGroups, ProfileViewModel profile); - PublicFacultyStaffProfileViewModel ToPublicFacultyStaffProfileViewModel - (string username, string currentUserType, FacultyStaffProfileViewModel fac); - PublicStudentProfileViewModel ToPublicStudentProfileViewModel - (string username, string currentUserType, StudentProfileViewModel stu); + CombinedProfileViewModel ImposePrivacySettings(IEnumerable viewerGroups, ProfileViewModel profile); Task UpdateUserPrivacyAsync(string username, UserPrivacyUpdateViewModel facultyStaffPrivacy); Task UpdateMailStopAsync(string username, string newMail); Task UpdateMobilePrivacyAsync(string username, string value);