Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New User Privacy Setting (2024) #1042

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Gordon360/Authorization/StateYourBusiness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
_membershipService = context.HttpContext.RequestServices.GetRequiredService<IMembershipService>();
_membershipRequestService = context.HttpContext.RequestServices.GetRequiredService<IMembershipRequestService>();
_newsService = context.HttpContext.RequestServices.GetRequiredService<INewsService>();
_CCTContext = context.HttpContext.RequestServices.GetService<CCTContext>();

Check warning on line 67 in Gordon360/Authorization/StateYourBusiness.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.

// set RecIM services
_recimParticipantService = context.HttpContext.RequestServices.GetRequiredService<IParticipantService>();
Expand Down Expand Up @@ -635,7 +635,11 @@

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
Expand Down
68 changes: 58 additions & 10 deletions Gordon360/Controllers/ProfilesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Gordon360.Models.CCT.Context;

namespace Gordon360.Controllers;

[Route("api/[controller]")]
public class ProfilesController(IProfileService profileService,
IAccountService accountService,
IMembershipService membershipService,
IConfiguration config) : GordonControllerBase
IConfiguration config,
CCTContext context) : GordonControllerBase
{

/// <summary>Get profile info of currently logged in user</summary>
Expand Down Expand Up @@ -54,7 +56,7 @@ public class ProfilesController(IProfileService profileService,
/// <returns></returns>
[HttpGet]
[Route("{username}")]
public ActionResult<ProfileViewModel?> GetUserProfile(string username)
public ActionResult<ProfileViewModel?> GetUserProfileAsync(string username)
{
var viewerGroups = AuthUtils.GetGroups(User);

Expand All @@ -76,23 +78,26 @@ public class ProfilesController(IProfileService profileService,
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))
{
student = _student == null ? null : (PublicStudentProfileViewModel)_student;
faculty = _faculty == null ? null : (PublicFacultyStaffProfileViewModel)_faculty;
// If this student is also in Alumni AuthGroup, then s/he can see alumni's
// public profile; if not, return null.
student = _student == null ? null :
profileService.ToPublicStudentProfileViewModel(username, "stu", _student);
faculty = _faculty == null ? null :
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;
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 :
profileService.ToPublicFacultyStaffProfileViewModel(username, "alu", _faculty);
alumni = _alumni == null ? null : (PublicAlumniProfileViewModel)_alumni;
}

Expand Down Expand Up @@ -121,6 +126,20 @@ public async Task<ActionResult<IEnumerable<AdvisorViewModel>>> GetAdvisorsAsync(
return Ok(advisors);
}

///<summary>Get the privacy settings of a particular user</summary>
/// <returns>
/// All privacy settings of the given user.
/// </returns>
[HttpGet]
[Route("{username}/privacy_setting")]
[StateYourBusiness(operation = Operation.READ_ONE, resource = Resource.PROFILE)]
public ActionResult<IEnumerable<UserPrivacyGetViewModel>> GetPrivacySettingAsync(string username)
{
var privacy = profileService.GetPrivacySettingAsync(username);

return Ok(privacy);
}

/// <summary> Gets the clifton strengths of a particular user </summary>
/// <param name="username"> The username for which to retrieve info </param>
/// <returns> Clifton strengths of the given user. </returns>
Expand Down Expand Up @@ -466,6 +485,35 @@ public async Task<ActionResult<FacultyStaffProfileViewModel>> UpdateOfficeHours(
return Ok(result);
}

/// <summary>
/// Set visibility of some piece of personal data for user.
/// </summary>
/// <param name="userPrivacy">Faculty Staff Privacy Decisions (see UserPrivacyUpdateViewModel)</param>
/// <returns></returns>
[HttpPut]
[Route("user_privacy")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[Route("user_privacy")]
[Route("{username}/user_privacy")]

This may be personal preference, but I think it's better to always refer to a unique resource identifier rather than assuming the current authenticated user -- especially when trying to follow rest architecture.

Another option would be [Route("me/user_privacy")] but I don't know that we use that elsewhere.

// [StateYourBusiness(operation = Operation.UPDATE, resource = Resource.PROFILE_PRIVACY)]
public async Task<ActionResult<UserPrivacyUpdateViewModel>> UpdateUserPrivacyAsync(UserPrivacyUpdateViewModel userPrivacy)
{
var authenticatedUserUsername = AuthUtils.GetUsername(User);
await profileService.UpdateUserPrivacyAsync(authenticatedUserUsername, userPrivacy);
return Ok();
}

/// <summary>
/// Return a list visibility groups.
/// </summary>
/// <returns> All visibility groups (Public, FacStaff, Private)</returns>
[HttpGet]
[Route("visibility_groups")]
public ActionResult<IEnumerable<string>> GetVisibilityGroup()
{
var groups = context.UserPrivacy_Visibility_Groups.Select(up_v_g => up_v_g.Group)
.Distinct()
.Where(g => g != null);
return Ok(groups);
}

/// <summary>
/// Update mail location
/// </summary>
Expand Down
53 changes: 52 additions & 1 deletion Gordon360/Documentation/Gordon360.xml

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

28 changes: 28 additions & 0 deletions Gordon360/Models/CCT/Context/CCTContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ public CCTContext(DbContextOptions<CCTContext> options)

public virtual DbSet<UserCourses> UserCourses { get; set; }

public virtual DbSet<UserPrivacy_Fields> UserPrivacy_Fields { get; set; }

public virtual DbSet<UserPrivacy_Settings> UserPrivacy_Settings { get; set; }

public virtual DbSet<UserPrivacy_Visibility_Groups> UserPrivacy_Visibility_Groups { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ACCOUNT>(entity =>
Expand Down Expand Up @@ -609,6 +615,28 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.Property(e => e.WEDNESDAY_CDE).IsFixedLength();
entity.Property(e => e.YR_CDE).IsFixedLength();
});

modelBuilder.Entity<UserPrivacy_Fields>(entity =>
{
entity.Property(e => e.ID).ValueGeneratedOnAdd();
});

modelBuilder.Entity<UserPrivacy_Settings>(entity =>
{
entity.HasOne(d => d.FieldNavigation).WithMany(p => p.UserPrivacy_Settings)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_UserPrivacy_Settings_UserPrivacy_Fields");

entity.HasOne(d => d.VisibilityNavigation).WithMany(p => p.UserPrivacy_Settings)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_UserPrivacy_Settings_UserPrivacy_Visibility_Groups");
});

modelBuilder.Entity<UserPrivacy_Visibility_Groups>(entity =>
{
entity.Property(e => e.ID).ValueGeneratedOnAdd();
});

modelBuilder.HasSequence("Information_Change_Request_Seq");

OnModelCreatingGeneratedProcedures(modelBuilder);
Expand Down
12 changes: 12 additions & 0 deletions Gordon360/Models/CCT/Context/efpt.CCT.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@
"Name": "[dbo].[StudentNewsExpiration]",
"ObjectType": 0
},
{
"Name": "[dbo].[UserPrivacy_Fields]",
"ObjectType": 0
},
{
"Name": "[dbo].[UserPrivacy_Settings]",
"ObjectType": 0
},
{
"Name": "[dbo].[UserPrivacy_Visibility_Groups]",
"ObjectType": 0
},
{
"Name": "[RecIM].[Activity]",
"ObjectType": 0
Expand Down
23 changes: 23 additions & 0 deletions Gordon360/Models/CCT/dbo/UserPrivacy_Fields.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
#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("UserPrivacy_Fields", Schema = "dbo")]
public partial class UserPrivacy_Fields
{
public int ID { get; set; }

[Key]
[StringLength(50)]
[Unicode(false)]
public string Field { get; set; }

[InverseProperty("FieldNavigation")]
public virtual ICollection<UserPrivacy_Settings> UserPrivacy_Settings { get; set; } = new List<UserPrivacy_Settings>();
}
37 changes: 37 additions & 0 deletions Gordon360/Models/CCT/dbo/UserPrivacy_Settings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
#nullable disable
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

namespace Gordon360.Models.CCT;

[PrimaryKey("gordon_id", "Field")]
[Table("UserPrivacy_Settings", Schema = "dbo")]
public partial class UserPrivacy_Settings
{
[Key]
[StringLength(10)]
[Unicode(false)]
public string gordon_id { get; set; }

[Key]
[StringLength(50)]
[Unicode(false)]
public string Field { get; set; }

[Required]
[StringLength(50)]
[Unicode(false)]
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; }
}
23 changes: 23 additions & 0 deletions Gordon360/Models/CCT/dbo/UserPrivacy_Visibility_Groups.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
#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("UserPrivacy_Visibility_Groups", Schema = "dbo")]
public partial class UserPrivacy_Visibility_Groups
{
public int ID { get; set; }

[Key]
[StringLength(50)]
[Unicode(false)]
public string Group { get; set; }

[InverseProperty("VisibilityNavigation")]
public virtual ICollection<UserPrivacy_Settings> UserPrivacy_Settings { get; set; } = new List<UserPrivacy_Settings>();
}
2 changes: 2 additions & 0 deletions Gordon360/Models/ViewModels/FacultyStaffProfileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public record FacultyStaffProfileViewModel
string HomeCountry,
string HomePhone,
string HomeFax,
string MobilePhone,
string KeepPrivate,
string JobTitle,
string Dept,
Expand Down Expand Up @@ -73,6 +74,7 @@ public record FacultyStaffProfileViewModel
fac.HomeCountry ?? "",
fac.HomePhone ?? "",
fac.HomeFax ?? "",
fac.MobilePhone ?? "",
fac.KeepPrivate ?? "",
fac.JobTitle ?? "",
fac.Dept ?? "",
Expand Down
2 changes: 1 addition & 1 deletion Gordon360/Models/ViewModels/ProfileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading
Loading