Skip to content

Commit

Permalink
Continued working on ImposePrivacySettings()
Browse files Browse the repository at this point in the history
  • Loading branch information
jsenning committed Jun 26, 2024
1 parent 1976b02 commit 34f5edd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Gordon360/Controllers/ProfilesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class ProfilesController(IProfileService profileService,

var profile = profileService.ComposeProfile(student, alumni, faculty, _customInfo);

var cleaned_profile = profileService.ImposePrivacySettings(username, "fac", profile);
var cleaned_profile = profileService.ImposePrivacySettings(username, viewerGroups, profile);

return Ok(cleaned_profile);
}
Expand Down
2 changes: 1 addition & 1 deletion Gordon360/Documentation/Gordon360.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 31 additions & 15 deletions Gordon360/Services/ProfileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Net.Mail;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Gordon360.Enums;

namespace Gordon360.Services;

Expand Down Expand Up @@ -281,31 +282,46 @@ public async Task UpdateCustomProfileAsync(string username, string type, CUSTOM_
/// convert combined profile to public profile based on individual privacy settings
/// </summary>
/// <param name="username">username of the person being searched</param>
/// <param name="currentUserType">personnel type of the logged-in user (fac, stu, alu)</param>
/// <param name="viewerGroups">list of AuthGroups the logged-in user belongs to</param>
/// <param name="profile">combined profile of the person being searched</param>
/// <returns>public profile of the person based on individual privacy settings</returns>
public CombinedProfileViewModel ImposePrivacySettings
(string username, string currentUserType, ProfileViewModel profile)
(string username, IEnumerable<AuthGroup> viewerGroups, ProfileViewModel profile)
{
CombinedProfileViewModel public_profile = (CombinedProfileViewModel) profile;

// SiteAdmin and Police see full profile
if (viewerGroups.Contains(AuthGroup.SiteAdmin) || viewerGroups.Contains(AuthGroup.Police))
{
return public_profile;
}

// select all privacy settings
// var account = accountService.GetAccountByUsername(public_profile.AD_Username);
var account = accountService.GetAccountByUsername(username);
var privacy = context.UserPrivacy_Settings.Where(up_s => up_s.gordon_id == account.GordonID);

Type cpvm = new CombinedProfileViewModel().GetType();

// foreach (UserPrivacy_Settings row in privacy)
// {
// if (row.Visibility == "Private" || (row.Visibility == "FacStaff" && currentUserType != "fac"))
// {
// cpvm.GetProperty(row.Field).SetValue(publicFac, "Private as requested.");
// }
// }

// BOGUS ENTRY
// This is just an example of how we can change things. "MobilePhone"
cpvm.GetProperty("MobilePhone").SetValue(public_profile, "8885551212");
public_profile.HomePhone = "5551212";
if (viewerGroups.Contains(AuthGroup.FacStaff) && public_profile.PersonType.Contains("fac"))
{
foreach (UserPrivacy_Settings row in privacy)
{
if (row.Visibility == "Private")
{
cpvm.GetProperty(row.Field).SetValue(public_profile, null);
}
}
}
else if (viewerGroups.Contains(AuthGroup.Student) || viewerGroups.Contains(AuthGroup.Alumni))
{
foreach (UserPrivacy_Settings row in privacy)
{
if (row.Visibility == "Private" || row.Visibility == "FacStaff")
{
cpvm.GetProperty(row.Field).SetValue(public_profile, null);
}
}
}

return public_profile;
}
Expand Down
2 changes: 1 addition & 1 deletion Gordon360/Services/ServiceInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface IProfileService
Task<FacultyStaffProfileViewModel> UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom);
Task<FacultyStaffProfileViewModel> UpdateOfficeHoursAsync(string username, string newHours);
CombinedProfileViewModel ImposePrivacySettings
(string username, string currentUserType, ProfileViewModel profile);
(string username, IEnumerable<AuthGroup> viewerGroups, ProfileViewModel profile);
PublicFacultyStaffProfileViewModel ToPublicFacultyStaffProfileViewModel
(string username, string currentUserType, FacultyStaffProfileViewModel fac);
PublicStudentProfileViewModel ToPublicStudentProfileViewModel
Expand Down

0 comments on commit 34f5edd

Please sign in to comment.