Skip to content

Commit

Permalink
Lay grond work for imposing privacy constraints after composing profile
Browse files Browse the repository at this point in the history
  • Loading branch information
jsenning committed Jun 25, 2024
1 parent 0b7898f commit 1976b02
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 9 deletions.
16 changes: 7 additions & 9 deletions Gordon360/Controllers/ProfilesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,13 @@ public class ProfilesController(IProfileService profileService,
else if (viewerGroups.Contains(AuthGroup.FacStaff))
{
student = _student;
faculty = _faculty == null ? null :
profileService.ToPublicFacultyStaffProfileViewModel(username, "fac", _faculty);
faculty = _faculty == null ? null : (PublicFacultyStaffProfileViewModel)_faculty;
alumni = _alumni == null ? null : (PublicAlumniProfileViewModel)_alumni;
}
else if (viewerGroups.Contains(AuthGroup.Student))
{
student = _student == null ? null :
profileService.ToPublicStudentProfileViewModel(username, "stu", _student);
faculty = _faculty == null ? null :
profileService.ToPublicFacultyStaffProfileViewModel(username, "stu", _faculty);
student = _student == null ? null : (PublicStudentProfileViewModel)_student;
faculty = _faculty == null ? null : (PublicFacultyStaffProfileViewModel)_faculty;
// If this student is also in Alumni AuthGroup, then s/he can see alumni's public profile; if not, return null.
alumni = (_alumni == null) ? null :
viewerGroups.Contains(AuthGroup.Alumni) ?
Expand All @@ -96,8 +93,7 @@ public class ProfilesController(IProfileService profileService,
else if (viewerGroups.Contains(AuthGroup.Alumni))
{
student = null;
faculty = _faculty == null ? null :
profileService.ToPublicFacultyStaffProfileViewModel(username, "alu", _faculty);
faculty = _faculty == null ? null : (PublicFacultyStaffProfileViewModel)_faculty;
alumni = _alumni == null ? null : (PublicAlumniProfileViewModel)_alumni;
}

Expand All @@ -108,7 +104,9 @@ public class ProfilesController(IProfileService profileService,

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

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

return Ok(cleaned_profile);
}

///<summary>Get the advisor(s) of a particular student</summary>
Expand Down
9 changes: 9 additions & 0 deletions Gordon360/Documentation/Gordon360.xml

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

216 changes: 216 additions & 0 deletions Gordon360/Models/ViewModels/CombinedProfileViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
using System;

namespace Gordon360.Models.ViewModels;

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 string Email { get; set; }
public string Gender { get; set; }
public string HomeStreet1 { get; set; }
public string HomeStreet2 { get; set; }
public string HomeCity { get; set; }
public string HomeState { get; set; }
public string HomePostalCode { get; set; }
public string HomeCountry { get; set; }
public string HomePhone { get; set; }
public string HomeFax { get; set; }
public string AD_Username { get; set; }
public Nullable<int> show_pic { get; set; }
public Nullable<int> preferred_photo { get; set; }
public string Country { get; set; }
public string Barcode { get; set; }
public string Facebook { get; set; }
public string Twitter { get; set; }
public string Instagram { get; set; }
public string LinkedIn { get; set; }
public string Handshake { get; set; }
public string Calendar { get; set; }

// Student Only
public string OnOffCampus { get; set; }
public string OffCampusStreet1 { get; set; }
public string OffCampusStreet2 { get; set; }
public string OffCampusCity { get; set; }
public string OffCampusState { get; set; }
public string OffCampusPostalCode { get; set; }
public string OffCampusCountry { get; set; }
public string OffCampusPhone { get; set; }
public string OffCampusFax { get; set; }
public string Major3 { get; set; }
public string Major3Description { get; set; }
public string Minor1 { get; set; }
public string Minor1Description { get; set; }
public string Minor2 { get; set; }
public string Minor2Description { get; set; }
public string Minor3 { get; set; }
public string Minor3Description { get; set; }
public string GradDate { get; set; }
public string PlannedGradYear { get; set; }
public string MobilePhone { get; set; }
public bool IsMobilePhonePrivate { get; set; }
public Nullable<int> ChapelRequired { get; set; }
public Nullable<int> ChapelAttended { get; set; }
public string Cohort { get; set; }
public string Class { get; set; }
public string AdvisorIDs { get; set; }
public string Married { get; set; }
public string Commuter { get; set; }

// Alumni Only
public string WebUpdate { get; set; }
public string HomeEmail { get; set; }
public string MaritalStatus { get; set; }
public string College { get; set; }
public string ClassYear { get; set; }
public string PreferredClassYear { get; set; }
public string ShareName { get; set; }
public string ShareAddress { get; set; }

// Student And Alumni Only
public string Major { get; set; }
public string Major1Description { get; set; }
public string Major2 { get; set; }
public string Major2Description { get; set; }
public string grad_student { get; set; }

// FacStaff Only
public string OnCampusDepartment { get; set; }
public string Type { get; set; }
public string office_hours { get; set; }
public string Dept { get; set; }
public string Mail_Description { get; set; }

// FacStaff and Alumni Only
public string JobTitle { get; set; }
public string SpouseName { get; set; }

// FacStaff and Student Only
public string BuildingDescription { get; set; }
public string Mail_Location { get; set; }
public string OnCampusBuilding { get; set; }
public string OnCampusRoom { get; set; }
public string OnCampusPhone { get; set; }
public string OnCampusPrivatePhone { get; set; }
public string OnCampusFax { get; set; }
public string KeepPrivate { get; set; }

// ProfileViewModel Only
public string PersonType { get; set; }

public static implicit operator CombinedProfileViewModel(ProfileViewModel vm)
{
CombinedProfileViewModel new_vm = new CombinedProfileViewModel
{
// All Profiles
ID = vm.ID ?? null,
Title = vm.Title ?? null,
FirstName = vm.FirstName ?? null,
MiddleName = vm.MiddleName ?? null,
LastName = vm.LastName ?? null,
Suffix = vm.Suffix ?? null,
MaidenName = vm.MaidenName ?? null,
NickName = vm.NickName ?? null,
Email = vm.Email ?? null,
Gender = vm.Gender ?? null,
HomeStreet1 = vm.HomeStreet1 ?? null,
HomeStreet2 = vm.HomeStreet2 ?? null,
HomeCity = vm.HomeCity ?? null,
HomeState = vm.HomeState ?? null,
HomePostalCode = vm.HomePostalCode ?? null,
HomeCountry = vm.HomeCountry ?? null,
HomePhone = vm.HomePhone ?? null,
HomeFax = vm.HomeFax ?? null,
AD_Username = vm.AD_Username ?? null,
show_pic = vm.show_pic,
preferred_photo = vm.preferred_photo,
Country = vm.Country ?? null,
Barcode = vm.Barcode ?? null,
Facebook = vm.Facebook ?? null,
Twitter = vm.Twitter ?? null,
Instagram = vm.Instagram ?? null,
LinkedIn = vm.LinkedIn ?? null,
Handshake = vm.Handshake ?? null,
Calendar = vm.Calendar ?? null,

// Student Only
OnOffCampus = vm.OnOffCampus ?? null,
OffCampusStreet1 = vm.OffCampusStreet1 ?? null,
OffCampusStreet2 = vm.OffCampusStreet2 ?? null,
OffCampusCity = vm.OffCampusCity ?? null,
OffCampusState = vm.OffCampusState ?? null,
OffCampusPostalCode = vm.OffCampusPostalCode ?? null,
OffCampusCountry = vm.OffCampusCountry ?? null,
OffCampusPhone = vm.OffCampusPhone ?? null,
OffCampusFax = vm.OffCampusFax ?? null,
Major3 = vm.Major3 ?? null,
Major3Description = vm.Major3Description ?? null,
Minor1 = vm.Minor1 ?? null,
Minor1Description = vm.Minor1Description ?? null,
Minor2 = vm.Minor2 ?? null,
Minor2Description = vm.Minor2Description ?? null,
Minor3 = vm.Minor3 ?? null,
Minor3Description = vm.Minor3Description ?? null,
GradDate = vm.GradDate ?? null,
PlannedGradYear = vm.PlannedGradYear ?? null,
MobilePhone = vm.MobilePhone ?? null,
IsMobilePhonePrivate = vm.IsMobilePhonePrivate,
ChapelRequired = vm.ChapelRequired,
ChapelAttended = vm.ChapelAttended,
Cohort = vm.Cohort ?? null,
Class = vm.Class ?? null,
AdvisorIDs = vm.AdvisorIDs ?? null,
Married = vm.Married ?? null,
Commuter = vm.Commuter ?? null,

// Alumni Only
WebUpdate = vm. WebUpdate ?? null,
HomeEmail = vm.HomeEmail ?? null,
MaritalStatus = vm.MaritalStatus ?? null,
College = vm.College ?? null,
ClassYear = vm.ClassYear ?? null,
PreferredClassYear = vm. PreferredClassYear ?? null,
ShareName = vm.ShareName ?? null,
ShareAddress = vm. ShareAddress ?? null,

// Student And Alumni Only
Major = vm.Major ?? null,
Major1Description = vm.Major1Description ?? null,
Major2 = vm.Major2 ?? null,
Major2Description = vm.Major2Description ?? null,
grad_student = vm.grad_student ?? null,

// FacStaff Only
OnCampusDepartment = vm. OnCampusDepartment ?? null,
Type = vm. Type ?? null,
office_hours = vm. office_hours ?? null,
Dept = vm.Dept ?? null,
Mail_Description = vm.Mail_Description ?? null,

// FacStaff and Alumni Only
JobTitle = vm.JobTitle ?? null,
SpouseName = vm.SpouseName ?? null,

// FacStaff and Student Only
BuildingDescription = vm.BuildingDescription ?? null,
Mail_Location = vm.Mail_Location ?? null,
OnCampusBuilding = vm.OnCampusBuilding ?? null,
OnCampusRoom = vm.OnCampusRoom ?? null,
OnCampusPhone = vm.OnCampusPhone ?? null,
OnCampusPrivatePhone = vm.OnCampusPrivatePhone ?? null,
OnCampusFax = vm.OnCampusFax ?? null,
KeepPrivate = vm.KeepPrivate ?? null,

// ProfileViewModel Only
PersonType = vm.PersonType ?? null
};
return new_vm;
}
}
33 changes: 33 additions & 0 deletions Gordon360/Services/ProfileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,39 @@ public async Task UpdateCustomProfileAsync(string username, string type, CUSTOM_
}


/// <summary>
/// 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="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)
{
CombinedProfileViewModel public_profile = (CombinedProfileViewModel) profile;
// select all privacy settings
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";

return public_profile;
}

/// <summary>
/// convert original fac/staff profile to public fac/staff profile based on individual privacy settings
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Gordon360/Services/ServiceInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public interface IProfileService
Task<StudentProfileViewModel> UpdateMobilePhoneNumberAsync(string username, string newMobilePhoneNumber);
Task<FacultyStaffProfileViewModel> UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom);
Task<FacultyStaffProfileViewModel> UpdateOfficeHoursAsync(string username, string newHours);
CombinedProfileViewModel ImposePrivacySettings
(string username, string currentUserType, ProfileViewModel profile);
PublicFacultyStaffProfileViewModel ToPublicFacultyStaffProfileViewModel
(string username, string currentUserType, FacultyStaffProfileViewModel fac);
PublicStudentProfileViewModel ToPublicStudentProfileViewModel
Expand Down

0 comments on commit 1976b02

Please sign in to comment.