From b407dadc91f6046e2ec5337fd6d84b568b0eeff5 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Tue, 27 Jun 2023 12:07:43 -0400 Subject: [PATCH 01/44] Update EF Core models --- Gordon360/Models/CCT/Context/CCTContext.cs | 29 +++++++++++++++++-- .../Models/CCT/Context/efpt.CCT.config.json | 14 ++++++++- Gordon360/Models/CCT/dbo/FacStaff.cs | 6 ++-- .../Models/CCT/dbo/FacStaff_Field_Type.cs | 20 +++++++++++++ Gordon360/Models/CCT/dbo/FacStaff_Privacy.cs | 27 +++++++++++++++++ .../Models/CCT/dbo/FacStaff_Viewer_Type.cs | 20 +++++++++++++ 6 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 Gordon360/Models/CCT/dbo/FacStaff_Field_Type.cs create mode 100644 Gordon360/Models/CCT/dbo/FacStaff_Privacy.cs create mode 100644 Gordon360/Models/CCT/dbo/FacStaff_Viewer_Type.cs diff --git a/Gordon360/Models/CCT/Context/CCTContext.cs b/Gordon360/Models/CCT/Context/CCTContext.cs index 83d831692..d79b3b9b5 100644 --- a/Gordon360/Models/CCT/Context/CCTContext.cs +++ b/Gordon360/Models/CCT/Context/CCTContext.cs @@ -44,6 +44,9 @@ public CCTContext(DbContextOptions options) public virtual DbSet ERROR_LOG { get; set; } public virtual DbSet EmergencyContact { get; set; } public virtual DbSet FacStaff { get; set; } + public virtual DbSet FacStaff_Field_Type { get; set; } + public virtual DbSet FacStaff_Privacy { get; set; } + public virtual DbSet FacStaff_Viewer_Type { get; set; } public virtual DbSet Graduation { get; set; } public virtual DbSet Health_Question { get; set; } public virtual DbSet Health_Status { get; set; } @@ -295,6 +298,23 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(e => e.BuildingDescription).IsFixedLength(); }); + modelBuilder.Entity(entity => + { + entity.Property(e => e.ID).ValueGeneratedOnAdd(); + }); + + modelBuilder.Entity(entity => + { + entity.Property(e => e.Field).HasDefaultValueSql("((0))"); + + entity.Property(e => e.Viewer).HasDefaultValueSql("((0))"); + }); + + modelBuilder.Entity(entity => + { + entity.Property(e => e.ID).ValueGeneratedOnAdd(); + }); + modelBuilder.Entity(entity => { entity.ToView("Graduation", "dbo"); @@ -509,10 +529,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { - entity.HasKey(e => e.Username) - .HasName("PK__Particip__536C85E53B50E910"); + entity.Property(e => e.AllowEmails).HasDefaultValueSql("((1))"); entity.Property(e => e.ID).ValueGeneratedOnAdd(); + + entity.Property(e => e.SpecifiedGender).IsFixedLength(); }); modelBuilder.Entity(entity => @@ -525,6 +546,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.HasOne(d => d.ParticipantUsernameNavigation) .WithMany(p => p.ParticipantActivity) .HasForeignKey(d => d.ParticipantUsername) + .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("FK_ParticipantActivity_Participant"); entity.HasOne(d => d.PrivType) @@ -540,7 +562,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(p => p.ParticipantNotification) .HasForeignKey(d => d.ParticipantUsername) .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("FK_PartipantNotification_Participant"); + .HasConstraintName("FK_ParticipantNotification_Participant"); }); modelBuilder.Entity(entity => @@ -563,6 +585,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.HasOne(d => d.ParticipantUsernameNavigation) .WithMany(p => p.ParticipantTeam) .HasForeignKey(d => d.ParticipantUsername) + .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("FK_ParticipantTeam_Participant"); entity.HasOne(d => d.RoleType) diff --git a/Gordon360/Models/CCT/Context/efpt.CCT.config.json b/Gordon360/Models/CCT/Context/efpt.CCT.config.json index 78dc7de30..c69e50acc 100644 --- a/Gordon360/Models/CCT/Context/efpt.CCT.config.json +++ b/Gordon360/Models/CCT/Context/efpt.CCT.config.json @@ -38,6 +38,18 @@ "Name": "[dbo].[ERROR_LOG]", "ObjectType": 0 }, + { + "Name": "[dbo].[FacStaff_Field_Type]", + "ObjectType": 0 + }, + { + "Name": "[dbo].[FacStaff_Privacy]", + "ObjectType": 0 + }, + { + "Name": "[dbo].[FacStaff_Viewer_Type]", + "ObjectType": 0 + }, { "Name": "[dbo].[Health_Question]", "ObjectType": 0 @@ -799,7 +811,7 @@ "ObjectType": 1 } ], - "UiHint": "SQLTrain1.CCT", + "UiHint": "sqltrain1.CCT.dbo", "UseBoolPropertiesWithoutDefaultSql": false, "UseDatabaseNames": true, "UseDbContextSplitting": false, diff --git a/Gordon360/Models/CCT/dbo/FacStaff.cs b/Gordon360/Models/CCT/dbo/FacStaff.cs index 562b3897e..582c37f24 100644 --- a/Gordon360/Models/CCT/dbo/FacStaff.cs +++ b/Gordon360/Models/CCT/dbo/FacStaff.cs @@ -11,8 +11,7 @@ namespace Gordon360.Models.CCT [Keyless] public partial class FacStaff { - [Required] - [StringLength(10)] + [StringLength(9)] [Unicode(false)] public string ID { get; set; } [StringLength(5)] @@ -75,6 +74,9 @@ public partial class FacStaff [StringLength(15)] [Unicode(false)] public string HomePhone { get; set; } + [StringLength(15)] + [Unicode(false)] + public string MobilePhone { get; set; } [StringLength(1)] [Unicode(false)] public string HomeFax { get; set; } diff --git a/Gordon360/Models/CCT/dbo/FacStaff_Field_Type.cs b/Gordon360/Models/CCT/dbo/FacStaff_Field_Type.cs new file mode 100644 index 000000000..b49a69ce4 --- /dev/null +++ b/Gordon360/Models/CCT/dbo/FacStaff_Field_Type.cs @@ -0,0 +1,20 @@ +// This file has been auto generated by EF Core Power Tools. +#nullable disable +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; + +namespace Gordon360.Models.CCT +{ + [Table("FacStaff_Field_Type", Schema = "dbo")] + public partial class FacStaff_Field_Type + { + public int ID { get; set; } + [Key] + [StringLength(50)] + [Unicode(false)] + public string Field { get; set; } + } +} \ No newline at end of file diff --git a/Gordon360/Models/CCT/dbo/FacStaff_Privacy.cs b/Gordon360/Models/CCT/dbo/FacStaff_Privacy.cs new file mode 100644 index 000000000..db1ef144c --- /dev/null +++ b/Gordon360/Models/CCT/dbo/FacStaff_Privacy.cs @@ -0,0 +1,27 @@ +// This file has been auto generated by EF Core Power Tools. +#nullable disable +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; + +namespace Gordon360.Models.CCT +{ + [Table("FacStaff_Privacy", Schema = "dbo")] + public partial class FacStaff_Privacy + { + [Key] + [StringLength(10)] + [Unicode(false)] + public string gordon_id { get; set; } + [Required] + [StringLength(50)] + [Unicode(false)] + public string Field { get; set; } + [Required] + [StringLength(50)] + [Unicode(false)] + public string Viewer { get; set; } + } +} \ No newline at end of file diff --git a/Gordon360/Models/CCT/dbo/FacStaff_Viewer_Type.cs b/Gordon360/Models/CCT/dbo/FacStaff_Viewer_Type.cs new file mode 100644 index 000000000..5c4c0d118 --- /dev/null +++ b/Gordon360/Models/CCT/dbo/FacStaff_Viewer_Type.cs @@ -0,0 +1,20 @@ +// This file has been auto generated by EF Core Power Tools. +#nullable disable +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; + +namespace Gordon360.Models.CCT +{ + [Table("FacStaff_Viewer_Type", Schema = "dbo")] + public partial class FacStaff_Viewer_Type + { + public int ID { get; set; } + [Key] + [StringLength(50)] + [Unicode(false)] + public string Viewer { get; set; } + } +} \ No newline at end of file From daaa94fd0ea0431684ff02033f1f2a0c6d179c24 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Tue, 27 Jun 2023 12:21:20 -0400 Subject: [PATCH 02/44] continue EF Core update --- Gordon360/Documentation/Gordon360.xml | 26 ++++++---------------- Gordon360/Models/CCT/Context/CCTContext.cs | 4 ---- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index e119f774f..be96f27d0 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -1184,7 +1184,7 @@ New description - + Gets all schedule objects for a user @@ -2387,6 +2387,7 @@ The username for the user whose office location is to be updated The new building location to update the user's office location to The new room to update the user's office room to + updated fac/staff profile if found @@ -2394,6 +2395,7 @@ The username for the user whose office hours is to be updated The new hours to update the user's office hours to + updated fac/staff profile if found @@ -2513,34 +2515,20 @@ Service Class that facilitates data transactions between the SchedulesController and the Schedule part of the database model. - + Fetch the schedule item whose id and session code is specified by the parameter The AD Username of the student + The selected session of the student StudentScheduleViewModel if found, null if not found - + Fetch the schedule item whose id and session code is specified by the parameter The AD Username of the instructor - StudentScheduleViewModel if found, null if not found - - - - Fetch the schedule item whose id and session code is specified by the parameter - - The AD Username of the instructor - The session of the instructor - StudentScheduleViewModel if found, null if not found - - - - Fetch the schedule item whose id and session code is specified by the parameter - - The AD Username of the Student - The session of the student + The selected session of the instructor StudentScheduleViewModel if found, null if not found diff --git a/Gordon360/Models/CCT/Context/CCTContext.cs b/Gordon360/Models/CCT/Context/CCTContext.cs index d79b3b9b5..912e1d864 100644 --- a/Gordon360/Models/CCT/Context/CCTContext.cs +++ b/Gordon360/Models/CCT/Context/CCTContext.cs @@ -529,11 +529,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { - entity.Property(e => e.AllowEmails).HasDefaultValueSql("((1))"); - entity.Property(e => e.ID).ValueGeneratedOnAdd(); - - entity.Property(e => e.SpecifiedGender).IsFixedLength(); }); modelBuilder.Entity(entity => From 8d0f4ecc4c91edc8711deffc5598adef5bb14cb9 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Tue, 27 Jun 2023 16:17:51 -0400 Subject: [PATCH 03/44] add mobilePhone, isMobilePhonePrivate, and isHomePhonePrivate --- Gordon360/Models/CCT/dbo/FacStaff.cs | 6 ++++++ .../ViewModels/FacultyStaffProfileViewModel.cs | 6 ++++++ .../PublicFacultyStaffProfileViewModel.cs | 14 ++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/Gordon360/Models/CCT/dbo/FacStaff.cs b/Gordon360/Models/CCT/dbo/FacStaff.cs index 582c37f24..820b0f382 100644 --- a/Gordon360/Models/CCT/dbo/FacStaff.cs +++ b/Gordon360/Models/CCT/dbo/FacStaff.cs @@ -76,9 +76,15 @@ public partial class FacStaff public string HomePhone { get; set; } [StringLength(15)] [Unicode(false)] + public int IsHomePhonePrivate { get; set; } + [StringLength(50)] + [Unicode(false)] public string MobilePhone { get; set; } [StringLength(1)] [Unicode(false)] + public int IsMobilePhonePrivate { get; set; } + [StringLength(50)] + [Unicode(false)] public string HomeFax { get; set; } [Required] [StringLength(1)] diff --git a/Gordon360/Models/ViewModels/FacultyStaffProfileViewModel.cs b/Gordon360/Models/ViewModels/FacultyStaffProfileViewModel.cs index d4c67696e..334efac4c 100644 --- a/Gordon360/Models/ViewModels/FacultyStaffProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/FacultyStaffProfileViewModel.cs @@ -25,6 +25,9 @@ public record FacultyStaffProfileViewModel string HomePostalCode, string HomeCountry, string HomePhone, + bool IsHomePhonePrivate, + string MobilePhone, + bool IsMobilePhonePrivate, string HomeFax, string KeepPrivate, string JobTitle, @@ -72,6 +75,9 @@ public record FacultyStaffProfileViewModel fac.HomePostalCode ?? "", fac.HomeCountry ?? "", fac.HomePhone ?? "", + fac.IsHomePhonePrivate == 1 ? true : false, + fac.MobilePhone ?? "", + fac.IsMobilePhonePrivate == 1 ? true : false, fac.HomeFax ?? "", fac.KeepPrivate ?? "", fac.JobTitle ?? "", diff --git a/Gordon360/Models/ViewModels/PublicFacultyStaffProfileViewModel.cs b/Gordon360/Models/ViewModels/PublicFacultyStaffProfileViewModel.cs index aa49c5b55..ca3868df1 100644 --- a/Gordon360/Models/ViewModels/PublicFacultyStaffProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/PublicFacultyStaffProfileViewModel.cs @@ -18,9 +18,12 @@ public class PublicFacultyStaffProfileViewModel public string OnCampusPrivatePhone { get; set; } public string OnCampusFax { get; set; } public string HomePhone { get; set; } + public bool IsHomePhonePrivate { get; set; } public string HomeCity { get; set; } public string HomeState { get; set; } public string HomeCountry { get; set; } + public string MobilePhone { get; set; } + public bool IsMobilePhonePrivate { get; set; } public string KeepPrivate { get; set; } public string JobTitle { get; set; } public string SpouseName { get; set; } @@ -59,6 +62,9 @@ public static implicit operator PublicFacultyStaffProfileViewModel(FacultyStaffP OnCampusPrivatePhone = fac.OnCampusPrivatePhone ?? "", OnCampusFax = fac.OnCampusFax ?? "", HomePhone = fac.HomePhone ?? "", + IsHomePhonePrivate = fac.IsHomePhonePrivate, + MobilePhone = fac.MobilePhone ?? "", + IsMobilePhonePrivate = fac.IsMobilePhonePrivate, HomeCity = fac.HomeCity ?? "", HomeState = fac.HomeState ?? "", HomeCountry = fac.HomeCountry ?? "", @@ -77,6 +83,14 @@ public static implicit operator PublicFacultyStaffProfileViewModel(FacultyStaffP Mail_Location = fac.Mail_Location ?? "", Mail_Description = fac.Mail_Description ?? "" }; + if (vm.IsHomePhonePrivate) + { + vm.HomePhone = "Private as requested."; + } + if (vm.IsMobilePhonePrivate) + { + vm.MobilePhone = "Private as requested."; + } if (vm.KeepPrivate.Contains('1')) { vm.HomeCity = "Private as requested."; From 3adcc9a3ca1b82b827b43ed30f5c023c29cd5e61 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Tue, 27 Jun 2023 17:13:45 -0400 Subject: [PATCH 04/44] add UpdateHomePrivacyAsync - not working yet --- Gordon360/Models/CCT/dbo/FacStaff.cs | 3 ++- Gordon360/Services/ProfileService.cs | 25 +++++++++++++++++++++++++ Gordon360/Services/ServiceInterfaces.cs | 3 ++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Gordon360/Models/CCT/dbo/FacStaff.cs b/Gordon360/Models/CCT/dbo/FacStaff.cs index 820b0f382..1e4920034 100644 --- a/Gordon360/Models/CCT/dbo/FacStaff.cs +++ b/Gordon360/Models/CCT/dbo/FacStaff.cs @@ -11,7 +11,8 @@ namespace Gordon360.Models.CCT [Keyless] public partial class FacStaff { - [StringLength(9)] + [Required] + [StringLength(10)] [Unicode(false)] public string ID { get; set; } [StringLength(5)] diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index f3ee80d60..1be0a7241 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -8,6 +8,7 @@ using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Net; using System.Net.Mail; @@ -282,6 +283,25 @@ public async Task UpdateProfileLinkAsync(string username, string type, CUSTOM_PR await _context.SaveChangesAsync(); } + /// + /// privacy setting of home phone. + /// + /// AD Username + /// Y or N + public async Task UpdateHomePrivacyAsync(string username, string value) + { + var account = _accountService.GetAccountByUsername(username); + await _context.Procedures.UPDATE_PHONE_PRIVACYAsync(int.Parse(account.GordonID), value); + // Update value in cached data + var facStaff = _context.FacStaff.FirstOrDefault(x => x.ID == account.GordonID); + if (facStaff != null) + { + facStaff.IsHomePhonePrivate = (value == "Y" ? 1 : 0); + } + + _context.SaveChanges(); + } + /// /// privacy setting of mobile phone. /// @@ -293,10 +313,15 @@ public async Task UpdateMobilePrivacyAsync(string username, string value) await _context.Procedures.UPDATE_PHONE_PRIVACYAsync(int.Parse(account.GordonID), value); // Update value in cached data var student = _context.Student.FirstOrDefault(x => x.ID == account.GordonID); + var facStaff = _context.FacStaff.FirstOrDefault(x => x.ID == account.GordonID); if (student != null) { student.IsMobilePhonePrivate = (value == "Y" ? 1 : 0); } + else if (facStaff != null) + { + facStaff.IsMobilePhonePrivate = (value == "Y" ? 1 : 0); + } _context.SaveChanges(); } diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index f5441ba3d..a9b1637ad 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -34,9 +34,10 @@ public interface IProfileService ProfileCustomViewModel? GetCustomUserInfo(string username); Task GetPhotoPathAsync(string username); Task UpdateProfileLinkAsync(string username, string type, CUSTOM_PROFILE path); - Task UpdateMobilePhoneNumberAsync(string username, string newMobilePhoneNumber); + Task UpdateMobilePhoneNumberAsync(string username, string newMobilePhoneNumber); Task UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom); Task UpdateOfficeHoursAsync(string username, string newHours); + Task UpdateHomePrivacyAsync(string username, string value); Task UpdateMobilePrivacyAsync(string username, string value); Task UpdateImagePrivacyAsync(string username, string value); Task UpdateProfileImageAsync(string username, string path, string name); From 4eb6757b0ea47e524922a5f23145d19d7f08171b Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Wed, 28 Jun 2023 10:04:26 -0400 Subject: [PATCH 05/44] fix the error --- Gordon360/Services/ProfileService.cs | 4 ---- Gordon360/Services/ServiceInterfaces.cs | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 1be0a7241..2b0c057b1 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -318,10 +318,6 @@ public async Task UpdateMobilePrivacyAsync(string username, string value) { student.IsMobilePhonePrivate = (value == "Y" ? 1 : 0); } - else if (facStaff != null) - { - facStaff.IsMobilePhonePrivate = (value == "Y" ? 1 : 0); - } _context.SaveChanges(); } diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index a9b1637ad..5a6c256f7 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -34,7 +34,7 @@ public interface IProfileService ProfileCustomViewModel? GetCustomUserInfo(string username); Task GetPhotoPathAsync(string username); Task UpdateProfileLinkAsync(string username, string type, CUSTOM_PROFILE path); - Task UpdateMobilePhoneNumberAsync(string username, string newMobilePhoneNumber); + Task UpdateMobilePhoneNumberAsync(string username, string newMobilePhoneNumber); Task UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom); Task UpdateOfficeHoursAsync(string username, string newHours); Task UpdateHomePrivacyAsync(string username, string value); From d870395982c8390141106b9d517cb5131fd618f1 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Wed, 28 Jun 2023 11:50:19 -0400 Subject: [PATCH 06/44] remove isMobilePhonePrivate and isHomePhonePrivate for fac/staff --- Gordon360/Controllers/ProfilesController.cs | 15 ++++++++++++++ Gordon360/Documentation/Gordon360.xml | 14 +++++++++++++ Gordon360/Models/CCT/dbo/FacStaff.cs | 6 ------ .../FacultyStaffProfileViewModel.cs | 4 ---- .../PublicFacultyStaffProfileViewModel.cs | 12 ----------- Gordon360/Services/ProfileService.cs | 20 ------------------- 6 files changed, 29 insertions(+), 42 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index ea796758e..79e22502f 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -473,6 +473,21 @@ public async Task> UpdateOfficeHours( return Ok(result); } + /// + /// Update privacy of home phone number + /// + /// Y or N + /// + [HttpPut] + [Route("home_privacy/{value}")] + public async Task UpdateHomePrivacyAsync(string value) + { + var authenticatedUserUsername = AuthUtils.GetUsername(User); + await _profileService.UpdateHomePrivacyAsync(authenticatedUserUsername, value); + + return Ok(); + } + /// /// Update privacy of mobile phone number /// diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index be96f27d0..ec5260d9b 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -672,6 +672,13 @@ office hours + + + Update privacy of home phone number + + Y or N + + Update privacy of mobile phone number @@ -2366,6 +2373,13 @@ + + + privacy setting of home phone. + + AD Username + Y or N + privacy setting of mobile phone. diff --git a/Gordon360/Models/CCT/dbo/FacStaff.cs b/Gordon360/Models/CCT/dbo/FacStaff.cs index 1e4920034..3f12a991d 100644 --- a/Gordon360/Models/CCT/dbo/FacStaff.cs +++ b/Gordon360/Models/CCT/dbo/FacStaff.cs @@ -77,15 +77,9 @@ public partial class FacStaff public string HomePhone { get; set; } [StringLength(15)] [Unicode(false)] - public int IsHomePhonePrivate { get; set; } - [StringLength(50)] - [Unicode(false)] public string MobilePhone { get; set; } [StringLength(1)] [Unicode(false)] - public int IsMobilePhonePrivate { get; set; } - [StringLength(50)] - [Unicode(false)] public string HomeFax { get; set; } [Required] [StringLength(1)] diff --git a/Gordon360/Models/ViewModels/FacultyStaffProfileViewModel.cs b/Gordon360/Models/ViewModels/FacultyStaffProfileViewModel.cs index 334efac4c..273cfed65 100644 --- a/Gordon360/Models/ViewModels/FacultyStaffProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/FacultyStaffProfileViewModel.cs @@ -25,9 +25,7 @@ public record FacultyStaffProfileViewModel string HomePostalCode, string HomeCountry, string HomePhone, - bool IsHomePhonePrivate, string MobilePhone, - bool IsMobilePhonePrivate, string HomeFax, string KeepPrivate, string JobTitle, @@ -75,9 +73,7 @@ public record FacultyStaffProfileViewModel fac.HomePostalCode ?? "", fac.HomeCountry ?? "", fac.HomePhone ?? "", - fac.IsHomePhonePrivate == 1 ? true : false, fac.MobilePhone ?? "", - fac.IsMobilePhonePrivate == 1 ? true : false, fac.HomeFax ?? "", fac.KeepPrivate ?? "", fac.JobTitle ?? "", diff --git a/Gordon360/Models/ViewModels/PublicFacultyStaffProfileViewModel.cs b/Gordon360/Models/ViewModels/PublicFacultyStaffProfileViewModel.cs index ca3868df1..3e382a330 100644 --- a/Gordon360/Models/ViewModels/PublicFacultyStaffProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/PublicFacultyStaffProfileViewModel.cs @@ -18,12 +18,10 @@ public class PublicFacultyStaffProfileViewModel public string OnCampusPrivatePhone { get; set; } public string OnCampusFax { get; set; } public string HomePhone { get; set; } - public bool IsHomePhonePrivate { get; set; } public string HomeCity { get; set; } public string HomeState { get; set; } public string HomeCountry { get; set; } public string MobilePhone { get; set; } - public bool IsMobilePhonePrivate { get; set; } public string KeepPrivate { get; set; } public string JobTitle { get; set; } public string SpouseName { get; set; } @@ -62,9 +60,7 @@ public static implicit operator PublicFacultyStaffProfileViewModel(FacultyStaffP OnCampusPrivatePhone = fac.OnCampusPrivatePhone ?? "", OnCampusFax = fac.OnCampusFax ?? "", HomePhone = fac.HomePhone ?? "", - IsHomePhonePrivate = fac.IsHomePhonePrivate, MobilePhone = fac.MobilePhone ?? "", - IsMobilePhonePrivate = fac.IsMobilePhonePrivate, HomeCity = fac.HomeCity ?? "", HomeState = fac.HomeState ?? "", HomeCountry = fac.HomeCountry ?? "", @@ -83,14 +79,6 @@ public static implicit operator PublicFacultyStaffProfileViewModel(FacultyStaffP Mail_Location = fac.Mail_Location ?? "", Mail_Description = fac.Mail_Description ?? "" }; - if (vm.IsHomePhonePrivate) - { - vm.HomePhone = "Private as requested."; - } - if (vm.IsMobilePhonePrivate) - { - vm.MobilePhone = "Private as requested."; - } if (vm.KeepPrivate.Contains('1')) { vm.HomeCity = "Private as requested."; diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 2b0c057b1..f72fba8da 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -283,25 +283,6 @@ public async Task UpdateProfileLinkAsync(string username, string type, CUSTOM_PR await _context.SaveChangesAsync(); } - /// - /// privacy setting of home phone. - /// - /// AD Username - /// Y or N - public async Task UpdateHomePrivacyAsync(string username, string value) - { - var account = _accountService.GetAccountByUsername(username); - await _context.Procedures.UPDATE_PHONE_PRIVACYAsync(int.Parse(account.GordonID), value); - // Update value in cached data - var facStaff = _context.FacStaff.FirstOrDefault(x => x.ID == account.GordonID); - if (facStaff != null) - { - facStaff.IsHomePhonePrivate = (value == "Y" ? 1 : 0); - } - - _context.SaveChanges(); - } - /// /// privacy setting of mobile phone. /// @@ -313,7 +294,6 @@ public async Task UpdateMobilePrivacyAsync(string username, string value) await _context.Procedures.UPDATE_PHONE_PRIVACYAsync(int.Parse(account.GordonID), value); // Update value in cached data var student = _context.Student.FirstOrDefault(x => x.ID == account.GordonID); - var facStaff = _context.FacStaff.FirstOrDefault(x => x.ID == account.GordonID); if (student != null) { student.IsMobilePhonePrivate = (value == "Y" ? 1 : 0); From ab489998f2159769af9c9e5f28403a35e938e264 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Wed, 28 Jun 2023 13:15:56 -0400 Subject: [PATCH 07/44] remove UpdateHomePrivacyAsync from ProfileController and ProfileService temporarily --- Gordon360/Controllers/ProfilesController.cs | 15 --------------- Gordon360/Documentation/Gordon360.xml | 14 -------------- Gordon360/Services/ServiceInterfaces.cs | 1 - 3 files changed, 30 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index 79e22502f..ea796758e 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -473,21 +473,6 @@ public async Task> UpdateOfficeHours( return Ok(result); } - /// - /// Update privacy of home phone number - /// - /// Y or N - /// - [HttpPut] - [Route("home_privacy/{value}")] - public async Task UpdateHomePrivacyAsync(string value) - { - var authenticatedUserUsername = AuthUtils.GetUsername(User); - await _profileService.UpdateHomePrivacyAsync(authenticatedUserUsername, value); - - return Ok(); - } - /// /// Update privacy of mobile phone number /// diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index ec5260d9b..be96f27d0 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -672,13 +672,6 @@ office hours - - - Update privacy of home phone number - - Y or N - - Update privacy of mobile phone number @@ -2373,13 +2366,6 @@ - - - privacy setting of home phone. - - AD Username - Y or N - privacy setting of mobile phone. diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index 5a6c256f7..f5441ba3d 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -37,7 +37,6 @@ public interface IProfileService Task UpdateMobilePhoneNumberAsync(string username, string newMobilePhoneNumber); Task UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom); Task UpdateOfficeHoursAsync(string username, string newHours); - Task UpdateHomePrivacyAsync(string username, string value); Task UpdateMobilePrivacyAsync(string username, string value); Task UpdateImagePrivacyAsync(string username, string value); Task UpdateProfileImageAsync(string username, string path, string name); From ca323c125bc6f5030178d3d6ffdf54799fbc4d92 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Wed, 28 Jun 2023 17:28:55 -0400 Subject: [PATCH 08/44] modifying UpdateFacStaffPrivacyAsync - not working --- Gordon360/Controllers/ProfilesController.cs | 19 ++++++++++++++++++ Gordon360/Documentation/Gordon360.xml | 14 +++++++++++++ Gordon360/Services/ProfileService.cs | 22 +++++++++++++++++++++ Gordon360/Services/ServiceInterfaces.cs | 1 + 4 files changed, 56 insertions(+) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index ea796758e..3ce2b1b3b 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -473,6 +473,25 @@ public async Task> UpdateOfficeHours( return Ok(result); } + /// + /// Update visibility of some piece of personal data for facstaff. + /// + /// Identifies the piece of information (home phone, etc.) + /// Specifies who to show this field to (public, private, facstaff) + /// + [HttpPut] + [Route("facstaff_privacy/field/{field}/permission/{permission}")] + public async Task UpdateFacStaffPrivacyAsync(string field, string permission) + { + // Since the database stores each permission in a separate row for the + // role that can access it, a single call will change multiple rows. + // For example, private will need to delete all rows for this person and field. + var authenticatedUserUsername = AuthUtils.GetUsername(User); + await _profileService.UpdateFacStaffPrivacyAsync(authenticatedUserUsername, field, permission); + + return Ok(); + } + /// /// Update privacy of mobile phone number /// diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index be96f27d0..ec5260d9b 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -672,6 +672,13 @@ office hours + + + Update privacy of home phone number + + Y or N + + Update privacy of mobile phone number @@ -2366,6 +2373,13 @@ + + + privacy setting of home phone. + + AD Username + Y or N + privacy setting of mobile phone. diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index f72fba8da..9a54ec619 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -4,6 +4,7 @@ using Gordon360.Models.ViewModels; using Gordon360.Models.webSQL.Context; using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.Extensions.Configuration; using Newtonsoft.Json.Linq; using System; @@ -283,6 +284,27 @@ public async Task UpdateProfileLinkAsync(string username, string type, CUSTOM_PR await _context.SaveChangesAsync(); } + /// + /// privacy setting of home phone. + /// + /// AD Username + /// Y or N + /// Y or N + public async Task UpdateFacStaffPrivacyAsync(string username, string field, string viewer) + { + var account = _accountService.GetAccountByUsername(username); + await _context.Procedures.UPDATE_PHONE_PRIVACYAsync(int.Parse(account.GordonID), value); + // Update value in cached data + var facStaff = _context.FacStaff_Privacy.FirstOrDefault(x => x.gordon_id == account.GordonID); + if (facStaff != null) + { + facStaff.Field = (field == "HomePhoneNumber" ? "HomePhoneNumber" : null); + facStaff.Viewer = (viewer == "Student" ? "Student" : null); + } + + _context.SaveChanges(); + } + /// /// privacy setting of mobile phone. /// diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index f5441ba3d..5a6c256f7 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -37,6 +37,7 @@ public interface IProfileService Task UpdateMobilePhoneNumberAsync(string username, string newMobilePhoneNumber); Task UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom); Task UpdateOfficeHoursAsync(string username, string newHours); + Task UpdateHomePrivacyAsync(string username, string value); Task UpdateMobilePrivacyAsync(string username, string value); Task UpdateImagePrivacyAsync(string username, string value); Task UpdateProfileImageAsync(string username, string path, string name); From 9b6189dcb8e5a432e6507decd9a666e9487357c0 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Thu, 29 Jun 2023 17:16:45 -0400 Subject: [PATCH 09/44] finishing update route --- Gordon360/Controllers/ProfilesController.cs | 12 ++-- Gordon360/Documentation/Gordon360.xml | 25 ++++++-- .../FacultyStaffPrivacyViewModel.cs | 9 +++ Gordon360/Services/ProfileService.cs | 59 ++++++++++++++++++- Gordon360/Services/ServiceInterfaces.cs | 2 +- 5 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 Gordon360/Models/ViewModels/FacultyStaffPrivacyViewModel.cs diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index 3ce2b1b3b..da3a4d562 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -476,18 +476,14 @@ public async Task> UpdateOfficeHours( /// /// Update visibility of some piece of personal data for facstaff. /// - /// Identifies the piece of information (home phone, etc.) - /// Specifies who to show this field to (public, private, facstaff) + /// Faculty Staff Privacy Decisions /// [HttpPut] - [Route("facstaff_privacy/field/{field}/permission/{permission}")] - public async Task UpdateFacStaffPrivacyAsync(string field, string permission) + [Route("facstaff_privacy")] + public async Task> UpdateFacStaffPrivacyAsync(FacultyStaffPrivacyViewModel facultyStaffPrivacy) { - // Since the database stores each permission in a separate row for the - // role that can access it, a single call will change multiple rows. - // For example, private will need to delete all rows for this person and field. var authenticatedUserUsername = AuthUtils.GetUsername(User); - await _profileService.UpdateFacStaffPrivacyAsync(authenticatedUserUsername, field, permission); + await _profileService.UpdateFacStaffPrivacyAsync(authenticatedUserUsername, facultyStaffPrivacy); return Ok(); } diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index ec5260d9b..1e405ec04 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -672,11 +672,11 @@ office hours - + - Update privacy of home phone number + Update visibility of some piece of personal data for facstaff. - Y or N + Faculty Staff Privacy Decisions @@ -2373,12 +2373,27 @@ - + privacy setting of home phone. AD Username - Y or N + Y or N + Y or N + + + + privacy setting of home phone. + + AD Username + Faculty Staff Privacy View Model + + + + privacy setting of home phone. + + AD Username + Faculty Staff Privacy View Model diff --git a/Gordon360/Models/ViewModels/FacultyStaffPrivacyViewModel.cs b/Gordon360/Models/ViewModels/FacultyStaffPrivacyViewModel.cs new file mode 100644 index 000000000..45af3d765 --- /dev/null +++ b/Gordon360/Models/ViewModels/FacultyStaffPrivacyViewModel.cs @@ -0,0 +1,9 @@ +namespace Gordon360.Models.ViewModels +{ + public class FacultyStaffPrivacyViewModel + { + public string field { get; set; } + public string viewer { get; set; } + public bool visiable { get; set; } + } +} \ No newline at end of file diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 9a54ec619..8ad951ab1 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -4,7 +4,6 @@ using Gordon360.Models.ViewModels; using Gordon360.Models.webSQL.Context; using Microsoft.AspNetCore.Authorization; -using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.Extensions.Configuration; using Newtonsoft.Json.Linq; using System; @@ -14,6 +13,7 @@ using System.Net; using System.Net.Mail; using System.Threading.Tasks; +using Privacy = Gordon360.Models.CCT.FacStaff_Privacy; namespace Gordon360.Services { @@ -290,10 +290,9 @@ public async Task UpdateProfileLinkAsync(string username, string type, CUSTOM_PR /// AD Username /// Y or N /// Y or N - public async Task UpdateFacStaffPrivacyAsync(string username, string field, string viewer) + public async Task AddFacStaffPrivacyAsync(string username, string field, string viewer) { var account = _accountService.GetAccountByUsername(username); - await _context.Procedures.UPDATE_PHONE_PRIVACYAsync(int.Parse(account.GordonID), value); // Update value in cached data var facStaff = _context.FacStaff_Privacy.FirstOrDefault(x => x.gordon_id == account.GordonID); if (facStaff != null) @@ -305,6 +304,60 @@ public async Task UpdateFacStaffPrivacyAsync(string username, string field, stri _context.SaveChanges(); } + /// + /// privacy setting of home phone. + /// + /// AD Username + /// Faculty Staff Privacy View Model + public async Task UpdateFacStaffPrivacyAsync(string username, FacultyStaffPrivacyViewModel facultyStaffPrivacy) + { + var account = _accountService.GetAccountByUsername(username); + var facStaff = _context.FacStaff_Privacy.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Field == facultyStaffPrivacy.field); + if (facStaff == null) + { + var privacy = new Privacy + { + gordon_id = account.GordonID, + Field = facultyStaffPrivacy.field, + Viewer = facultyStaffPrivacy.viewer + }; ; + await _context.FacStaff_Privacy.AddAsync(privacy); + } + else + { + facStaff.Viewer = facultyStaffPrivacy.viewer; + } + + _context.SaveChanges(); + } + + /// + /// privacy setting of home phone. + /// + /// AD Username + /// Faculty Staff Privacy View Model + public async Task UpdateFacStaffPrivacyAsync2(string username, FacultyStaffPrivacyViewModel facultyStaffPrivacy) + { + var account = _accountService.GetAccountByUsername(username); + var facStaff = _context.FacStaff_Privacy.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Field == facultyStaffPrivacy.field && x.Viewer == facultyStaffPrivacy.viewer); + if (facStaff == null && facultyStaffPrivacy.visiable) + { + var privacy = new Privacy + { + gordon_id = account.GordonID, + Field = facultyStaffPrivacy.field, + Viewer = facultyStaffPrivacy.viewer + }; + await _context.FacStaff_Privacy.AddAsync(privacy); + } + else if (facStaff != null && !facultyStaffPrivacy.visiable) + { + facStaff.Viewer = facultyStaffPrivacy.viewer; + } + + _context.SaveChanges(); + } + /// /// privacy setting of mobile phone. /// diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index 5a6c256f7..c4491a791 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -37,7 +37,7 @@ public interface IProfileService Task UpdateMobilePhoneNumberAsync(string username, string newMobilePhoneNumber); Task UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom); Task UpdateOfficeHoursAsync(string username, string newHours); - Task UpdateHomePrivacyAsync(string username, string value); + Task UpdateFacStaffPrivacyAsync(string username, FacultyStaffPrivacyViewModel facultyStaffPrivacy); Task UpdateMobilePrivacyAsync(string username, string value); Task UpdateImagePrivacyAsync(string username, string value); Task UpdateProfileImageAsync(string username, string path, string name); From 3a768b3f5ef9015d6a7ee8ae688a1d67408365b0 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Fri, 30 Jun 2023 10:30:40 -0400 Subject: [PATCH 10/44] decided using one row for each User and Field --- Gordon360/Documentation/Gordon360.xml | 15 ------ .../FacultyStaffPrivacyViewModel.cs | 1 - Gordon360/Services/ProfileService.cs | 51 +------------------ 3 files changed, 2 insertions(+), 65 deletions(-) diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index 1e405ec04..c299c9134 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -2373,14 +2373,6 @@ - - - privacy setting of home phone. - - AD Username - Y or N - Y or N - privacy setting of home phone. @@ -2388,13 +2380,6 @@ AD Username Faculty Staff Privacy View Model - - - privacy setting of home phone. - - AD Username - Faculty Staff Privacy View Model - privacy setting of mobile phone. diff --git a/Gordon360/Models/ViewModels/FacultyStaffPrivacyViewModel.cs b/Gordon360/Models/ViewModels/FacultyStaffPrivacyViewModel.cs index 45af3d765..ae9b6f339 100644 --- a/Gordon360/Models/ViewModels/FacultyStaffPrivacyViewModel.cs +++ b/Gordon360/Models/ViewModels/FacultyStaffPrivacyViewModel.cs @@ -4,6 +4,5 @@ public class FacultyStaffPrivacyViewModel { public string field { get; set; } public string viewer { get; set; } - public bool visiable { get; set; } } } \ No newline at end of file diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 8ad951ab1..a52cd8aeb 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -285,27 +285,7 @@ public async Task UpdateProfileLinkAsync(string username, string type, CUSTOM_PR } /// - /// privacy setting of home phone. - /// - /// AD Username - /// Y or N - /// Y or N - public async Task AddFacStaffPrivacyAsync(string username, string field, string viewer) - { - var account = _accountService.GetAccountByUsername(username); - // Update value in cached data - var facStaff = _context.FacStaff_Privacy.FirstOrDefault(x => x.gordon_id == account.GordonID); - if (facStaff != null) - { - facStaff.Field = (field == "HomePhoneNumber" ? "HomePhoneNumber" : null); - facStaff.Viewer = (viewer == "Student" ? "Student" : null); - } - - _context.SaveChanges(); - } - - /// - /// privacy setting of home phone. + /// privacy setting of a specific field /// /// AD Username /// Faculty Staff Privacy View Model @@ -314,33 +294,6 @@ public async Task UpdateFacStaffPrivacyAsync(string username, FacultyStaffPrivac var account = _accountService.GetAccountByUsername(username); var facStaff = _context.FacStaff_Privacy.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Field == facultyStaffPrivacy.field); if (facStaff == null) - { - var privacy = new Privacy - { - gordon_id = account.GordonID, - Field = facultyStaffPrivacy.field, - Viewer = facultyStaffPrivacy.viewer - }; ; - await _context.FacStaff_Privacy.AddAsync(privacy); - } - else - { - facStaff.Viewer = facultyStaffPrivacy.viewer; - } - - _context.SaveChanges(); - } - - /// - /// privacy setting of home phone. - /// - /// AD Username - /// Faculty Staff Privacy View Model - public async Task UpdateFacStaffPrivacyAsync2(string username, FacultyStaffPrivacyViewModel facultyStaffPrivacy) - { - var account = _accountService.GetAccountByUsername(username); - var facStaff = _context.FacStaff_Privacy.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Field == facultyStaffPrivacy.field && x.Viewer == facultyStaffPrivacy.viewer); - if (facStaff == null && facultyStaffPrivacy.visiable) { var privacy = new Privacy { @@ -350,7 +303,7 @@ public async Task UpdateFacStaffPrivacyAsync2(string username, FacultyStaffPriva }; await _context.FacStaff_Privacy.AddAsync(privacy); } - else if (facStaff != null && !facultyStaffPrivacy.visiable) + else { facStaff.Viewer = facultyStaffPrivacy.viewer; } From e3c398ee277384254fff40957447d33f6e88ad95 Mon Sep 17 00:00:00 2001 From: amos-cha Date: Fri, 30 Jun 2023 11:01:46 -0400 Subject: [PATCH 11/44] Update table connections --- Gordon360/Models/CCT/Context/CCTContext.cs | 52 ++++++++++++------- .../Models/CCT/Context/efpt.CCT.config.json | 24 ++++----- ...ff_Field_Type.cs => UserPrivacy_Fields.cs} | 4 +- ...aff_Privacy.cs => UserPrivacy_Settings.cs} | 14 +++-- ...pe.cs => UserPrivacy_Visibility_Groups.cs} | 6 +-- .../Models/ViewModels/UserPrivacyViewModel.cs | 8 +++ 6 files changed, 67 insertions(+), 41 deletions(-) rename Gordon360/Models/CCT/dbo/{FacStaff_Field_Type.cs => UserPrivacy_Fields.cs} (83%) rename Gordon360/Models/CCT/dbo/{FacStaff_Privacy.cs => UserPrivacy_Settings.cs} (60%) rename Gordon360/Models/CCT/dbo/{FacStaff_Viewer_Type.cs => UserPrivacy_Visibility_Groups.cs} (73%) create mode 100644 Gordon360/Models/ViewModels/UserPrivacyViewModel.cs diff --git a/Gordon360/Models/CCT/Context/CCTContext.cs b/Gordon360/Models/CCT/Context/CCTContext.cs index 912e1d864..e1da4c345 100644 --- a/Gordon360/Models/CCT/Context/CCTContext.cs +++ b/Gordon360/Models/CCT/Context/CCTContext.cs @@ -44,9 +44,6 @@ public CCTContext(DbContextOptions options) public virtual DbSet ERROR_LOG { get; set; } public virtual DbSet EmergencyContact { get; set; } public virtual DbSet FacStaff { get; set; } - public virtual DbSet FacStaff_Field_Type { get; set; } - public virtual DbSet FacStaff_Privacy { get; set; } - public virtual DbSet FacStaff_Viewer_Type { get; set; } public virtual DbSet Graduation { get; set; } public virtual DbSet Health_Question { get; set; } public virtual DbSet Health_Status { get; set; } @@ -106,6 +103,9 @@ public CCTContext(DbContextOptions options) public virtual DbSet Team { get; set; } public virtual DbSet TeamStatus { get; set; } public virtual DbSet Timesheets_Clock_In_Out { get; set; } + public virtual DbSet UserPrivacy_Fields { get; set; } + public virtual DbSet UserPrivacy_Settings { get; set; } + public virtual DbSet UserPrivacy_Visibility_Groups { get; set; } public virtual DbSet User_Connection_Ids { get; set; } public virtual DbSet User_Rooms { get; set; } public virtual DbSet Users { get; set; } @@ -298,23 +298,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(e => e.BuildingDescription).IsFixedLength(); }); - modelBuilder.Entity(entity => - { - entity.Property(e => e.ID).ValueGeneratedOnAdd(); - }); - - modelBuilder.Entity(entity => - { - entity.Property(e => e.Field).HasDefaultValueSql("((0))"); - - entity.Property(e => e.Viewer).HasDefaultValueSql("((0))"); - }); - - modelBuilder.Entity(entity => - { - entity.Property(e => e.ID).ValueGeneratedOnAdd(); - }); - modelBuilder.Entity(entity => { entity.ToView("Graduation", "dbo"); @@ -750,6 +733,35 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasConstraintName("FK_Team_TeamStatus"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Field) + .HasName("Field"); + entity.Property(e => e.ID).ValueGeneratedOnAdd(); + }); + + modelBuilder.Entity(entity => + { + entity.HasOne(d => d.FieldNavigation) + .WithMany() + .HasForeignKey(d => d.Field) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("FK_UserPrivacy_Settings_UserPrivacy_Fields"); + + entity.HasOne(d => d.VisibilityNavigation) + .WithMany() + .HasForeignKey(d => d.Visibility) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("FK_UserPrivacy_Settings_UserPrivacy_Visibility_Groups"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Group) + .HasName("Group"); + entity.Property(e => e.ID).ValueGeneratedOnAdd(); + }); + modelBuilder.HasSequence("Information_Change_Request_Seq", "dbo"); OnModelCreatingGeneratedProcedures(modelBuilder); diff --git a/Gordon360/Models/CCT/Context/efpt.CCT.config.json b/Gordon360/Models/CCT/Context/efpt.CCT.config.json index c69e50acc..623db5d0b 100644 --- a/Gordon360/Models/CCT/Context/efpt.CCT.config.json +++ b/Gordon360/Models/CCT/Context/efpt.CCT.config.json @@ -38,18 +38,6 @@ "Name": "[dbo].[ERROR_LOG]", "ObjectType": 0 }, - { - "Name": "[dbo].[FacStaff_Field_Type]", - "ObjectType": 0 - }, - { - "Name": "[dbo].[FacStaff_Privacy]", - "ObjectType": 0 - }, - { - "Name": "[dbo].[FacStaff_Viewer_Type]", - "ObjectType": 0 - }, { "Name": "[dbo].[Health_Question]", "ObjectType": 0 @@ -142,6 +130,18 @@ "Name": "[dbo].[User_Rooms]", "ObjectType": 0 }, + { + "Name": "[dbo].[UserPrivacy_Fields]", + "ObjectType": 0 + }, + { + "Name": "[dbo].[UserPrivacy_Settings]", + "ObjectType": 0 + }, + { + "Name": "[dbo].[UserPrivacy_Visibility_Groups]", + "ObjectType": 0 + }, { "Name": "[dbo].[Users]", "ObjectType": 0 diff --git a/Gordon360/Models/CCT/dbo/FacStaff_Field_Type.cs b/Gordon360/Models/CCT/dbo/UserPrivacy_Fields.cs similarity index 83% rename from Gordon360/Models/CCT/dbo/FacStaff_Field_Type.cs rename to Gordon360/Models/CCT/dbo/UserPrivacy_Fields.cs index b49a69ce4..ccf7036d8 100644 --- a/Gordon360/Models/CCT/dbo/FacStaff_Field_Type.cs +++ b/Gordon360/Models/CCT/dbo/UserPrivacy_Fields.cs @@ -8,8 +8,8 @@ namespace Gordon360.Models.CCT { - [Table("FacStaff_Field_Type", Schema = "dbo")] - public partial class FacStaff_Field_Type + [Table("UserPrivacy_Fields", Schema = "dbo")] + public partial class UserPrivacy_Fields { public int ID { get; set; } [Key] diff --git a/Gordon360/Models/CCT/dbo/FacStaff_Privacy.cs b/Gordon360/Models/CCT/dbo/UserPrivacy_Settings.cs similarity index 60% rename from Gordon360/Models/CCT/dbo/FacStaff_Privacy.cs rename to Gordon360/Models/CCT/dbo/UserPrivacy_Settings.cs index db1ef144c..4bcdaf156 100644 --- a/Gordon360/Models/CCT/dbo/FacStaff_Privacy.cs +++ b/Gordon360/Models/CCT/dbo/UserPrivacy_Settings.cs @@ -8,10 +8,11 @@ namespace Gordon360.Models.CCT { - [Table("FacStaff_Privacy", Schema = "dbo")] - public partial class FacStaff_Privacy + [Keyless] + [Table("UserPrivacy_Settings", Schema = "dbo")] + public partial class UserPrivacy_Settings { - [Key] + [Required] [StringLength(10)] [Unicode(false)] public string gordon_id { get; set; } @@ -22,6 +23,11 @@ public partial class FacStaff_Privacy [Required] [StringLength(50)] [Unicode(false)] - public string Viewer { get; set; } + public string Visibility { get; set; } + + [ForeignKey("Field")] + public virtual UserPrivacy_Fields FieldNavigation { get; set; } + [ForeignKey("Visibility")] + public virtual UserPrivacy_Visibility_Groups VisibilityNavigation { get; set; } } } \ No newline at end of file diff --git a/Gordon360/Models/CCT/dbo/FacStaff_Viewer_Type.cs b/Gordon360/Models/CCT/dbo/UserPrivacy_Visibility_Groups.cs similarity index 73% rename from Gordon360/Models/CCT/dbo/FacStaff_Viewer_Type.cs rename to Gordon360/Models/CCT/dbo/UserPrivacy_Visibility_Groups.cs index 5c4c0d118..b0485acf1 100644 --- a/Gordon360/Models/CCT/dbo/FacStaff_Viewer_Type.cs +++ b/Gordon360/Models/CCT/dbo/UserPrivacy_Visibility_Groups.cs @@ -8,13 +8,13 @@ namespace Gordon360.Models.CCT { - [Table("FacStaff_Viewer_Type", Schema = "dbo")] - public partial class FacStaff_Viewer_Type + [Table("UserPrivacy_Visibility_Groups", Schema = "dbo")] + public partial class UserPrivacy_Visibility_Groups { public int ID { get; set; } [Key] [StringLength(50)] [Unicode(false)] - public string Viewer { get; set; } + public string Group { get; set; } } } \ No newline at end of file diff --git a/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs b/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs new file mode 100644 index 000000000..20f075e63 --- /dev/null +++ b/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs @@ -0,0 +1,8 @@ +namespace Gordon360.Models.ViewModels +{ + public class UserPrivacyViewModel + { + public string field { get; set; } + public string viewer { get; set; } + } +} \ No newline at end of file From 7f5f0c2eb9f727079687c477bcd22d80fc0295c9 Mon Sep 17 00:00:00 2001 From: amos-cha Date: Fri, 30 Jun 2023 11:08:33 -0400 Subject: [PATCH 12/44] Fix syntax errors --- Gordon360/Controllers/ProfilesController.cs | 2 +- Gordon360/Documentation/Gordon360.xml | 19 +----- .../FacultyStaffPrivacyViewModel.cs | 9 --- .../Models/ViewModels/UserPrivacyViewModel.cs | 4 +- Gordon360/Services/ProfileService.cs | 65 +++---------------- Gordon360/Services/ServiceInterfaces.cs | 2 +- 6 files changed, 15 insertions(+), 86 deletions(-) delete mode 100644 Gordon360/Models/ViewModels/FacultyStaffPrivacyViewModel.cs diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index da3a4d562..b5960bcc3 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -480,7 +480,7 @@ public async Task> UpdateOfficeHours( /// [HttpPut] [Route("facstaff_privacy")] - public async Task> UpdateFacStaffPrivacyAsync(FacultyStaffPrivacyViewModel facultyStaffPrivacy) + public async Task> UpdateFacStaffPrivacyAsync(UserPrivacyViewModel facultyStaffPrivacy) { var authenticatedUserUsername = AuthUtils.GetUsername(User); await _profileService.UpdateFacStaffPrivacyAsync(authenticatedUserUsername, facultyStaffPrivacy); diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index 1e405ec04..e8d6ac062 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -672,7 +672,7 @@ office hours - + Update visibility of some piece of personal data for facstaff. @@ -2373,22 +2373,7 @@ - - - privacy setting of home phone. - - AD Username - Y or N - Y or N - - - - privacy setting of home phone. - - AD Username - Faculty Staff Privacy View Model - - + privacy setting of home phone. diff --git a/Gordon360/Models/ViewModels/FacultyStaffPrivacyViewModel.cs b/Gordon360/Models/ViewModels/FacultyStaffPrivacyViewModel.cs deleted file mode 100644 index 45af3d765..000000000 --- a/Gordon360/Models/ViewModels/FacultyStaffPrivacyViewModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Gordon360.Models.ViewModels -{ - public class FacultyStaffPrivacyViewModel - { - public string field { get; set; } - public string viewer { get; set; } - public bool visiable { get; set; } - } -} \ No newline at end of file diff --git a/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs b/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs index 20f075e63..43c39787b 100644 --- a/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs +++ b/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs @@ -2,7 +2,7 @@ { public class UserPrivacyViewModel { - public string field { get; set; } - public string viewer { get; set; } + public string Field { get; set; } + public string VisibilityGroup { get; set; } } } \ No newline at end of file diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 8ad951ab1..0d7217cb5 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -13,7 +13,6 @@ using System.Net; using System.Net.Mail; using System.Threading.Tasks; -using Privacy = Gordon360.Models.CCT.FacStaff_Privacy; namespace Gordon360.Services { @@ -284,75 +283,28 @@ public async Task UpdateProfileLinkAsync(string username, string type, CUSTOM_PR await _context.SaveChangesAsync(); } - /// - /// privacy setting of home phone. - /// - /// AD Username - /// Y or N - /// Y or N - public async Task AddFacStaffPrivacyAsync(string username, string field, string viewer) - { - var account = _accountService.GetAccountByUsername(username); - // Update value in cached data - var facStaff = _context.FacStaff_Privacy.FirstOrDefault(x => x.gordon_id == account.GordonID); - if (facStaff != null) - { - facStaff.Field = (field == "HomePhoneNumber" ? "HomePhoneNumber" : null); - facStaff.Viewer = (viewer == "Student" ? "Student" : null); - } - - _context.SaveChanges(); - } - /// /// privacy setting of home phone. /// /// AD Username /// Faculty Staff Privacy View Model - public async Task UpdateFacStaffPrivacyAsync(string username, FacultyStaffPrivacyViewModel facultyStaffPrivacy) + public async Task UpdateFacStaffPrivacyAsync(string username, UserPrivacyViewModel facultyStaffPrivacy) { var account = _accountService.GetAccountByUsername(username); - var facStaff = _context.FacStaff_Privacy.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Field == facultyStaffPrivacy.field); - if (facStaff == null) + var facStaff = _context.UserPrivacy_Settings.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Field == facultyStaffPrivacy.Field); + if (facStaff is null) { - var privacy = new Privacy + var privacy = new UserPrivacy_Settings { gordon_id = account.GordonID, - Field = facultyStaffPrivacy.field, - Viewer = facultyStaffPrivacy.viewer + Field = facultyStaffPrivacy.Field, + Visibility = facultyStaffPrivacy.VisibilityGroup }; ; - await _context.FacStaff_Privacy.AddAsync(privacy); + await _context.UserPrivacy_Settings.AddAsync(privacy); } else { - facStaff.Viewer = facultyStaffPrivacy.viewer; - } - - _context.SaveChanges(); - } - - /// - /// privacy setting of home phone. - /// - /// AD Username - /// Faculty Staff Privacy View Model - public async Task UpdateFacStaffPrivacyAsync2(string username, FacultyStaffPrivacyViewModel facultyStaffPrivacy) - { - var account = _accountService.GetAccountByUsername(username); - var facStaff = _context.FacStaff_Privacy.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Field == facultyStaffPrivacy.field && x.Viewer == facultyStaffPrivacy.viewer); - if (facStaff == null && facultyStaffPrivacy.visiable) - { - var privacy = new Privacy - { - gordon_id = account.GordonID, - Field = facultyStaffPrivacy.field, - Viewer = facultyStaffPrivacy.viewer - }; - await _context.FacStaff_Privacy.AddAsync(privacy); - } - else if (facStaff != null && !facultyStaffPrivacy.visiable) - { - facStaff.Viewer = facultyStaffPrivacy.viewer; + facStaff.Visibility = facultyStaffPrivacy.VisibilityGroup; } _context.SaveChanges(); @@ -564,5 +516,6 @@ private static JObject MergeProfile(JObject profile, JObject profileInfo) }); return profile; } + } } diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index c4491a791..b2018d022 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -37,7 +37,7 @@ public interface IProfileService Task UpdateMobilePhoneNumberAsync(string username, string newMobilePhoneNumber); Task UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom); Task UpdateOfficeHoursAsync(string username, string newHours); - Task UpdateFacStaffPrivacyAsync(string username, FacultyStaffPrivacyViewModel facultyStaffPrivacy); + Task UpdateFacStaffPrivacyAsync(string username, UserPrivacyViewModel facultyStaffPrivacy); Task UpdateMobilePrivacyAsync(string username, string value); Task UpdateImagePrivacyAsync(string username, string value); Task UpdateProfileImageAsync(string username, string path, string name); From ee37a34fc4972ba3d5f45f55052731ec2abc3379 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Fri, 30 Jun 2023 17:31:09 -0400 Subject: [PATCH 13/44] finishing get profile functions --- Gordon360/Controllers/ProfilesController.cs | 6 +-- Gordon360/Services/ProfileService.cs | 47 ++++++++++++++++++++- Gordon360/Services/ServiceInterfaces.cs | 4 +- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index b5960bcc3..ad31782e9 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -86,7 +86,7 @@ public ProfilesController(IProfileService profileService, IAccountService accoun else if (viewerGroups.Contains(AuthGroup.FacStaff)) { student = _student; - faculty = _faculty == null ? null : (PublicFacultyStaffProfileViewModel)_faculty; + faculty = _faculty == null ? null : _profileService.ToPublicFacultyStaffProfileViewModel(username, "fac", _faculty); alumni = _alumni == null ? null : (PublicAlumniProfileViewModel)_alumni; } else if (viewerGroups.Contains(AuthGroup.Student)) @@ -480,10 +480,10 @@ public async Task> UpdateOfficeHours( /// [HttpPut] [Route("facstaff_privacy")] - public async Task> UpdateFacStaffPrivacyAsync(UserPrivacyViewModel facultyStaffPrivacy) + public async Task> UpdateUserPrivacyAsync(UserPrivacyViewModel facultyStaffPrivacy) { var authenticatedUserUsername = AuthUtils.GetUsername(User); - await _profileService.UpdateFacStaffPrivacyAsync(authenticatedUserUsername, facultyStaffPrivacy); + await _profileService.UpdateUserPrivacyAsync(authenticatedUserUsername, facultyStaffPrivacy); return Ok(); } diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 0d7217cb5..c28a55a76 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -283,12 +283,57 @@ public async Task UpdateProfileLinkAsync(string username, string type, CUSTOM_PR await _context.SaveChangesAsync(); } + public async Task ToPublicFacultyStaffProfileViewModel + (string username, string currentUser, FacultyStaffProfileViewModel fac) + { + PublicFacultyStaffProfileViewModel publicFac = (PublicFacultyStaffProfileViewModel) fac; + var account = _accountService.GetAccountByUsername(username); + var user = _context.UserPrivacy_Settings.FirstOrDefault(x => x.gordon_id == account.GordonID); + if (user == null) + { + publicFac.HomeCity = ""; + publicFac.HomeState = ""; + publicFac.HomeCountry = ""; + publicFac.SpouseName = ""; + publicFac.Country = ""; + publicFac.HomePhone = ""; + publicFac.MobilePhone = ""; + } + else + { + // Find out all the rows that contain Private value in Visibility column for the user who has been searched for + var privateOption = _context.UserPrivacy_Settings.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Visibility == "Private"); + if (privateOption != null) + { + if (privateOption.Field == "HomeCity") publicFac.HomeCity = ""; + if (privateOption.Field == "HomeState") publicFac.HomeState = ""; + if (privateOption.Field == "HomeCountry") publicFac.HomeCountry = ""; + if (privateOption.Field == "SpouseName") publicFac.SpouseName = ""; + if (privateOption.Field == "Country") publicFac.Country = ""; + if (privateOption.Field == "HomePhone") publicFac.HomePhone = ""; + if (privateOption.Field == "MobilePhone") publicFac.MobilePhone = ""; + } + var facStaffOption = _context.UserPrivacy_Settings.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Visibility == "FacStaff"); + if (facStaffOption != null) + { + if (facStaffOption.Field == "HomeCity" && (currentUser == "stu" || currentUser == "alu")) publicFac.HomeCity = ""; + if (facStaffOption.Field == "HomeState" && (currentUser == "stu" || currentUser == "alu")) publicFac.HomeState = ""; + if (facStaffOption.Field == "HomeCountry" && (currentUser == "stu" || currentUser == "alu")) publicFac.HomeCountry = ""; + if (facStaffOption.Field == "SpouseName" && (currentUser == "stu" || currentUser == "alu")) publicFac.SpouseName = ""; + if (facStaffOption.Field == "Country" && (currentUser == "stu" || currentUser == "alu")) publicFac.Country = ""; + if (facStaffOption.Field == "HomePhone" && (currentUser == "stu" || currentUser == "alu")) publicFac.HomePhone = ""; + if (facStaffOption.Field == "MobilePhone" && (currentUser == "stu" || currentUser == "alu")) publicFac.MobilePhone = ""; + } + } + return publicFac; + } + /// /// privacy setting of home phone. /// /// AD Username /// Faculty Staff Privacy View Model - public async Task UpdateFacStaffPrivacyAsync(string username, UserPrivacyViewModel facultyStaffPrivacy) + public async Task UpdateUserPrivacyAsync(string username, UserPrivacyViewModel facultyStaffPrivacy) { var account = _accountService.GetAccountByUsername(username); var facStaff = _context.UserPrivacy_Settings.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Field == facultyStaffPrivacy.Field); diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index b2018d022..d0bff0e38 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -37,7 +37,9 @@ public interface IProfileService Task UpdateMobilePhoneNumberAsync(string username, string newMobilePhoneNumber); Task UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom); Task UpdateOfficeHoursAsync(string username, string newHours); - Task UpdateFacStaffPrivacyAsync(string username, UserPrivacyViewModel facultyStaffPrivacy); + Task ToPublicFacultyStaffProfileViewModel + (string username, string currentUser, FacultyStaffProfileViewModel fac); + Task UpdateUserPrivacyAsync(string username, UserPrivacyViewModel facultyStaffPrivacy); Task UpdateMobilePrivacyAsync(string username, string value); Task UpdateImagePrivacyAsync(string username, string value); Task UpdateProfileImageAsync(string username, string path, string name); From 3ab1e77273063d4472a083900d2b21d4286fceef Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Mon, 3 Jul 2023 10:22:15 -0400 Subject: [PATCH 14/44] using a better way to wipe out the private imformation --- Gordon360/Services/ProfileService.cs | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index c28a55a76..4d1eb0106 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -302,6 +302,8 @@ public async Task ToPublicFacultyStaffProfil else { // Find out all the rows that contain Private value in Visibility column for the user who has been searched for + // May be used later + /* var privateOption = _context.UserPrivacy_Settings.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Visibility == "Private"); if (privateOption != null) { @@ -324,6 +326,62 @@ public async Task ToPublicFacultyStaffProfil if (facStaffOption.Field == "HomePhone" && (currentUser == "stu" || currentUser == "alu")) publicFac.HomePhone = ""; if (facStaffOption.Field == "MobilePhone" && (currentUser == "stu" || currentUser == "alu")) publicFac.MobilePhone = ""; } + */ + + // May be used later + // List thing = new() { }; + //foreach (UserPrivacy_Fields field in _context.UserPrivacy_Fields) + //{ + + //} + + // 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_Fields field in _context.UserPrivacy_Fields) + { + + var row = privacy.FirstOrDefault(p => p.Field == field.Field); + if (row is UserPrivacy_Settings instance) + if (instance.Visibility == "Private" || (instance.Visibility == "FacStaff" && currentUser != "fac")) + fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); + else + fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); + + // May be used later + // if (row is null) + // publicFac.HomeCity = ""; + + // switch (field.Field) + // { + // case "HomeCity": + + // if (row is UserPrivacy_Settings instance) + // { + // if (instance.Visibility == "Private") + // publicFac.HomeCity = ""; + // if (instance.Visibility == "FacStaff" && currentUser != "fac") + // publicFac.HomeCity = ""; + // } + // break; + // case "HomeState": + // break; + // case "HomeCountry": + // break; + // case "SpouseName": + // break; + // case "Country": + // break; + // case "HomePhone": + // break; + // case "MobilePhone": + // default: + // break; + // } + //} + } } return publicFac; } From ee5e0cb7dd9c1bc99fdf2c1e58ee6acccdf84593 Mon Sep 17 00:00:00 2001 From: amos-cha Date: Wed, 5 Jul 2023 10:04:47 -0400 Subject: [PATCH 15/44] Update variable naming --- Gordon360/Services/ServiceInterfaces.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index d0bff0e38..46f4d2d15 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -38,7 +38,7 @@ public interface IProfileService Task UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom); Task UpdateOfficeHoursAsync(string username, string newHours); Task ToPublicFacultyStaffProfileViewModel - (string username, string currentUser, FacultyStaffProfileViewModel fac); + (string username, string currentUserType, FacultyStaffProfileViewModel fac); Task UpdateUserPrivacyAsync(string username, UserPrivacyViewModel facultyStaffPrivacy); Task UpdateMobilePrivacyAsync(string username, string value); Task UpdateImagePrivacyAsync(string username, string value); From 3dcbf875a378e18a63408e72ffa7a21e773d061d Mon Sep 17 00:00:00 2001 From: amos-cha Date: Wed, 5 Jul 2023 10:05:13 -0400 Subject: [PATCH 16/44] Update to use route instead of direct cast --- Gordon360/Controllers/ProfilesController.cs | 12 ++++++++---- Gordon360/Documentation/Gordon360.xml | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index ad31782e9..3af879082 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -21,6 +21,7 @@ namespace Gordon360.Controllers { [Route("api/[controller]")] + [AllowAnonymous] public class ProfilesController : GordonControllerBase { private readonly IProfileService _profileService; @@ -42,7 +43,8 @@ public ProfilesController(IProfileService profileService, IAccountService accoun [Route("")] public ActionResult Get() { - var authenticatedUserUsername = AuthUtils.GetUsername(User); + // var authenticatedUserUsername = AuthUtils.GetUsername(User); + var authenticatedUserUsername = "amos.cha"; var student = _profileService.GetStudentProfileByUsername(authenticatedUserUsername); var faculty = _profileService.GetFacultyStaffProfileByUsername(authenticatedUserUsername); @@ -64,7 +66,7 @@ public ProfilesController(IProfileService profileService, IAccountService accoun /// [HttpGet] [Route("{username}")] - public ActionResult GetUserProfile(string username) + public async Task> GetUserProfileAsync(string username) { var viewerGroups = AuthUtils.GetGroups(User); @@ -77,6 +79,7 @@ public ProfilesController(IProfileService profileService, IAccountService accoun object? faculty = null; object? alumni = null; + if (viewerGroups.Contains(AuthGroup.SiteAdmin) || viewerGroups.Contains(AuthGroup.Police)) { student = _student; @@ -92,14 +95,14 @@ public ProfilesController(IProfileService profileService, IAccountService accoun else if (viewerGroups.Contains(AuthGroup.Student)) { student = _student == null ? null : (PublicStudentProfileViewModel)_student; - faculty = _faculty == null ? null : (PublicFacultyStaffProfileViewModel)_faculty; + faculty = _faculty == null ? null : await _profileService.ToPublicFacultyStaffProfileViewModel(username, "stu", _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) ? (PublicAlumniProfileViewModel)_alumni : null; } else if (viewerGroups.Contains(AuthGroup.Alumni)) { student = null; - faculty = _faculty == null ? null : (PublicFacultyStaffProfileViewModel)_faculty; + faculty = _faculty == null ? null : await _profileService.ToPublicFacultyStaffProfileViewModel(username, "alu", _faculty); alumni = _alumni == null ? null : (PublicAlumniProfileViewModel)_alumni; } @@ -107,6 +110,7 @@ public ProfilesController(IProfileService profileService, IAccountService accoun { return Ok(null); } + var profile = _profileService.ComposeProfile(student, alumni, faculty, _customInfo); diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index e8d6ac062..6b261b310 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -579,7 +579,7 @@ Get profile info of currently logged in user - + Get public profile info for a user username of the profile info @@ -672,7 +672,7 @@ office hours - + Update visibility of some piece of personal data for facstaff. @@ -2373,7 +2373,7 @@ - + privacy setting of home phone. From 48c14abe5b521303f9d2c811ddaa9f01eb5dbd7e Mon Sep 17 00:00:00 2001 From: amos-cha Date: Wed, 5 Jul 2023 10:05:37 -0400 Subject: [PATCH 17/44] Deprecate use of privacy bit for FacStaff --- .../ViewModels/PublicFacultyStaffProfileViewModel.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Gordon360/Models/ViewModels/PublicFacultyStaffProfileViewModel.cs b/Gordon360/Models/ViewModels/PublicFacultyStaffProfileViewModel.cs index 3e382a330..bcc12b325 100644 --- a/Gordon360/Models/ViewModels/PublicFacultyStaffProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/PublicFacultyStaffProfileViewModel.cs @@ -79,15 +79,6 @@ public static implicit operator PublicFacultyStaffProfileViewModel(FacultyStaffP Mail_Location = fac.Mail_Location ?? "", Mail_Description = fac.Mail_Description ?? "" }; - if (vm.KeepPrivate.Contains('1')) - { - vm.HomeCity = "Private as requested."; - vm.HomeState = ""; - vm.HomeCountry = ""; - vm.SpouseName = "Private as requested."; - vm.Country = ""; - vm.HomePhone = ""; - } return vm; } } From 2cd45e3277d51f514f2fed1477adf3d538806900 Mon Sep 17 00:00:00 2001 From: amos-cha Date: Wed, 5 Jul 2023 10:06:46 -0400 Subject: [PATCH 18/44] Fix async race condition Caused by await not being called on an async service Update logic to be less clunky --- Gordon360/Services/ProfileService.cs | 107 ++++----------------------- 1 file changed, 14 insertions(+), 93 deletions(-) diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 4d1eb0106..c2592f2c4 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -284,105 +284,26 @@ public async Task UpdateProfileLinkAsync(string username, string type, CUSTOM_PR } public async Task ToPublicFacultyStaffProfileViewModel - (string username, string currentUser, FacultyStaffProfileViewModel fac) + (string username, string currentUserType, FacultyStaffProfileViewModel fac) { PublicFacultyStaffProfileViewModel publicFac = (PublicFacultyStaffProfileViewModel) fac; var account = _accountService.GetAccountByUsername(username); - var user = _context.UserPrivacy_Settings.FirstOrDefault(x => x.gordon_id == account.GordonID); - if (user == null) - { - publicFac.HomeCity = ""; - publicFac.HomeState = ""; - publicFac.HomeCountry = ""; - publicFac.SpouseName = ""; - publicFac.Country = ""; - publicFac.HomePhone = ""; - publicFac.MobilePhone = ""; - } - else - { - // Find out all the rows that contain Private value in Visibility column for the user who has been searched for - // May be used later - /* - var privateOption = _context.UserPrivacy_Settings.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Visibility == "Private"); - if (privateOption != null) - { - if (privateOption.Field == "HomeCity") publicFac.HomeCity = ""; - if (privateOption.Field == "HomeState") publicFac.HomeState = ""; - if (privateOption.Field == "HomeCountry") publicFac.HomeCountry = ""; - if (privateOption.Field == "SpouseName") publicFac.SpouseName = ""; - if (privateOption.Field == "Country") publicFac.Country = ""; - if (privateOption.Field == "HomePhone") publicFac.HomePhone = ""; - if (privateOption.Field == "MobilePhone") publicFac.MobilePhone = ""; - } - var facStaffOption = _context.UserPrivacy_Settings.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Visibility == "FacStaff"); - if (facStaffOption != null) - { - if (facStaffOption.Field == "HomeCity" && (currentUser == "stu" || currentUser == "alu")) publicFac.HomeCity = ""; - if (facStaffOption.Field == "HomeState" && (currentUser == "stu" || currentUser == "alu")) publicFac.HomeState = ""; - if (facStaffOption.Field == "HomeCountry" && (currentUser == "stu" || currentUser == "alu")) publicFac.HomeCountry = ""; - if (facStaffOption.Field == "SpouseName" && (currentUser == "stu" || currentUser == "alu")) publicFac.SpouseName = ""; - if (facStaffOption.Field == "Country" && (currentUser == "stu" || currentUser == "alu")) publicFac.Country = ""; - if (facStaffOption.Field == "HomePhone" && (currentUser == "stu" || currentUser == "alu")) publicFac.HomePhone = ""; - if (facStaffOption.Field == "MobilePhone" && (currentUser == "stu" || currentUser == "alu")) publicFac.MobilePhone = ""; - } - */ - // May be used later - // List thing = new() { }; - //foreach (UserPrivacy_Fields field in _context.UserPrivacy_Fields) - //{ + // 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(); - //} - - // 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_Fields field in _context.UserPrivacy_Fields) - { - - var row = privacy.FirstOrDefault(p => p.Field == field.Field); - if (row is UserPrivacy_Settings instance) - if (instance.Visibility == "Private" || (instance.Visibility == "FacStaff" && currentUser != "fac")) - fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); - else - fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); - - // May be used later - // if (row is null) - // publicFac.HomeCity = ""; - - // switch (field.Field) - // { - // case "HomeCity": - - // if (row is UserPrivacy_Settings instance) - // { - // if (instance.Visibility == "Private") - // publicFac.HomeCity = ""; - // if (instance.Visibility == "FacStaff" && currentUser != "fac") - // publicFac.HomeCity = ""; - // } - // break; - // case "HomeState": - // break; - // case "HomeCountry": - // break; - // case "SpouseName": - // break; - // case "Country": - // break; - // case "HomePhone": - // break; - // case "MobilePhone": - // default: - // break; - // } - //} - } + foreach (UserPrivacy_Fields field in _context.UserPrivacy_Fields) + { + var row = privacy.FirstOrDefault(p => p.Field == field.Field); + if (row is UserPrivacy_Settings instance) + if (instance.Visibility == "Private" || (instance.Visibility == "FacStaff" && currentUserType != "fac")) + fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); + else + fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); } + return publicFac; } From 389f69d8f3233e814fd84451737eadf8bd497da4 Mon Sep 17 00:00:00 2001 From: Amos Cha <78386128+amos-cha@users.noreply.github.com> Date: Wed, 5 Jul 2023 10:13:31 -0400 Subject: [PATCH 19/44] Manage minor cleanup --- Gordon360/Controllers/ProfilesController.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index 07227cf83..ad34a0477 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -21,7 +21,6 @@ namespace Gordon360.Controllers { [Route("api/[controller]")] - [AllowAnonymous] public class ProfilesController : GordonControllerBase { private readonly IProfileService _profileService; @@ -43,8 +42,7 @@ public ProfilesController(IProfileService profileService, IAccountService accoun [Route("")] public ActionResult Get() { - // var authenticatedUserUsername = AuthUtils.GetUsername(User); - var authenticatedUserUsername = "amos.cha"; + var authenticatedUserUsername = AuthUtils.GetUsername(User); var student = _profileService.GetStudentProfileByUsername(authenticatedUserUsername); var faculty = _profileService.GetFacultyStaffProfileByUsername(authenticatedUserUsername); @@ -89,7 +87,8 @@ public ProfilesController(IProfileService profileService, IAccountService accoun else if (viewerGroups.Contains(AuthGroup.FacStaff)) { student = _student; - faculty = _faculty == null ? null : _profileService.ToPublicFacultyStaffProfileViewModel(username, "fac", _faculty); + faculty = _faculty == null ? null : + _profileService.ToPublicFacultyStaffProfileViewModel(username, "fac", _faculty); alumni = _alumni == null ? null : (PublicAlumniProfileViewModel)_alumni; } else if (viewerGroups.Contains(AuthGroup.Student)) @@ -105,7 +104,8 @@ public ProfilesController(IProfileService profileService, IAccountService accoun else if (viewerGroups.Contains(AuthGroup.Alumni)) { student = null; - faculty = _faculty == null ? null : await _profileService.ToPublicFacultyStaffProfileViewModel(username, "alu", _faculty); + faculty = _faculty == null ? null : + await _profileService.ToPublicFacultyStaffProfileViewModel(username, "alu", _faculty); alumni = _alumni == null ? null : (PublicAlumniProfileViewModel)_alumni; } From 36d0bad6c64e69aaa2b5e6ccb1b873b543d982e0 Mon Sep 17 00:00:00 2001 From: amos-cha Date: Wed, 5 Jul 2023 10:24:01 -0400 Subject: [PATCH 20/44] Add SyB to `put` route --- Gordon360/Authorization/StateYourBusiness.cs | 6 +++++- Gordon360/Controllers/ProfilesController.cs | 1 + Gordon360/Static Classes/Names.cs | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Gordon360/Authorization/StateYourBusiness.cs b/Gordon360/Authorization/StateYourBusiness.cs index 4bc1cb693..3f7e29ef7 100644 --- a/Gordon360/Authorization/StateYourBusiness.cs +++ b/Gordon360/Authorization/StateYourBusiness.cs @@ -646,7 +646,11 @@ private async Task CanUpdateAsync(string resource) return false; } - + case Resource.PROFILE_PRIVACY: + { + // current implementation only allows for facstaff implementation. + return user_groups.Contains(AuthGroup.FacStaff); + } case Resource.ACTIVITY_INFO: { // User is admin diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index ad34a0477..7ed4cac82 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -487,6 +487,7 @@ public async Task> UpdateOfficeHours( /// [HttpPut] [Route("facstaff_privacy")] + [StateYourBusiness(operation = Operation.UPDATE, resource = Resource.PROFILE_PRIVACY)] public async Task> UpdateUserPrivacyAsync(UserPrivacyViewModel facultyStaffPrivacy) { var authenticatedUserUsername = AuthUtils.GetUsername(User); diff --git a/Gordon360/Static Classes/Names.cs b/Gordon360/Static Classes/Names.cs index cf4f99f3b..a4ae61754 100644 --- a/Gordon360/Static Classes/Names.cs +++ b/Gordon360/Static Classes/Names.cs @@ -6,6 +6,7 @@ public static class Resource { public const string EMERGENCY_CONTACT = "A new emergency contact resource"; public const string PROFILE = "A new profile resource"; + public const string PROFILE_PRIVACY = "A individual's specific profile privacy resrouce"; public const string MEMBERSHIP_REQUEST = "A Membership Request Resource"; public const string MEMBERSHIP = "A Membership Resource"; public const string MEMBERSHIP_PRIVACY = "A Membership privacy"; From 1af67aa317b8eb91a36a8d185d1f8e30c6db3ec1 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Fri, 7 Jul 2023 15:22:20 -0400 Subject: [PATCH 21/44] add primary key --- Gordon360/Controllers/ProfilesController.cs | 40 ++++++++++++++----- Gordon360/Documentation/Gordon360.xml | 18 ++++++--- Gordon360/Models/CCT/Context/CCTContext.cs | 10 ++--- Gordon360/Models/CCT/dbo/CUSTOM_PROFILE.cs | 3 ++ Gordon360/Models/CCT/dbo/Student.cs | 3 ++ .../Models/CCT/dbo/UserPrivacy_Fields.cs | 8 ++++ .../Models/CCT/dbo/UserPrivacy_Settings.cs | 7 ++-- .../CCT/dbo/UserPrivacy_Visibility_Groups.cs | 8 ++++ .../Models/ViewModels/UserPrivacyViewModel.cs | 1 + Gordon360/Services/ProfileService.cs | 2 +- 10 files changed, 74 insertions(+), 26 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index 7ed4cac82..8e2f06760 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -17,23 +17,28 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; +using Gordon360.Models.CCT.Context; namespace Gordon360.Controllers { [Route("api/[controller]")] + [AllowAnonymous] public class ProfilesController : GordonControllerBase { private readonly IProfileService _profileService; private readonly IAccountService _accountService; private readonly IMembershipService _membershipService; private readonly IConfiguration _config; + private readonly CCTContext _context; - public ProfilesController(IProfileService profileService, IAccountService accountService, IMembershipService membershipService, IConfiguration config) + public ProfilesController(IProfileService profileService, IAccountService accountService, + IMembershipService membershipService, IConfiguration config, CCTContext context) { _profileService = profileService; _accountService = accountService; _membershipService = membershipService; _config = config; + _context = context; } /// Get profile info of currently logged in user @@ -64,9 +69,9 @@ public ProfilesController(IProfileService profileService, IAccountService accoun /// [HttpGet] [Route("{username}")] - public async Task> GetUserProfileAsync(string username) + public async Task> GetUserProfileAsync(string username,string tester) { - var viewerGroups = AuthUtils.GetGroups(User); + var viewerGroups = AuthUtils.GetGroups(tester); var _student = _profileService.GetStudentProfileByUsername(username); var _faculty = _profileService.GetFacultyStaffProfileByUsername(username); @@ -481,21 +486,36 @@ public async Task> UpdateOfficeHours( } /// - /// Update visibility of some piece of personal data for facstaff. + /// Set visibility of some piece of personal data for user. /// - /// Faculty Staff Privacy Decisions + /// Faculty Staff Privacy Decisions (see UserPrivacyViewModel) /// [HttpPut] - [Route("facstaff_privacy")] - [StateYourBusiness(operation = Operation.UPDATE, resource = Resource.PROFILE_PRIVACY)] - public async Task> UpdateUserPrivacyAsync(UserPrivacyViewModel facultyStaffPrivacy) + [Route("user_privacy")] + // [StateYourBusiness(operation = Operation.UPDATE, resource = Resource.PROFILE_PRIVACY)] + public async Task> UpdateUserPrivacyAsync(UserPrivacyViewModel userPrivacy,string authenticatedUserUsername) { - var authenticatedUserUsername = AuthUtils.GetUsername(User); - await _profileService.UpdateUserPrivacyAsync(authenticatedUserUsername, facultyStaffPrivacy); + //var authenticatedUserUsername = AuthUtils.GetUsername(User); + await _profileService.UpdateUserPrivacyAsync(authenticatedUserUsername, userPrivacy); return Ok(); } + /// + /// Return a list buildings. + /// + /// All buildings + [HttpGet] + [Route("visibility_group")] + public ActionResult> GetVisibilityGroup() + { + var groups = _context.UserPrivacy_Visibility_Groups.Select(fs => fs.Group) + .Distinct() + .Where(d => d != null) + .OrderBy(d => d); + return Ok(groups); + } + /// /// Update privacy of mobile phone number /// diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index f10c8bc3d..ef92c4442 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -234,7 +234,7 @@ - Return a list involvements. + Return a list of involvements' descriptions. All involvements @@ -593,7 +593,7 @@ Get profile info of currently logged in user - + Get public profile info for a user username of the profile info @@ -686,13 +686,19 @@ office hours - + - Update visibility of some piece of personal data for facstaff. + Set visibility of some piece of personal data for user. - Faculty Staff Privacy Decisions + Faculty Staff Privacy Decisions (see UserPrivacyViewModel) + + + Return a list buildings. + + All buildings + Update privacy of mobile phone number @@ -2390,7 +2396,7 @@ - privacy setting of home phone. + privacy setting of some piece of personal data for user. AD Username Faculty Staff Privacy View Model diff --git a/Gordon360/Models/CCT/Context/CCTContext.cs b/Gordon360/Models/CCT/Context/CCTContext.cs index e1da4c345..86480b979 100644 --- a/Gordon360/Models/CCT/Context/CCTContext.cs +++ b/Gordon360/Models/CCT/Context/CCTContext.cs @@ -735,21 +735,21 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { - entity.HasKey(e => e.Field) - .HasName("Field"); entity.Property(e => e.ID).ValueGeneratedOnAdd(); }); modelBuilder.Entity(entity => { + entity.HasKey(e => new { e.gordon_id, e.Field }); + entity.HasOne(d => d.FieldNavigation) - .WithMany() + .WithMany(p => p.UserPrivacy_Settings) .HasForeignKey(d => d.Field) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("FK_UserPrivacy_Settings_UserPrivacy_Fields"); entity.HasOne(d => d.VisibilityNavigation) - .WithMany() + .WithMany(p => p.UserPrivacy_Settings) .HasForeignKey(d => d.Visibility) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("FK_UserPrivacy_Settings_UserPrivacy_Visibility_Groups"); @@ -757,8 +757,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { - entity.HasKey(e => e.Group) - .HasName("Group"); entity.Property(e => e.ID).ValueGeneratedOnAdd(); }); diff --git a/Gordon360/Models/CCT/dbo/CUSTOM_PROFILE.cs b/Gordon360/Models/CCT/dbo/CUSTOM_PROFILE.cs index b95b2c0b2..4d7be810c 100644 --- a/Gordon360/Models/CCT/dbo/CUSTOM_PROFILE.cs +++ b/Gordon360/Models/CCT/dbo/CUSTOM_PROFILE.cs @@ -27,5 +27,8 @@ public partial class CUSTOM_PROFILE public string handshake { get; set; } [Unicode(false)] public string calendar { get; set; } + [StringLength(4)] + [Unicode(false)] + public string PlannedGradYear { get; set; } } } \ No newline at end of file diff --git a/Gordon360/Models/CCT/dbo/Student.cs b/Gordon360/Models/CCT/dbo/Student.cs index f77fe3842..3b5ef73b2 100644 --- a/Gordon360/Models/CCT/dbo/Student.cs +++ b/Gordon360/Models/CCT/dbo/Student.cs @@ -191,5 +191,8 @@ public partial class Student public string Mail_Location { get; set; } public int? ChapelRequired { get; set; } public int? ChapelAttended { get; set; } + [StringLength(4)] + [Unicode(false)] + public string PlannedGradYear { get; set; } } } \ No newline at end of file diff --git a/Gordon360/Models/CCT/dbo/UserPrivacy_Fields.cs b/Gordon360/Models/CCT/dbo/UserPrivacy_Fields.cs index ccf7036d8..733cd7a75 100644 --- a/Gordon360/Models/CCT/dbo/UserPrivacy_Fields.cs +++ b/Gordon360/Models/CCT/dbo/UserPrivacy_Fields.cs @@ -11,10 +11,18 @@ namespace Gordon360.Models.CCT [Table("UserPrivacy_Fields", Schema = "dbo")] public partial class UserPrivacy_Fields { + public UserPrivacy_Fields() + { + UserPrivacy_Settings = new HashSet(); + } + public int ID { get; set; } [Key] [StringLength(50)] [Unicode(false)] public string Field { get; set; } + + [InverseProperty("FieldNavigation")] + public virtual ICollection UserPrivacy_Settings { get; set; } } } \ No newline at end of file diff --git a/Gordon360/Models/CCT/dbo/UserPrivacy_Settings.cs b/Gordon360/Models/CCT/dbo/UserPrivacy_Settings.cs index 4bcdaf156..7cf3e2e78 100644 --- a/Gordon360/Models/CCT/dbo/UserPrivacy_Settings.cs +++ b/Gordon360/Models/CCT/dbo/UserPrivacy_Settings.cs @@ -8,15 +8,14 @@ namespace Gordon360.Models.CCT { - [Keyless] [Table("UserPrivacy_Settings", Schema = "dbo")] public partial class UserPrivacy_Settings { - [Required] + [Key] [StringLength(10)] [Unicode(false)] public string gordon_id { get; set; } - [Required] + [Key] [StringLength(50)] [Unicode(false)] public string Field { get; set; } @@ -26,8 +25,10 @@ public partial class UserPrivacy_Settings public string Visibility { get; set; } [ForeignKey("Field")] + [InverseProperty("UserPrivacy_Settings")] public virtual UserPrivacy_Fields FieldNavigation { get; set; } [ForeignKey("Visibility")] + [InverseProperty("UserPrivacy_Settings")] public virtual UserPrivacy_Visibility_Groups VisibilityNavigation { get; set; } } } \ No newline at end of file diff --git a/Gordon360/Models/CCT/dbo/UserPrivacy_Visibility_Groups.cs b/Gordon360/Models/CCT/dbo/UserPrivacy_Visibility_Groups.cs index b0485acf1..170000e68 100644 --- a/Gordon360/Models/CCT/dbo/UserPrivacy_Visibility_Groups.cs +++ b/Gordon360/Models/CCT/dbo/UserPrivacy_Visibility_Groups.cs @@ -11,10 +11,18 @@ namespace Gordon360.Models.CCT [Table("UserPrivacy_Visibility_Groups", Schema = "dbo")] public partial class UserPrivacy_Visibility_Groups { + public UserPrivacy_Visibility_Groups() + { + UserPrivacy_Settings = new HashSet(); + } + public int ID { get; set; } [Key] [StringLength(50)] [Unicode(false)] public string Group { get; set; } + + [InverseProperty("VisibilityNavigation")] + public virtual ICollection UserPrivacy_Settings { get; set; } } } \ No newline at end of file diff --git a/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs b/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs index 43c39787b..76e2b6a35 100644 --- a/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs +++ b/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs @@ -1,5 +1,6 @@ namespace Gordon360.Models.ViewModels { + // public class UserPrivacyViewModel { public string Field { get; set; } diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index c2592f2c4..be6f84beb 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -308,7 +308,7 @@ public async Task ToPublicFacultyStaffProfil } /// - /// privacy setting of home phone. + /// privacy setting of some piece of personal data for user. /// /// AD Username /// Faculty Staff Privacy View Model From f20b5530a09019a8b8c7f42fee5de995eb5fa591 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Fri, 7 Jul 2023 19:19:11 -0400 Subject: [PATCH 22/44] update comments for UserPrivacyViewModel.cs --- Gordon360/Models/ViewModels/UserPrivacyViewModel.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs b/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs index 76e2b6a35..fbe7fa549 100644 --- a/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs +++ b/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs @@ -1,6 +1,7 @@ namespace Gordon360.Models.ViewModels { - // + // Field: the field where the user wants to update the privacy setting (HomeCity, HomeState, HomeCountry, SpouseName, Country, HomePhone, MobilePhone) + // VisibilityGroup: the group that the user wants to be seen by (Public, Private, FacStaff) public class UserPrivacyViewModel { public string Field { get; set; } From b029f18b4b1746035972cb92edeb505676f45ac6 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Mon, 10 Jul 2023 17:25:25 -0400 Subject: [PATCH 23/44] adding get privacy setting --- Gordon360/Controllers/ProfilesController.cs | 18 ++++++++++++++++-- Gordon360/Documentation/Gordon360.xml | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index 8e2f06760..729440214 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -140,6 +140,20 @@ public async Task>> GetAdvisorsAsync( return Ok(advisors); } + ///Get the privacy settings of a particular user + /// + /// All privacy settings of the given user. + /// + [HttpGet] + [Route("privacy_setting/{username}")] + [StateYourBusiness(operation = Operation.READ_ONE, resource = Resource.PROFILE)] + public async Task>> GetPrivacySettingAsync(string username) + { + var privacy = await _profileService.GetPrivacySettingAsync(username); + + return Ok(privacy); + } + /// Gets the clifton strengths of a particular user /// The username for which to retrieve info /// Clifton strengths of the given user. @@ -493,9 +507,9 @@ public async Task> UpdateOfficeHours( [HttpPut] [Route("user_privacy")] // [StateYourBusiness(operation = Operation.UPDATE, resource = Resource.PROFILE_PRIVACY)] - public async Task> UpdateUserPrivacyAsync(UserPrivacyViewModel userPrivacy,string authenticatedUserUsername) + public async Task> UpdateUserPrivacyAsync(UserPrivacyViewModel userPrivacy) { - //var authenticatedUserUsername = AuthUtils.GetUsername(User); + var authenticatedUserUsername = AuthUtils.GetUsername(User); await _profileService.UpdateUserPrivacyAsync(authenticatedUserUsername, userPrivacy); return Ok(); diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index ef92c4442..296150b3f 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -686,7 +686,7 @@ office hours - + Set visibility of some piece of personal data for user. From 9339e463aeb318f373ca8f6297bfcb96910cd989 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Tue, 11 Jul 2023 08:58:01 -0400 Subject: [PATCH 24/44] working on get privacy setting --- Gordon360/Controllers/ProfilesController.cs | 4 +-- Gordon360/Documentation/Gordon360.xml | 13 ++++++++ .../Models/ViewModels/UserPrivacyViewModel.cs | 5 +++ Gordon360/Services/ProfileService.cs | 33 ++++++++++++++++++- Gordon360/Services/ServiceInterfaces.cs | 1 + 5 files changed, 53 insertions(+), 3 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index 729440214..c80e0fa6d 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -147,9 +147,9 @@ public async Task>> GetAdvisorsAsync( [HttpGet] [Route("privacy_setting/{username}")] [StateYourBusiness(operation = Operation.READ_ONE, resource = Resource.PROFILE)] - public async Task>> GetPrivacySettingAsync(string username) + public ActionResult> GetPrivacySettingAsync(string username) { - var privacy = await _profileService.GetPrivacySettingAsync(username); + var privacy = _profileService.GetPrivacySettingAsync(username); return Ok(privacy); } diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index 296150b3f..c77472c0b 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -605,6 +605,12 @@ provides first name, last name, and username. + + Get the privacy settings of a particular user + + All privacy settings of the given user. + + Gets the clifton strengths of a particular user The username for which to retrieve info @@ -2394,6 +2400,13 @@ + + + get privacy setting for particular user + + AD username + + privacy setting of some piece of personal data for user. diff --git a/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs b/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs index fbe7fa549..91559807d 100644 --- a/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs +++ b/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs @@ -4,6 +4,11 @@ // VisibilityGroup: the group that the user wants to be seen by (Public, Private, FacStaff) public class UserPrivacyViewModel { + public UserPrivacyViewModel(string field, string group) + { + Field = field; + VisibilityGroup = group; + } public string Field { get; set; } public string VisibilityGroup { get; set; } } diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index be6f84beb..97c4a0cbc 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -303,10 +303,41 @@ public async Task ToPublicFacultyStaffProfil else fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); } - + return publicFac; } + /// + /// get privacy setting for particular user + /// + /// AD username + /// + public IEnumerable GetPrivacySettingAsync(string username) + { + var account = _accountService.GetAccountByUsername(username); + + // select all privacy settings + var privacy = _context.UserPrivacy_Settings.Where(up_s => up_s.gordon_id == account.GordonID); + + if (privacy == null) + { + return null; + } + + List resultList = new(); + + foreach (UserPrivacy_Fields field in _context.UserPrivacy_Fields) + { + var row = privacy.FirstOrDefault(p => p.Field == field.Field); + if (row is UserPrivacy_Settings instance) + { + resultList.Add(new UserPrivacyViewModel(field.Field, instance.Visibility)); + } + } + + return resultList; + } + /// /// privacy setting of some piece of personal data for user. /// diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index f41dddfa3..dc346891a 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -29,6 +29,7 @@ public interface IProfileService DateTime GetBirthdate(string username); Task> GetAdvisorsAsync(string username); CliftonStrengthsViewModel? GetCliftonStrengths(int id); + IEnumerable GetPrivacySettingAsync(string username); Task ToggleCliftonStrengthsPrivacyAsync(int id); IEnumerable GetEmergencyContact(string username); ProfileCustomViewModel? GetCustomUserInfo(string username); From 8e5b4c89fa8a378df76f506a92b295a3053e047e Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Tue, 11 Jul 2023 10:54:25 -0400 Subject: [PATCH 25/44] distinguish Country and HomeCountry --- Gordon360/Models/ViewModels/ProfileViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gordon360/Models/ViewModels/ProfileViewModel.cs b/Gordon360/Models/ViewModels/ProfileViewModel.cs index 3fb144c03..3958dd19c 100644 --- a/Gordon360/Models/ViewModels/ProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/ProfileViewModel.cs @@ -17,7 +17,7 @@ public record ProfileViewModel( string HomeCity, string HomeState, string HomePostalCode, - string HomeCountry, + string HomeCountry, // Abbreviation of Country string HomePhone, string HomeFax, string AD_Username, From 6693a05684eb25e2ed742fbec03e70c7fe367050 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Wed, 12 Jul 2023 08:03:02 -0400 Subject: [PATCH 26/44] add comments and test for ToPublicProfileViewModel --- Gordon360/Controllers/ProfilesController.cs | 7 ++- Gordon360/Documentation/Gordon360.xml | 18 +++++++ .../Models/ViewModels/ProfileViewModel.cs | 2 +- .../PublicStudentProfileViewModel.cs | 5 -- Gordon360/Services/ProfileService.cs | 49 +++++++++++++++++-- Gordon360/Services/ServiceInterfaces.cs | 2 + 6 files changed, 69 insertions(+), 14 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index c80e0fa6d..7172de32b 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -69,7 +69,7 @@ public ProfilesController(IProfileService profileService, IAccountService accoun /// [HttpGet] [Route("{username}")] - public async Task> GetUserProfileAsync(string username,string tester) + public async Task> GetUserProfileAsync(string tester,string username) { var viewerGroups = AuthUtils.GetGroups(tester); @@ -81,7 +81,6 @@ public ProfilesController(IProfileService profileService, IAccountService accoun object? student = null; object? faculty = null; object? alumni = null; - if (viewerGroups.Contains(AuthGroup.SiteAdmin) || viewerGroups.Contains(AuthGroup.Police)) { @@ -98,7 +97,8 @@ public ProfilesController(IProfileService profileService, IAccountService accoun } else if (viewerGroups.Contains(AuthGroup.Student)) { - student = _student == null ? null : (PublicStudentProfileViewModel)_student; + student = _student == null ? null : + await _profileService.ToPublicStudentProfileViewModel(username, "stu", _student); faculty = _faculty == null ? null : await _profileService.ToPublicFacultyStaffProfileViewModel(username, "stu", _faculty); // If this student is also in Alumni AuthGroup, then s/he can see alumni's public profile; if not, return null. @@ -118,7 +118,6 @@ public ProfilesController(IProfileService profileService, IAccountService accoun { return Ok(null); } - var profile = _profileService.ComposeProfile(student, alumni, faculty, _customInfo); diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index c77472c0b..2cba0ff88 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -2400,6 +2400,24 @@ + + + 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/ProfileViewModel.cs b/Gordon360/Models/ViewModels/ProfileViewModel.cs index 3958dd19c..57abe2f7e 100644 --- a/Gordon360/Models/ViewModels/ProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/ProfileViewModel.cs @@ -30,6 +30,7 @@ public record ProfileViewModel( string Instagram, string LinkedIn, string Handshake, + string MobilePhone, // Student Only @@ -51,7 +52,6 @@ public record ProfileViewModel( string Minor3, string Minor3Description, string GradDate, - string MobilePhone, bool IsMobilePhonePrivate, int? ChapelRequired, int? ChapelAttended, diff --git a/Gordon360/Models/ViewModels/PublicStudentProfileViewModel.cs b/Gordon360/Models/ViewModels/PublicStudentProfileViewModel.cs index 866921067..f29ad3b1e 100644 --- a/Gordon360/Models/ViewModels/PublicStudentProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/PublicStudentProfileViewModel.cs @@ -72,12 +72,7 @@ public static implicit operator PublicStudentProfileViewModel(StudentProfileView Minor1Description = stu.Minor1Description ?? "", Minor2Description = stu.Minor2Description ?? "", Minor3Description = stu.Minor3Description ?? "" - }; - if (vm.IsMobilePhonePrivate) - { - vm.MobilePhone = "Private as requested."; - } if (vm.KeepPrivate.Contains("S")) { vm.HomeCity = "Private as requested."; diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 97c4a0cbc..4266e1dd9 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -283,10 +283,17 @@ public async Task UpdateProfileLinkAsync(string username, string type, CUSTOM_PR await _context.SaveChangesAsync(); } + /// + /// 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 async Task ToPublicFacultyStaffProfileViewModel (string username, string currentUserType, FacultyStaffProfileViewModel fac) { - PublicFacultyStaffProfileViewModel publicFac = (PublicFacultyStaffProfileViewModel) fac; + PublicFacultyStaffProfileViewModel publicFac = (PublicFacultyStaffProfileViewModel)fac; var account = _accountService.GetAccountByUsername(username); // select all privacy settings @@ -298,15 +305,49 @@ public async Task ToPublicFacultyStaffProfil { var row = privacy.FirstOrDefault(p => p.Field == field.Field); if (row is UserPrivacy_Settings instance) + { if (instance.Visibility == "Private" || (instance.Visibility == "FacStaff" && currentUserType != "fac")) - fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); - else - fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); + fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); + } + // else + // fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); } 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 async Task 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_Fields field in _context.UserPrivacy_Fields) + { + var row = privacy.FirstOrDefault(p => p.Field == field.Field); + Console.WriteLine(s_vm.GetProperty(field.Field)); + if (row is UserPrivacy_Settings instance) + if (instance.Visibility == "Private" || (instance.Visibility == "FacStaff" && currentUserType != "fac")) + s_vm.GetProperty(field.Field).SetValue(publicStu, ""); + else + s_vm.GetProperty(field.Field).SetValue(publicStu, ""); + } + + return publicStu; + } + /// /// get privacy setting for particular user /// diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index dc346891a..49471fb00 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -40,6 +40,8 @@ public interface IProfileService Task UpdateOfficeHoursAsync(string username, string newHours); Task ToPublicFacultyStaffProfileViewModel (string username, string currentUserType, FacultyStaffProfileViewModel fac); + Task ToPublicStudentProfileViewModel + (string username, string currentUserType, StudentProfileViewModel stu); Task UpdateUserPrivacyAsync(string username, UserPrivacyViewModel facultyStaffPrivacy); Task UpdateMobilePrivacyAsync(string username, string value); Task UpdateImagePrivacyAsync(string username, string value); From 517d5a6d69ab0d88d4d05db03d78d357ed60b279 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Thu, 13 Jul 2023 13:12:04 -0400 Subject: [PATCH 27/44] change async functions to not async functions --- Gordon360/Controllers/ProfilesController.cs | 10 +++---- Gordon360/Documentation/Gordon360.xml | 2 +- Gordon360/Services/ProfileService.cs | 32 +++++++++++++++------ Gordon360/Services/ServiceInterfaces.cs | 4 +-- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index 7172de32b..659320c19 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -69,9 +69,9 @@ public ProfilesController(IProfileService profileService, IAccountService accoun /// [HttpGet] [Route("{username}")] - public async Task> GetUserProfileAsync(string tester,string username) + public ActionResult GetUserProfileAsync(string username) { - var viewerGroups = AuthUtils.GetGroups(tester); + var viewerGroups = AuthUtils.GetGroups(User); var _student = _profileService.GetStudentProfileByUsername(username); var _faculty = _profileService.GetFacultyStaffProfileByUsername(username); @@ -98,9 +98,9 @@ public ProfilesController(IProfileService profileService, IAccountService accoun else if (viewerGroups.Contains(AuthGroup.Student)) { student = _student == null ? null : - await _profileService.ToPublicStudentProfileViewModel(username, "stu", _student); + _profileService.ToPublicStudentProfileViewModel(username, "stu", _student); faculty = _faculty == null ? null : - await _profileService.ToPublicFacultyStaffProfileViewModel(username, "stu", _faculty); + _profileService.ToPublicFacultyStaffProfileViewModel(username, "stu", _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) ? @@ -110,7 +110,7 @@ public ProfilesController(IProfileService profileService, IAccountService accoun { student = null; faculty = _faculty == null ? null : - await _profileService.ToPublicFacultyStaffProfileViewModel(username, "alu", _faculty); + _profileService.ToPublicFacultyStaffProfileViewModel(username, "alu", _faculty); alumni = _alumni == null ? null : (PublicAlumniProfileViewModel)_alumni; } diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index 2cba0ff88..f7a437985 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -593,7 +593,7 @@ Get profile info of currently logged in user - + Get public profile info for a user username of the profile info diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 4266e1dd9..7ac52c102 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -290,7 +290,7 @@ public async Task UpdateProfileLinkAsync(string username, string type, CUSTOM_PR /// 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 async Task ToPublicFacultyStaffProfileViewModel + public PublicFacultyStaffProfileViewModel ToPublicFacultyStaffProfileViewModel (string username, string currentUserType, FacultyStaffProfileViewModel fac) { PublicFacultyStaffProfileViewModel publicFac = (PublicFacultyStaffProfileViewModel)fac; @@ -307,10 +307,14 @@ public async Task ToPublicFacultyStaffProfil if (row is UserPrivacy_Settings instance) { if (instance.Visibility == "Private" || (instance.Visibility == "FacStaff" && currentUserType != "fac")) + { fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); + } + } + else + { + fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); } - // else - // fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); } return publicFac; @@ -323,7 +327,7 @@ public async Task ToPublicFacultyStaffProfil /// 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 async Task ToPublicStudentProfileViewModel + public PublicStudentProfileViewModel ToPublicStudentProfileViewModel (string username, string currentUserType, StudentProfileViewModel stu) { PublicStudentProfileViewModel publicStu = (PublicStudentProfileViewModel)stu; @@ -337,12 +341,22 @@ public async Task ToPublicStudentProfileViewModel foreach (UserPrivacy_Fields field in _context.UserPrivacy_Fields) { var row = privacy.FirstOrDefault(p => p.Field == field.Field); - Console.WriteLine(s_vm.GetProperty(field.Field)); - if (row is UserPrivacy_Settings instance) - if (instance.Visibility == "Private" || (instance.Visibility == "FacStaff" && currentUserType != "fac")) - s_vm.GetProperty(field.Field).SetValue(publicStu, ""); + // HomePhone and SpouseName fields are not for students + if (field.Field == "HomePhone" || field.Field == "SpouseName") { } else - s_vm.GetProperty(field.Field).SetValue(publicStu, ""); + { + if (row is UserPrivacy_Settings instance) + { + if (instance.Visibility == "Private" || (instance.Visibility == "FacStaff" && currentUserType != "fac")) + { + s_vm.GetProperty(field.Field).SetValue(publicStu, ""); + } + } + else + { + s_vm.GetProperty(field.Field).SetValue(publicStu, ""); + } + } } return publicStu; diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index 49471fb00..97c56f8af 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -38,9 +38,9 @@ public interface IProfileService Task UpdateMobilePhoneNumberAsync(string username, string newMobilePhoneNumber); Task UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom); Task UpdateOfficeHoursAsync(string username, string newHours); - Task ToPublicFacultyStaffProfileViewModel + PublicFacultyStaffProfileViewModel ToPublicFacultyStaffProfileViewModel (string username, string currentUserType, FacultyStaffProfileViewModel fac); - Task ToPublicStudentProfileViewModel + PublicStudentProfileViewModel ToPublicStudentProfileViewModel (string username, string currentUserType, StudentProfileViewModel stu); Task UpdateUserPrivacyAsync(string username, UserPrivacyViewModel facultyStaffPrivacy); Task UpdateMobilePrivacyAsync(string username, string value); From 0ad3c9c7e7d73b03bfeb3dceff1aa91ba394df87 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Fri, 14 Jul 2023 16:02:08 -0400 Subject: [PATCH 28/44] completed privacy setting for Home field --- Gordon360/Controllers/ProfilesController.cs | 9 ++++++++- Gordon360/Services/ProfileService.cs | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index 659320c19..63dbf3107 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -509,7 +509,14 @@ public async Task> UpdateOfficeHours( public async Task> UpdateUserPrivacyAsync(UserPrivacyViewModel userPrivacy) { var authenticatedUserUsername = AuthUtils.GetUsername(User); - await _profileService.UpdateUserPrivacyAsync(authenticatedUserUsername, userPrivacy); + // The privacy setting of some fields (such as HomeCountry and Country) are controlled by one button, + // so they are conbined and sent by one API request, and we need to split them here. + string[] subFields = userPrivacy.Field.Split(' '); + foreach (var subField in subFields) + { + userPrivacy.Field = subField; + await _profileService.UpdateUserPrivacyAsync(authenticatedUserUsername, userPrivacy); + } return Ok(); } diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 7ac52c102..5006aa6a6 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -308,12 +308,12 @@ public PublicFacultyStaffProfileViewModel ToPublicFacultyStaffProfileViewModel { if (instance.Visibility == "Private" || (instance.Visibility == "FacStaff" && currentUserType != "fac")) { - fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); + fs_vm.GetProperty(field.Field).SetValue(publicFac, "Private as requested."); } } else { - fs_vm.GetProperty(field.Field).SetValue(publicFac, ""); + fs_vm.GetProperty(field.Field).SetValue(publicFac, "Private as requested."); } } @@ -349,12 +349,12 @@ public PublicStudentProfileViewModel ToPublicStudentProfileViewModel { if (instance.Visibility == "Private" || (instance.Visibility == "FacStaff" && currentUserType != "fac")) { - s_vm.GetProperty(field.Field).SetValue(publicStu, ""); + s_vm.GetProperty(field.Field).SetValue(publicStu, "Private as requested."); } } else { - s_vm.GetProperty(field.Field).SetValue(publicStu, ""); + s_vm.GetProperty(field.Field).SetValue(publicStu, "Private as requested."); } } } From e666a499ab3cee1caf8ff3d4b597896192f7d83e Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Fri, 14 Jul 2023 16:13:27 -0400 Subject: [PATCH 29/44] cleaning up --- Gordon360/Controllers/ProfilesController.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index 63dbf3107..998c92236 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -22,7 +22,6 @@ namespace Gordon360.Controllers { [Route("api/[controller]")] - [AllowAnonymous] public class ProfilesController : GordonControllerBase { private readonly IProfileService _profileService; @@ -529,10 +528,10 @@ public async Task> UpdateUserPrivacyAsync(Use [Route("visibility_group")] public ActionResult> GetVisibilityGroup() { - var groups = _context.UserPrivacy_Visibility_Groups.Select(fs => fs.Group) + var groups = _context.UserPrivacy_Visibility_Groups.Select(up_v_g => up_v_g.Group) .Distinct() - .Where(d => d != null) - .OrderBy(d => d); + .Where(g => g != null) + .OrderBy(g => g); return Ok(groups); } From a48035b06908718ea3a2a869c80dbde0c2c4bccc Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Mon, 17 Jul 2023 17:22:29 -0400 Subject: [PATCH 30/44] simplify querying --- Gordon360/Services/ProfileService.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 5006aa6a6..f0688fe8d 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -352,10 +352,6 @@ public PublicStudentProfileViewModel ToPublicStudentProfileViewModel s_vm.GetProperty(field.Field).SetValue(publicStu, "Private as requested."); } } - else - { - s_vm.GetProperty(field.Field).SetValue(publicStu, "Private as requested."); - } } } @@ -381,13 +377,9 @@ public IEnumerable GetPrivacySettingAsync(string username) List resultList = new(); - foreach (UserPrivacy_Fields field in _context.UserPrivacy_Fields) + foreach (UserPrivacy_Settings row in privacy) { - var row = privacy.FirstOrDefault(p => p.Field == field.Field); - if (row is UserPrivacy_Settings instance) - { - resultList.Add(new UserPrivacyViewModel(field.Field, instance.Visibility)); - } + resultList.Add(new UserPrivacyViewModel(row.Field, row.Visibility)); } return resultList; From 5f5c062731f22fe0305ab084b7129b6a9a24adf2 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Mon, 17 Jul 2023 17:59:58 -0400 Subject: [PATCH 31/44] continue to simplify querying (GetPrivacySettingAsync) --- Gordon360/Services/ProfileService.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index f0688fe8d..fd1c77f81 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -338,20 +338,11 @@ public PublicStudentProfileViewModel ToPublicStudentProfileViewModel // get type of viewmodel for reflection property setting Type s_vm = new PublicStudentProfileViewModel().GetType(); - foreach (UserPrivacy_Fields field in _context.UserPrivacy_Fields) + foreach (UserPrivacy_Settings row in privacy) { - var row = privacy.FirstOrDefault(p => p.Field == field.Field); - // HomePhone and SpouseName fields are not for students - if (field.Field == "HomePhone" || field.Field == "SpouseName") { } - else + if (row.Visibility == "Private" || (row.Visibility == "FacStaff" && currentUserType != "fac")) { - if (row is UserPrivacy_Settings instance) - { - if (instance.Visibility == "Private" || (instance.Visibility == "FacStaff" && currentUserType != "fac")) - { - s_vm.GetProperty(field.Field).SetValue(publicStu, "Private as requested."); - } - } + s_vm.GetProperty(row.Field).SetValue(publicStu, "Private as requested."); } } From 4ad5dcec3f5fa743ded1f61e1af7213e7efd437b Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Thu, 20 Jul 2023 10:51:34 -0400 Subject: [PATCH 32/44] change the fields from strings to lists of strings --- Gordon360/Controllers/ProfilesController.cs | 16 ++------ Gordon360/Documentation/Gordon360.xml | 8 ++-- .../ViewModels/UserPrivacyGetViewModel.cs | 16 ++++++++ ...Model.cs => UserPrivacyUpdateViewModel.cs} | 10 +++-- Gordon360/Services/ProfileService.cs | 37 ++++++++++--------- Gordon360/Services/ServiceInterfaces.cs | 4 +- 6 files changed, 52 insertions(+), 39 deletions(-) create mode 100644 Gordon360/Models/ViewModels/UserPrivacyGetViewModel.cs rename Gordon360/Models/ViewModels/{UserPrivacyViewModel.cs => UserPrivacyUpdateViewModel.cs} (60%) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index 998c92236..f9c041c99 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -145,7 +145,7 @@ public async Task>> GetAdvisorsAsync( [HttpGet] [Route("privacy_setting/{username}")] [StateYourBusiness(operation = Operation.READ_ONE, resource = Resource.PROFILE)] - public ActionResult> GetPrivacySettingAsync(string username) + public ActionResult> GetPrivacySettingAsync(string username) { var privacy = _profileService.GetPrivacySettingAsync(username); @@ -500,23 +500,15 @@ public async Task> UpdateOfficeHours( /// /// Set visibility of some piece of personal data for user. /// - /// Faculty Staff Privacy Decisions (see UserPrivacyViewModel) + /// Faculty Staff Privacy Decisions (see UserPrivacyUpdateViewModel) /// [HttpPut] [Route("user_privacy")] // [StateYourBusiness(operation = Operation.UPDATE, resource = Resource.PROFILE_PRIVACY)] - public async Task> UpdateUserPrivacyAsync(UserPrivacyViewModel userPrivacy) + public async Task> UpdateUserPrivacyAsync(UserPrivacyUpdateViewModel userPrivacy) { var authenticatedUserUsername = AuthUtils.GetUsername(User); - // The privacy setting of some fields (such as HomeCountry and Country) are controlled by one button, - // so they are conbined and sent by one API request, and we need to split them here. - string[] subFields = userPrivacy.Field.Split(' '); - foreach (var subField in subFields) - { - userPrivacy.Field = subField; - await _profileService.UpdateUserPrivacyAsync(authenticatedUserUsername, userPrivacy); - } - + await _profileService.UpdateUserPrivacyAsync(authenticatedUserUsername, userPrivacy); return Ok(); } diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index f7a437985..fd48e5e10 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -692,11 +692,11 @@ office hours - + Set visibility of some piece of personal data for user. - Faculty Staff Privacy Decisions (see UserPrivacyViewModel) + Faculty Staff Privacy Decisions (see UserPrivacyUpdateViewModel) @@ -2423,9 +2423,9 @@ get privacy setting for particular user AD username - + all privacy setting of the particular user - + privacy setting of some piece of personal data for user. diff --git a/Gordon360/Models/ViewModels/UserPrivacyGetViewModel.cs b/Gordon360/Models/ViewModels/UserPrivacyGetViewModel.cs new file mode 100644 index 000000000..98c3bdcfd --- /dev/null +++ b/Gordon360/Models/ViewModels/UserPrivacyGetViewModel.cs @@ -0,0 +1,16 @@ +namespace Gordon360.Models.ViewModels +{ + // Field: the field where the user selected the privacy setting + // (HomeCity, HomeState, HomeCountry, SpouseName, Country, HomePhone, MobilePhone) + // VisibilityGroup: the group that the user wanted to be seen by (Public, Private, FacStaff) + public class UserPrivacyGetViewModel + { + public UserPrivacyGetViewModel(string field, string group) + { + Field = field; + VisibilityGroup = group; + } + public string Field { get; set; } + public string VisibilityGroup { get; set; } + } +} \ No newline at end of file diff --git a/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs b/Gordon360/Models/ViewModels/UserPrivacyUpdateViewModel.cs similarity index 60% rename from Gordon360/Models/ViewModels/UserPrivacyViewModel.cs rename to Gordon360/Models/ViewModels/UserPrivacyUpdateViewModel.cs index 91559807d..004d6e371 100644 --- a/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs +++ b/Gordon360/Models/ViewModels/UserPrivacyUpdateViewModel.cs @@ -1,15 +1,17 @@ -namespace Gordon360.Models.ViewModels +using System.Collections.Generic; + +namespace Gordon360.Models.ViewModels { // Field: the field where the user wants to update the privacy setting (HomeCity, HomeState, HomeCountry, SpouseName, Country, HomePhone, MobilePhone) // VisibilityGroup: the group that the user wants to be seen by (Public, Private, FacStaff) - public class UserPrivacyViewModel + public class UserPrivacyUpdateViewModel { - public UserPrivacyViewModel(string field, string group) + public UserPrivacyUpdateViewModel(IEnumerable field, string group) { Field = field; VisibilityGroup = group; } - public string Field { get; set; } + public IEnumerable Field { get; set; } public string VisibilityGroup { get; set; } } } \ No newline at end of file diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index fd1c77f81..7aa1cb01c 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -353,8 +353,8 @@ public PublicStudentProfileViewModel ToPublicStudentProfileViewModel /// get privacy setting for particular user /// /// AD username - /// - public IEnumerable GetPrivacySettingAsync(string username) + /// all privacy setting of the particular user + public IEnumerable GetPrivacySettingAsync(string username) { var account = _accountService.GetAccountByUsername(username); @@ -366,11 +366,11 @@ public IEnumerable GetPrivacySettingAsync(string username) return null; } - List resultList = new(); + List resultList = new(); foreach (UserPrivacy_Settings row in privacy) { - resultList.Add(new UserPrivacyViewModel(row.Field, row.Visibility)); + resultList.Add(new UserPrivacyGetViewModel(row.Field, row.Visibility)); } return resultList; @@ -381,23 +381,26 @@ public IEnumerable GetPrivacySettingAsync(string username) /// /// AD Username /// Faculty Staff Privacy View Model - public async Task UpdateUserPrivacyAsync(string username, UserPrivacyViewModel facultyStaffPrivacy) + public async Task UpdateUserPrivacyAsync(string username, UserPrivacyUpdateViewModel facultyStaffPrivacy) { var account = _accountService.GetAccountByUsername(username); - var facStaff = _context.UserPrivacy_Settings.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Field == facultyStaffPrivacy.Field); - if (facStaff is null) + foreach (string subField in facultyStaffPrivacy.Field) { - var privacy = new UserPrivacy_Settings + var facStaff = _context.UserPrivacy_Settings.FirstOrDefault(x => x.gordon_id == account.GordonID && x.Field == subField); + if (facStaff is null) { - gordon_id = account.GordonID, - Field = facultyStaffPrivacy.Field, - Visibility = facultyStaffPrivacy.VisibilityGroup - }; ; - await _context.UserPrivacy_Settings.AddAsync(privacy); - } - else - { - facStaff.Visibility = facultyStaffPrivacy.VisibilityGroup; + var privacy = new UserPrivacy_Settings + { + gordon_id = account.GordonID, + Field = subField, + Visibility = facultyStaffPrivacy.VisibilityGroup + }; ; + await _context.UserPrivacy_Settings.AddAsync(privacy); + } + else + { + facStaff.Visibility = facultyStaffPrivacy.VisibilityGroup; + } } _context.SaveChanges(); diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index 97c56f8af..240638e75 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -29,7 +29,7 @@ public interface IProfileService DateTime GetBirthdate(string username); Task> GetAdvisorsAsync(string username); CliftonStrengthsViewModel? GetCliftonStrengths(int id); - IEnumerable GetPrivacySettingAsync(string username); + IEnumerable GetPrivacySettingAsync(string username); Task ToggleCliftonStrengthsPrivacyAsync(int id); IEnumerable GetEmergencyContact(string username); ProfileCustomViewModel? GetCustomUserInfo(string username); @@ -42,7 +42,7 @@ PublicFacultyStaffProfileViewModel ToPublicFacultyStaffProfileViewModel (string username, string currentUserType, FacultyStaffProfileViewModel fac); PublicStudentProfileViewModel ToPublicStudentProfileViewModel (string username, string currentUserType, StudentProfileViewModel stu); - Task UpdateUserPrivacyAsync(string username, UserPrivacyViewModel facultyStaffPrivacy); + Task UpdateUserPrivacyAsync(string username, UserPrivacyUpdateViewModel facultyStaffPrivacy); Task UpdateMobilePrivacyAsync(string username, string value); Task UpdateImagePrivacyAsync(string username, string value); Task UpdateProfileImageAsync(string username, string path, string name); From d44a44e91a823799cc6b928a46b61fbd87365c22 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Thu, 20 Jul 2023 15:59:51 -0400 Subject: [PATCH 33/44] using implicitly cast --- .../Models/ViewModels/UserPrivacyViewModel.cs | 27 +++++++++++++++++++ Gordon360/Services/ProfileService.cs | 17 ++++++------ Gordon360/Services/ServiceInterfaces.cs | 2 +- 3 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 Gordon360/Models/ViewModels/UserPrivacyViewModel.cs diff --git a/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs b/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs new file mode 100644 index 000000000..49c656435 --- /dev/null +++ b/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs @@ -0,0 +1,27 @@ +using Gordon360.Models.CCT; +using Gordon360.Models.ViewModels.RecIM; + +namespace Gordon360.Models.ViewModels +{ + // Field: the field where the user selected the privacy setting + // (HomeCity, HomeState, HomeCountry, SpouseName, Country, HomePhone, MobilePhone) + // VisibilityGroup: the group that the user wanted to be seen by (Public, Private, FacStaff) + public class UserPrivacyViewModel + { + //public UserPrivacyViewModel(string field, string group) + //{ + // Field = field; + // VisibilityGroup = group; + //} + public string Field { get; set; } + public string VisibilityGroup { get; set; } + public static implicit operator UserPrivacyViewModel(UserPrivacy_Settings up_s) + { + return new UserPrivacyViewModel + { + Field = up_s.Field, + VisibilityGroup = up_s.Visibility + }; + } + } +} \ No newline at end of file diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 7aa1cb01c..30beddd41 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -354,26 +354,27 @@ public PublicStudentProfileViewModel ToPublicStudentProfileViewModel /// /// AD username /// all privacy setting of the particular user - public IEnumerable GetPrivacySettingAsync(string username) + public IEnumerable GetPrivacySettingAsync(string username) { var account = _accountService.GetAccountByUsername(username); // select all privacy settings - var privacy = _context.UserPrivacy_Settings.Where(up_s => up_s.gordon_id == account.GordonID); + var privacy = _context.UserPrivacy_Settings.Where(up_s => up_s.gordon_id == account.GordonID).Select(up_s => (UserPrivacyViewModel) up_s); if (privacy == null) { return null; } - List resultList = new(); + return privacy; + //List resultList = new(); - foreach (UserPrivacy_Settings row in privacy) - { - resultList.Add(new UserPrivacyGetViewModel(row.Field, row.Visibility)); - } + //foreach (UserPrivacy_Settings row in privacy) + //{ + // resultList.Add(new UserPrivacyViewModel(row.Field, row.Visibility)); + //} - return resultList; + //return resultList; } /// diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index 240638e75..824d32ea3 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -29,7 +29,7 @@ public interface IProfileService DateTime GetBirthdate(string username); Task> GetAdvisorsAsync(string username); CliftonStrengthsViewModel? GetCliftonStrengths(int id); - IEnumerable GetPrivacySettingAsync(string username); + IEnumerable GetPrivacySettingAsync(string username); Task ToggleCliftonStrengthsPrivacyAsync(int id); IEnumerable GetEmergencyContact(string username); ProfileCustomViewModel? GetCustomUserInfo(string username); From ca65e188463064434d67d2845f361697f470ca77 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Thu, 20 Jul 2023 16:03:01 -0400 Subject: [PATCH 34/44] remove unused comments --- Gordon360/Models/ViewModels/UserPrivacyViewModel.cs | 5 ----- Gordon360/Services/ProfileService.cs | 8 -------- 2 files changed, 13 deletions(-) diff --git a/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs b/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs index 49c656435..989bb3ed9 100644 --- a/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs +++ b/Gordon360/Models/ViewModels/UserPrivacyViewModel.cs @@ -8,11 +8,6 @@ namespace Gordon360.Models.ViewModels // VisibilityGroup: the group that the user wanted to be seen by (Public, Private, FacStaff) public class UserPrivacyViewModel { - //public UserPrivacyViewModel(string field, string group) - //{ - // Field = field; - // VisibilityGroup = group; - //} public string Field { get; set; } public string VisibilityGroup { get; set; } public static implicit operator UserPrivacyViewModel(UserPrivacy_Settings up_s) diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 30beddd41..f344e5638 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -367,14 +367,6 @@ public IEnumerable GetPrivacySettingAsync(string username) } return privacy; - //List resultList = new(); - - //foreach (UserPrivacy_Settings row in privacy) - //{ - // resultList.Add(new UserPrivacyViewModel(row.Field, row.Visibility)); - //} - - //return resultList; } /// From ede49170e4c050752886d029571b093218b398d7 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Fri, 21 Jul 2023 09:18:35 -0400 Subject: [PATCH 35/44] continue to clean up code --- Gordon360/Services/ProfileService.cs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index f344e5638..3463a382f 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -301,19 +301,11 @@ public PublicFacultyStaffProfileViewModel ToPublicFacultyStaffProfileViewModel // get type of viewmodel for reflection property setting Type fs_vm = new PublicFacultyStaffProfileViewModel().GetType(); - foreach (UserPrivacy_Fields field in _context.UserPrivacy_Fields) + foreach (UserPrivacy_Settings row in privacy) { - var row = privacy.FirstOrDefault(p => p.Field == field.Field); - if (row is UserPrivacy_Settings instance) - { - if (instance.Visibility == "Private" || (instance.Visibility == "FacStaff" && currentUserType != "fac")) - { - fs_vm.GetProperty(field.Field).SetValue(publicFac, "Private as requested."); - } - } - else + if (row.Visibility == "Private" || (row.Visibility == "FacStaff" && currentUserType != "fac")) { - fs_vm.GetProperty(field.Field).SetValue(publicFac, "Private as requested."); + fs_vm.GetProperty(row.Field).SetValue(publicFac, "Private as requested."); } } From 5f9c2ca1d07af643f49671c6fa5152c705c39e00 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Fri, 21 Jul 2023 09:37:01 -0400 Subject: [PATCH 36/44] changing comments --- Gordon360/Controllers/ProfilesController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index ce3759925..08c13ea2b 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -516,9 +516,9 @@ public async Task> UpdateUserPrivacyAsy } /// - /// Return a list buildings. + /// Return a list visibility groups. /// - /// All buildings + /// All visibility groups (Public, FacStaff, Private) [HttpGet] [Route("visibility_group")] public ActionResult> GetVisibilityGroup() From 416c1e15d8fc65503cb7b587a50083d770c8c493 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Fri, 21 Jul 2023 13:19:17 -0400 Subject: [PATCH 37/44] add HomePhone for student in public profile --- Gordon360/Documentation/Gordon360.xml | 17 +++++++++++++++-- .../ViewModels/PublicStudentProfileViewModel.cs | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index bfb65ff77..560f2671b 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -694,9 +694,9 @@ - Return a list buildings. + Return a list visibility groups. - All buildings + All visibility groups (Public, FacStaff, Private) @@ -1235,6 +1235,12 @@ A IEnumerable of schedule objects + + + Gets all session objects for a user + + A IEnumerable of session objects as well as the schedules + Get whether the currently logged-in user can read student schedules @@ -2601,6 +2607,13 @@ The selected session of the instructor StudentScheduleViewModel if found, null if not found + + + Fetch the session item whose id specified by the parameter + + The AD Username of the user + SessionCoursesViewModel if found, null if not found + Service class to facilitate data transactions between the Controller and the database model. diff --git a/Gordon360/Models/ViewModels/PublicStudentProfileViewModel.cs b/Gordon360/Models/ViewModels/PublicStudentProfileViewModel.cs index f29ad3b1e..a2badd381 100644 --- a/Gordon360/Models/ViewModels/PublicStudentProfileViewModel.cs +++ b/Gordon360/Models/ViewModels/PublicStudentProfileViewModel.cs @@ -24,6 +24,7 @@ public class PublicStudentProfileViewModel public string Gender { get; set; } public string grad_student { get; set; } public string MobilePhone { get; set; } + public string HomePhone { get; set; } public string AD_Username { get; set; } public bool IsMobilePhonePrivate { get; set; } public Nullable show_pic { get; set; } @@ -63,6 +64,7 @@ public static implicit operator PublicStudentProfileViewModel(StudentProfileView Gender = stu.Gender ?? "", IsMobilePhonePrivate = stu.IsMobilePhonePrivate, MobilePhone = stu.MobilePhone ?? "", + HomePhone = stu.HomePhone ?? "", show_pic = stu.show_pic, preferred_photo = stu.preferred_photo, Country = stu.Country ?? "", From 32128b81d82ff37cec1b53a8b45da429d31a98d3 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Fri, 21 Jul 2023 15:51:27 -0400 Subject: [PATCH 38/44] remove unnecessary lines --- Gordon360/Services/ProfileService.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Gordon360/Services/ProfileService.cs b/Gordon360/Services/ProfileService.cs index 6a8f4dea4..728b062b0 100644 --- a/Gordon360/Services/ProfileService.cs +++ b/Gordon360/Services/ProfileService.cs @@ -353,11 +353,6 @@ public IEnumerable GetPrivacySettingAsync(string username) // select all privacy settings var privacy = _context.UserPrivacy_Settings.Where(up_s => up_s.gordon_id == account.GordonID).Select(up_s => (UserPrivacyViewModel) up_s); - if (privacy == null) - { - return null; - } - return privacy; } From 1342930eb4f66ff4252ae513ad3b2faa6300771a Mon Sep 17 00:00:00 2001 From: Wenlan Ji <78650688+ArabellaJi@users.noreply.github.com> Date: Fri, 11 Aug 2023 19:22:52 -0400 Subject: [PATCH 39/44] fix minor spelling issue --- Gordon360/Static Classes/Names.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gordon360/Static Classes/Names.cs b/Gordon360/Static Classes/Names.cs index 73e99a57a..f6cb04c06 100644 --- a/Gordon360/Static Classes/Names.cs +++ b/Gordon360/Static Classes/Names.cs @@ -6,7 +6,7 @@ public static class Resource { public const string EMERGENCY_CONTACT = "A new emergency contact resource"; public const string PROFILE = "A new profile resource"; - public const string PROFILE_PRIVACY = "A individual's specific profile privacy resrouce"; + public const string PROFILE_PRIVACY = "A individual's specific profile privacy resource"; public const string MEMBERSHIP_REQUEST = "A Membership Request Resource"; public const string MEMBERSHIP = "A Membership Resource"; public const string MEMBERSHIP_PRIVACY = "A Membership privacy"; From 414263c7d336ff1e0b4ac3fe55962cc29430293c Mon Sep 17 00:00:00 2001 From: Wenlan Ji <78650688+ArabellaJi@users.noreply.github.com> Date: Fri, 11 Aug 2023 19:29:59 -0400 Subject: [PATCH 40/44] change the order of parameters and add a comment --- Gordon360/Controllers/ProfilesController.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Gordon360/Controllers/ProfilesController.cs b/Gordon360/Controllers/ProfilesController.cs index 4b70ecea9..e8fb0d022 100644 --- a/Gordon360/Controllers/ProfilesController.cs +++ b/Gordon360/Controllers/ProfilesController.cs @@ -32,15 +32,16 @@ public class ProfilesController : GordonControllerBase private readonly webSQLContext _webSQLContext; private readonly CCTContext _context; + /// constructor of ProfilesController public ProfilesController(IProfileService profileService, IAccountService accountService, - IMembershipService membershipService, IConfiguration config, CCTContext context, webSQLContext webSQLContext) + IMembershipService membershipService, IConfiguration config, webSQLContext webSQLContext, CCTContext context) { _profileService = profileService; _accountService = accountService; _membershipService = membershipService; _config = config; - _context = context; _webSQLContext = webSQLContext; + _context = context; } /// Get profile info of currently logged in user From 1210ca0940bd8d7452bba5538d839bb0c27c29ec Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Wed, 4 Oct 2023 22:33:31 -0400 Subject: [PATCH 41/44] initial add roommate completed --- Gordon360/Controllers/HousingController.cs | 14 +++++++++++ Gordon360/Documentation/Gordon360.xml | 13 ++++++++++ Gordon360/Models/CCT/Context/CCTContext.cs | 16 ++++++++++++ .../Models/CCT/Context/efpt.CCT.config.json | 4 +++ Gordon360/Models/CCT/Housing/Roommate.cs | 25 +++++++++++++++++++ Gordon360/Services/HousingService.cs | 25 +++++++++++++++++++ Gordon360/Services/ServiceInterfaces.cs | 1 + 7 files changed, 98 insertions(+) create mode 100644 Gordon360/Models/CCT/Housing/Roommate.cs diff --git a/Gordon360/Controllers/HousingController.cs b/Gordon360/Controllers/HousingController.cs index 48685d428..cb04cf562 100644 --- a/Gordon360/Controllers/HousingController.cs +++ b/Gordon360/Controllers/HousingController.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Security.Claims; +using System.Threading.Tasks; namespace Gordon360.Controllers { @@ -243,5 +244,18 @@ public ActionResult GetAllApartmentApplication( return NotFound(); } } + + /// + /// Update roommate information + /// + /// + [HttpPut] + [Route("housing_lottery/{roommate}")] + public async Task> UpdateRoommate(string roommate) + { + var username = AuthUtils.GetUsername(User); + await _housingService.UpdateRoommateAsync(username, roommate); + return Ok(); + } } } diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index 560f2671b..0cb376b0d 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -322,6 +322,12 @@ Get apartment application info for all applications if the current user is a housing admin Object of type ApartmentApplicationViewModel + + + Update roommate information + + + Get a user's active jobs @@ -2011,6 +2017,13 @@ The application ID number of the application to be submitted Returns whether the query succeeded + + + roommate imformation setting + + The username for the user who complete the aplication form + The name of the selected roommate + Service Class that facilitates data transactions between the JobsController and the student_timesheets + paid_shifts database model. diff --git a/Gordon360/Models/CCT/Context/CCTContext.cs b/Gordon360/Models/CCT/Context/CCTContext.cs index 86480b979..dee26868a 100644 --- a/Gordon360/Models/CCT/Context/CCTContext.cs +++ b/Gordon360/Models/CCT/Context/CCTContext.cs @@ -83,6 +83,7 @@ public CCTContext(DbContextOptions options) public virtual DbSet RequestView { get; set; } public virtual DbSet RoleType { get; set; } public virtual DbSet RoomAssign { get; set; } + public virtual DbSet Roommate { get; set; } public virtual DbSet Rooms { get; set; } public virtual DbSet Save_Bookings { get; set; } public virtual DbSet Save_Rides { get; set; } @@ -512,7 +513,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { + entity.Property(e => e.AllowEmails).HasDefaultValueSql("((1))"); + entity.Property(e => e.ID).ValueGeneratedOnAdd(); + + entity.Property(e => e.SpecifiedGender).IsFixedLength(); }); modelBuilder.Entity(entity => @@ -622,6 +627,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(e => e.SESS_CDE).IsFixedLength(); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.ID, e.RoommateName }) + .HasName("PK__Roommate__A9AF9368B01FE07C"); + }); + modelBuilder.Entity(entity => { entity.HasKey(e => new { e.ID, e.rideID }); @@ -662,6 +673,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasForeignKey(d => d.TypeID) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("FK_Series_SeriesType"); + + entity.HasOne(d => d.Winner) + .WithMany(p => p.Series) + .HasForeignKey(d => d.WinnerID) + .HasConstraintName("FK_Series_Team"); }); modelBuilder.Entity(entity => diff --git a/Gordon360/Models/CCT/Context/efpt.CCT.config.json b/Gordon360/Models/CCT/Context/efpt.CCT.config.json index 623db5d0b..79f89e98b 100644 --- a/Gordon360/Models/CCT/Context/efpt.CCT.config.json +++ b/Gordon360/Models/CCT/Context/efpt.CCT.config.json @@ -146,6 +146,10 @@ "Name": "[dbo].[Users]", "ObjectType": 0 }, + { + "Name": "[Housing].[Roommate]", + "ObjectType": 0 + }, { "Name": "[RecIM].[Activity]", "ObjectType": 0 diff --git a/Gordon360/Models/CCT/Housing/Roommate.cs b/Gordon360/Models/CCT/Housing/Roommate.cs new file mode 100644 index 000000000..162e69325 --- /dev/null +++ b/Gordon360/Models/CCT/Housing/Roommate.cs @@ -0,0 +1,25 @@ +// This file has been auto generated by EF Core Power Tools. +#nullable disable +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; + +namespace Gordon360.Models.CCT +{ + [Table("Roommate", Schema = "Housing")] + public partial class Roommate + { + [Key] + public int ID { get; set; } + [Required] + [StringLength(128)] + [Unicode(false)] + public string Name { get; set; } + [Key] + [StringLength(128)] + [Unicode(false)] + public string RoommateName { get; set; } + } +} \ No newline at end of file diff --git a/Gordon360/Services/HousingService.cs b/Gordon360/Services/HousingService.cs index 4bdce8780..7c6c1b1c7 100644 --- a/Gordon360/Services/HousingService.cs +++ b/Gordon360/Services/HousingService.cs @@ -9,6 +9,8 @@ using Gordon360.Enums; using Gordon360.Static.Methods; using Microsoft.EntityFrameworkCore; +using Gordon360.Models.webSQL.Context; +using System.Threading.Tasks; namespace Gordon360.Services { @@ -537,5 +539,28 @@ public bool ChangeApplicationDateSubmitted(int applicationID) _context.SaveChanges(); return true; } + + /// + /// roommate imformation setting + /// + /// The username for the user who complete the aplication form + /// The name of the selected roommate + public async Task UpdateRoommateAsync(string username, string roommate_name) + { + var GordonID = _context.ACCOUNT.FirstOrDefault(a => a.AD_Username == username)?.gordon_id; + if (GordonID == null) + { + throw new ResourceNotFoundException() { ExceptionMessage = "The applicant could not be found" }; + } + var newRoommate = new Roommate + { + ID = int.Parse(GordonID), + Name = username, + RoommateName = roommate_name + }; ; + await _context.Roommate.AddAsync(newRoommate); + + _context.SaveChanges(); + } } } diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index a67678b3b..e13171019 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -308,6 +308,7 @@ public interface IHousingService int EditApplication(string username, string sess_cde, int applicationID, string newEditorUsername, List newApartmentApplicants, List newApartmentChoices); bool ChangeApplicationEditor(string username, int applicationID, string newEditorUsername); bool ChangeApplicationDateSubmitted(int applicationID); + Task UpdateRoommateAsync(string username, string roommate_name); } public interface IAcademicCheckInService From 8d8ab77188f8b086d864c4617dde8a5ab9499325 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Wed, 4 Oct 2023 22:39:56 -0400 Subject: [PATCH 42/44] Revert "initial add roommate completed" This reverts commit 1210ca0940bd8d7452bba5538d839bb0c27c29ec. --- Gordon360/Controllers/HousingController.cs | 14 ----------- Gordon360/Documentation/Gordon360.xml | 13 ---------- Gordon360/Models/CCT/Context/CCTContext.cs | 16 ------------ .../Models/CCT/Context/efpt.CCT.config.json | 4 --- Gordon360/Models/CCT/Housing/Roommate.cs | 25 ------------------- Gordon360/Services/HousingService.cs | 25 ------------------- Gordon360/Services/ServiceInterfaces.cs | 1 - 7 files changed, 98 deletions(-) delete mode 100644 Gordon360/Models/CCT/Housing/Roommate.cs diff --git a/Gordon360/Controllers/HousingController.cs b/Gordon360/Controllers/HousingController.cs index cb04cf562..48685d428 100644 --- a/Gordon360/Controllers/HousingController.cs +++ b/Gordon360/Controllers/HousingController.cs @@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Security.Claims; -using System.Threading.Tasks; namespace Gordon360.Controllers { @@ -244,18 +243,5 @@ public ActionResult GetAllApartmentApplication( return NotFound(); } } - - /// - /// Update roommate information - /// - /// - [HttpPut] - [Route("housing_lottery/{roommate}")] - public async Task> UpdateRoommate(string roommate) - { - var username = AuthUtils.GetUsername(User); - await _housingService.UpdateRoommateAsync(username, roommate); - return Ok(); - } } } diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index 0cb376b0d..560f2671b 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -322,12 +322,6 @@ Get apartment application info for all applications if the current user is a housing admin Object of type ApartmentApplicationViewModel - - - Update roommate information - - - Get a user's active jobs @@ -2017,13 +2011,6 @@ The application ID number of the application to be submitted Returns whether the query succeeded - - - roommate imformation setting - - The username for the user who complete the aplication form - The name of the selected roommate - Service Class that facilitates data transactions between the JobsController and the student_timesheets + paid_shifts database model. diff --git a/Gordon360/Models/CCT/Context/CCTContext.cs b/Gordon360/Models/CCT/Context/CCTContext.cs index dee26868a..86480b979 100644 --- a/Gordon360/Models/CCT/Context/CCTContext.cs +++ b/Gordon360/Models/CCT/Context/CCTContext.cs @@ -83,7 +83,6 @@ public CCTContext(DbContextOptions options) public virtual DbSet RequestView { get; set; } public virtual DbSet RoleType { get; set; } public virtual DbSet RoomAssign { get; set; } - public virtual DbSet Roommate { get; set; } public virtual DbSet Rooms { get; set; } public virtual DbSet Save_Bookings { get; set; } public virtual DbSet Save_Rides { get; set; } @@ -513,11 +512,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { - entity.Property(e => e.AllowEmails).HasDefaultValueSql("((1))"); - entity.Property(e => e.ID).ValueGeneratedOnAdd(); - - entity.Property(e => e.SpecifiedGender).IsFixedLength(); }); modelBuilder.Entity(entity => @@ -627,12 +622,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(e => e.SESS_CDE).IsFixedLength(); }); - modelBuilder.Entity(entity => - { - entity.HasKey(e => new { e.ID, e.RoommateName }) - .HasName("PK__Roommate__A9AF9368B01FE07C"); - }); - modelBuilder.Entity(entity => { entity.HasKey(e => new { e.ID, e.rideID }); @@ -673,11 +662,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasForeignKey(d => d.TypeID) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("FK_Series_SeriesType"); - - entity.HasOne(d => d.Winner) - .WithMany(p => p.Series) - .HasForeignKey(d => d.WinnerID) - .HasConstraintName("FK_Series_Team"); }); modelBuilder.Entity(entity => diff --git a/Gordon360/Models/CCT/Context/efpt.CCT.config.json b/Gordon360/Models/CCT/Context/efpt.CCT.config.json index 79f89e98b..623db5d0b 100644 --- a/Gordon360/Models/CCT/Context/efpt.CCT.config.json +++ b/Gordon360/Models/CCT/Context/efpt.CCT.config.json @@ -146,10 +146,6 @@ "Name": "[dbo].[Users]", "ObjectType": 0 }, - { - "Name": "[Housing].[Roommate]", - "ObjectType": 0 - }, { "Name": "[RecIM].[Activity]", "ObjectType": 0 diff --git a/Gordon360/Models/CCT/Housing/Roommate.cs b/Gordon360/Models/CCT/Housing/Roommate.cs deleted file mode 100644 index 162e69325..000000000 --- a/Gordon360/Models/CCT/Housing/Roommate.cs +++ /dev/null @@ -1,25 +0,0 @@ -// This file has been auto generated by EF Core Power Tools. -#nullable disable -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using Microsoft.EntityFrameworkCore; - -namespace Gordon360.Models.CCT -{ - [Table("Roommate", Schema = "Housing")] - public partial class Roommate - { - [Key] - public int ID { get; set; } - [Required] - [StringLength(128)] - [Unicode(false)] - public string Name { get; set; } - [Key] - [StringLength(128)] - [Unicode(false)] - public string RoommateName { get; set; } - } -} \ No newline at end of file diff --git a/Gordon360/Services/HousingService.cs b/Gordon360/Services/HousingService.cs index 7c6c1b1c7..4bdce8780 100644 --- a/Gordon360/Services/HousingService.cs +++ b/Gordon360/Services/HousingService.cs @@ -9,8 +9,6 @@ using Gordon360.Enums; using Gordon360.Static.Methods; using Microsoft.EntityFrameworkCore; -using Gordon360.Models.webSQL.Context; -using System.Threading.Tasks; namespace Gordon360.Services { @@ -539,28 +537,5 @@ public bool ChangeApplicationDateSubmitted(int applicationID) _context.SaveChanges(); return true; } - - /// - /// roommate imformation setting - /// - /// The username for the user who complete the aplication form - /// The name of the selected roommate - public async Task UpdateRoommateAsync(string username, string roommate_name) - { - var GordonID = _context.ACCOUNT.FirstOrDefault(a => a.AD_Username == username)?.gordon_id; - if (GordonID == null) - { - throw new ResourceNotFoundException() { ExceptionMessage = "The applicant could not be found" }; - } - var newRoommate = new Roommate - { - ID = int.Parse(GordonID), - Name = username, - RoommateName = roommate_name - }; ; - await _context.Roommate.AddAsync(newRoommate); - - _context.SaveChanges(); - } } } diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index e13171019..a67678b3b 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -308,7 +308,6 @@ public interface IHousingService int EditApplication(string username, string sess_cde, int applicationID, string newEditorUsername, List newApartmentApplicants, List newApartmentChoices); bool ChangeApplicationEditor(string username, int applicationID, string newEditorUsername); bool ChangeApplicationDateSubmitted(int applicationID); - Task UpdateRoommateAsync(string username, string roommate_name); } public interface IAcademicCheckInService From 5979e60761643aab8c870bc3b1a3da95d7888520 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Wed, 4 Oct 2023 22:42:18 -0400 Subject: [PATCH 43/44] Revert "Revert "initial add roommate completed"" This reverts commit 8d8ab77188f8b086d864c4617dde8a5ab9499325. --- Gordon360/Controllers/HousingController.cs | 14 +++++++++++ Gordon360/Documentation/Gordon360.xml | 13 ++++++++++ Gordon360/Models/CCT/Context/CCTContext.cs | 16 ++++++++++++ .../Models/CCT/Context/efpt.CCT.config.json | 4 +++ Gordon360/Models/CCT/Housing/Roommate.cs | 25 +++++++++++++++++++ Gordon360/Services/HousingService.cs | 25 +++++++++++++++++++ Gordon360/Services/ServiceInterfaces.cs | 1 + 7 files changed, 98 insertions(+) create mode 100644 Gordon360/Models/CCT/Housing/Roommate.cs diff --git a/Gordon360/Controllers/HousingController.cs b/Gordon360/Controllers/HousingController.cs index 48685d428..cb04cf562 100644 --- a/Gordon360/Controllers/HousingController.cs +++ b/Gordon360/Controllers/HousingController.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Security.Claims; +using System.Threading.Tasks; namespace Gordon360.Controllers { @@ -243,5 +244,18 @@ public ActionResult GetAllApartmentApplication( return NotFound(); } } + + /// + /// Update roommate information + /// + /// + [HttpPut] + [Route("housing_lottery/{roommate}")] + public async Task> UpdateRoommate(string roommate) + { + var username = AuthUtils.GetUsername(User); + await _housingService.UpdateRoommateAsync(username, roommate); + return Ok(); + } } } diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index 560f2671b..0cb376b0d 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -322,6 +322,12 @@ Get apartment application info for all applications if the current user is a housing admin Object of type ApartmentApplicationViewModel + + + Update roommate information + + + Get a user's active jobs @@ -2011,6 +2017,13 @@ The application ID number of the application to be submitted Returns whether the query succeeded + + + roommate imformation setting + + The username for the user who complete the aplication form + The name of the selected roommate + Service Class that facilitates data transactions between the JobsController and the student_timesheets + paid_shifts database model. diff --git a/Gordon360/Models/CCT/Context/CCTContext.cs b/Gordon360/Models/CCT/Context/CCTContext.cs index 86480b979..dee26868a 100644 --- a/Gordon360/Models/CCT/Context/CCTContext.cs +++ b/Gordon360/Models/CCT/Context/CCTContext.cs @@ -83,6 +83,7 @@ public CCTContext(DbContextOptions options) public virtual DbSet RequestView { get; set; } public virtual DbSet RoleType { get; set; } public virtual DbSet RoomAssign { get; set; } + public virtual DbSet Roommate { get; set; } public virtual DbSet Rooms { get; set; } public virtual DbSet Save_Bookings { get; set; } public virtual DbSet Save_Rides { get; set; } @@ -512,7 +513,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { + entity.Property(e => e.AllowEmails).HasDefaultValueSql("((1))"); + entity.Property(e => e.ID).ValueGeneratedOnAdd(); + + entity.Property(e => e.SpecifiedGender).IsFixedLength(); }); modelBuilder.Entity(entity => @@ -622,6 +627,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(e => e.SESS_CDE).IsFixedLength(); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.ID, e.RoommateName }) + .HasName("PK__Roommate__A9AF9368B01FE07C"); + }); + modelBuilder.Entity(entity => { entity.HasKey(e => new { e.ID, e.rideID }); @@ -662,6 +673,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasForeignKey(d => d.TypeID) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("FK_Series_SeriesType"); + + entity.HasOne(d => d.Winner) + .WithMany(p => p.Series) + .HasForeignKey(d => d.WinnerID) + .HasConstraintName("FK_Series_Team"); }); modelBuilder.Entity(entity => diff --git a/Gordon360/Models/CCT/Context/efpt.CCT.config.json b/Gordon360/Models/CCT/Context/efpt.CCT.config.json index 623db5d0b..79f89e98b 100644 --- a/Gordon360/Models/CCT/Context/efpt.CCT.config.json +++ b/Gordon360/Models/CCT/Context/efpt.CCT.config.json @@ -146,6 +146,10 @@ "Name": "[dbo].[Users]", "ObjectType": 0 }, + { + "Name": "[Housing].[Roommate]", + "ObjectType": 0 + }, { "Name": "[RecIM].[Activity]", "ObjectType": 0 diff --git a/Gordon360/Models/CCT/Housing/Roommate.cs b/Gordon360/Models/CCT/Housing/Roommate.cs new file mode 100644 index 000000000..162e69325 --- /dev/null +++ b/Gordon360/Models/CCT/Housing/Roommate.cs @@ -0,0 +1,25 @@ +// This file has been auto generated by EF Core Power Tools. +#nullable disable +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; + +namespace Gordon360.Models.CCT +{ + [Table("Roommate", Schema = "Housing")] + public partial class Roommate + { + [Key] + public int ID { get; set; } + [Required] + [StringLength(128)] + [Unicode(false)] + public string Name { get; set; } + [Key] + [StringLength(128)] + [Unicode(false)] + public string RoommateName { get; set; } + } +} \ No newline at end of file diff --git a/Gordon360/Services/HousingService.cs b/Gordon360/Services/HousingService.cs index 4bdce8780..7c6c1b1c7 100644 --- a/Gordon360/Services/HousingService.cs +++ b/Gordon360/Services/HousingService.cs @@ -9,6 +9,8 @@ using Gordon360.Enums; using Gordon360.Static.Methods; using Microsoft.EntityFrameworkCore; +using Gordon360.Models.webSQL.Context; +using System.Threading.Tasks; namespace Gordon360.Services { @@ -537,5 +539,28 @@ public bool ChangeApplicationDateSubmitted(int applicationID) _context.SaveChanges(); return true; } + + /// + /// roommate imformation setting + /// + /// The username for the user who complete the aplication form + /// The name of the selected roommate + public async Task UpdateRoommateAsync(string username, string roommate_name) + { + var GordonID = _context.ACCOUNT.FirstOrDefault(a => a.AD_Username == username)?.gordon_id; + if (GordonID == null) + { + throw new ResourceNotFoundException() { ExceptionMessage = "The applicant could not be found" }; + } + var newRoommate = new Roommate + { + ID = int.Parse(GordonID), + Name = username, + RoommateName = roommate_name + }; ; + await _context.Roommate.AddAsync(newRoommate); + + _context.SaveChanges(); + } } } diff --git a/Gordon360/Services/ServiceInterfaces.cs b/Gordon360/Services/ServiceInterfaces.cs index a67678b3b..e13171019 100644 --- a/Gordon360/Services/ServiceInterfaces.cs +++ b/Gordon360/Services/ServiceInterfaces.cs @@ -308,6 +308,7 @@ public interface IHousingService int EditApplication(string username, string sess_cde, int applicationID, string newEditorUsername, List newApartmentApplicants, List newApartmentChoices); bool ChangeApplicationEditor(string username, int applicationID, string newEditorUsername); bool ChangeApplicationDateSubmitted(int applicationID); + Task UpdateRoommateAsync(string username, string roommate_name); } public interface IAcademicCheckInService From 6d0f52810155387f21e60ae9190e542953261f63 Mon Sep 17 00:00:00 2001 From: Wenlan Ji Date: Tue, 21 May 2024 15:25:12 -0400 Subject: [PATCH 44/44] fixed a few issue --- Gordon360/Documentation/Gordon360.xml | 175 ++++++++++++++++----- Gordon360/Models/CCT/Context/CCTContext.cs | 45 +++--- 2 files changed, 163 insertions(+), 57 deletions(-) diff --git a/Gordon360/Documentation/Gordon360.xml b/Gordon360/Documentation/Gordon360.xml index 515baa079..95f88ac46 100644 --- a/Gordon360/Documentation/Gordon360.xml +++ b/Gordon360/Documentation/Gordon360.xml @@ -49,8 +49,8 @@ Return a list of accounts matching some or all of the search parameter. - The firstname portion of the search - The lastname portion of the search + The firstname portion of the search + The lastname portion of the search All accounts matching some or all of both the firstname and lastname parameters, sorted by how well the account matched the search. @@ -588,6 +588,9 @@ The approved or denied news item The news item must not be expired + + constructor of ProfilesController + Get profile info of currently logged in user @@ -769,10 +772,9 @@ All Mail Destinations - + Gets a list of all Activities by parameter - Optional active parameter - Optional time parameter + Optional active parameter denoting whether or not an activity has been completed All Existing Activities @@ -791,14 +793,14 @@ - + Posts Activity into CCT.RecIM.Activity CreateActivityViewModel object with appropriate values Posted Activity - + Updates Activity based on input @@ -806,13 +808,61 @@ Updated Activity Object - + Cascade deletes all DBobjects related to given ActivityID + + + Gets all stored affiliations/halls/clubs with associated + Points/Activities Won : Winning Team + + + + + Gets specific stored affiliation with associated + Points/Activities Won : Winning Team + + + + + Creates new Affiliation + + + + + + + Updates an affiliation's logo and/or name + + + updated instance of affiliation + + + + + Creates new AffiliationPoints entry + (affiliationname, activity where points were attributed, optional points) + + put viewmodel + + + + + + Deletes affiliation + + + + + + Get all matches + + all matches + Get's current match attendance for a specified match @@ -840,14 +890,14 @@ - + Creates a new match/series surface - + Updates a given surface @@ -855,7 +905,7 @@ - + Deletes surface, points all foreign keys to an unknown surface to prevent corrupted data @@ -863,7 +913,7 @@ - + Updates Match Scores, Sportsmanship Ratings, and Team Status @@ -871,7 +921,7 @@ - + Updates Match Start Times and Surfaces @@ -879,21 +929,21 @@ - + Creates Match - + Cascade deletes all DBobjects related to given Match ID - + creates match attendance @@ -902,7 +952,7 @@ List of attendees for a team - + Adds single match participant @@ -910,7 +960,7 @@ object holding required username (optional teamID) - + Deletes single match participant @@ -918,6 +968,21 @@ object holding required username (optional teamID) + + + Rec-IM Reporting: + Every semester Rec-IM needs to report, their own client, + information regarding new users, retention of users, + gender ratio, involvements... + + This route does not specify semester terms, however, is more + specific in which it can select time constraints from beginning + to end with no limit to time in between + + report start time + report end time + + Queries all Series with an optional active tag @@ -946,7 +1011,7 @@ - + Updates Series Information @@ -954,7 +1019,7 @@ modified series - + Creates Series and associated SeriesTeam Models @@ -962,27 +1027,48 @@ ID of Series, used to select specific Teams created series - + Creates schedule or finds existing schedule created schedule for series created series schedule - + + + Updates team record manually (mitigates potential bugs) + + + Updated team record + updated team record + + Cascade deletes all DBobjects related to given Series ID - + Automatically creates Matches based on given Series optional request data, used for additional options on autoscheduling + + + Gives last date and number of matches of which the Auto Scheduler will create matches until. + + + optional request data, used for additional options on autoscheduling + + + + Gets available bracket information for a givaen series + + + Fetches all Sports in the RecIM database @@ -996,7 +1082,7 @@ - + Update Sport in the database by ID @@ -1004,7 +1090,14 @@ - + + + Deletes Sport in the database by ID + + + + + Creates new Sport for RecIM @@ -1032,15 +1125,14 @@ specified team type - + Create a new team with the requesting user set to team captain - creator's username - + Add a participant to a team @@ -1048,7 +1140,7 @@ Default Role Value value 3 (Member) - + Updates Participant role in a team @@ -1056,14 +1148,14 @@ - + Removes team and all participants in the team - + Removes specified user from a team @@ -1071,7 +1163,7 @@ - + Update a team info @@ -1093,7 +1185,7 @@ number of games a participant has attended for a team - + Accept one specified team invite and true delete others from the same activity if there's any @@ -2500,6 +2592,13 @@ query handle the enumeration. + + + Fetches the account record with the specified username. Inclusive of non-gordon accounts made by Rec-IM + + The AD username associated with the account. + account information + Scheduler does not currently handle overlaps @@ -2510,7 +2609,13 @@ Created Match objects - + + + Current double elimination autoscheduling will consider "play-in" as a "play-in" tournament + Losers of the play in do not count for the double elimination bracket. + + + Goal of this function is to generate a single elimination round. On the first possible round, this would imply handling teams with byes to ensure @@ -2744,4 +2849,4 @@ The base64 content of the image - \ No newline at end of file + diff --git a/Gordon360/Models/CCT/Context/CCTContext.cs b/Gordon360/Models/CCT/Context/CCTContext.cs index 93e3dc2e4..15d543a5e 100644 --- a/Gordon360/Models/CCT/Context/CCTContext.cs +++ b/Gordon360/Models/CCT/Context/CCTContext.cs @@ -861,45 +861,46 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { entity.Property(e => e.ID).ValueGeneratedOnAdd(); - modelBuilder.Entity(entity => - { - entity.ToView("UserCourses"); + modelBuilder.Entity(entity => + { + entity.ToView("UserCourses"); - entity.Property(e => e.BLDG_CDE).IsFixedLength(); + entity.Property(e => e.BLDG_CDE).IsFixedLength(); - entity.Property(e => e.CRS_CDE).IsFixedLength(); + entity.Property(e => e.CRS_CDE).IsFixedLength(); - entity.Property(e => e.CRS_TITLE).IsFixedLength(); + entity.Property(e => e.CRS_TITLE).IsFixedLength(); - entity.Property(e => e.DROP_FLAG).IsFixedLength(); + entity.Property(e => e.DROP_FLAG).IsFixedLength(); - entity.Property(e => e.FRIDAY_CDE).IsFixedLength(); + entity.Property(e => e.FRIDAY_CDE).IsFixedLength(); - entity.Property(e => e.LOC_CDE).IsFixedLength(); + entity.Property(e => e.LOC_CDE).IsFixedLength(); - entity.Property(e => e.MONDAY_CDE).IsFixedLength(); + entity.Property(e => e.MONDAY_CDE).IsFixedLength(); - entity.Property(e => e.ROOM_CDE).IsFixedLength(); + entity.Property(e => e.ROOM_CDE).IsFixedLength(); - entity.Property(e => e.SATURDAY_CDE).IsFixedLength(); + entity.Property(e => e.SATURDAY_CDE).IsFixedLength(); - entity.Property(e => e.SUNDAY_CDE).IsFixedLength(); + entity.Property(e => e.SUNDAY_CDE).IsFixedLength(); - entity.Property(e => e.THURSDAY_CDE).IsFixedLength(); + entity.Property(e => e.THURSDAY_CDE).IsFixedLength(); - entity.Property(e => e.TRM_CDE).IsFixedLength(); + entity.Property(e => e.TRM_CDE).IsFixedLength(); - entity.Property(e => e.TUESDAY_CDE).IsFixedLength(); + entity.Property(e => e.TUESDAY_CDE).IsFixedLength(); - entity.Property(e => e.WEDNESDAY_CDE).IsFixedLength(); + entity.Property(e => e.WEDNESDAY_CDE).IsFixedLength(); - entity.Property(e => e.YR_CDE).IsFixedLength(); - }); + entity.Property(e => e.YR_CDE).IsFixedLength(); + }); - modelBuilder.HasSequence("Information_Change_Request_Seq"); + modelBuilder.HasSequence("Information_Change_Request_Seq"); - OnModelCreatingGeneratedProcedures(modelBuilder); - OnModelCreatingPartial(modelBuilder); + OnModelCreatingGeneratedProcedures(modelBuilder); + OnModelCreatingPartial(modelBuilder); + }); } partial void OnModelCreatingPartial(ModelBuilder modelBuilder);