Skip to content

Commit

Permalink
Merge branch 'develop' into s23-fac-privacy-option
Browse files Browse the repository at this point in the history
  • Loading branch information
ArabellaJi authored Jul 21, 2023
2 parents 32128b8 + 4f9715e commit 7fd260c
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 38 deletions.
19 changes: 15 additions & 4 deletions Gordon360/Authorization/StateYourBusiness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,24 @@ private async Task<bool> CanReadPartialAsync(string resource)
}

// Only members can read a specific activity's memberships
if (context.ActionArguments.TryGetValue("involvementCode", out object? involvementCode_object) && involvementCode_object is string involvementCode)
if (context.ActionArguments.TryGetValue("involvementCode", out object? involvementCode_object) && involvementCode_object is string involvementCode)
{
var activityMembers = _membershipService.GetMemberships(activityCode: involvementCode, username: user_name);
var is_personAMember = activityMembers.Any(x => x.Participation != Participation.Guest.GetCode());
return is_personAMember;
if (context.ActionArguments.TryGetValue("sessionCode", out object? sessionCode_object) && sessionCode_object is string sessionCode)
{
var activityMembers = _membershipService.GetMemberships(activityCode: involvementCode, username: user_name, sessionCode: sessionCode);
var is_personAMember = activityMembers.Any(x => x.Participation != "GUEST");
return is_personAMember;

}
else
{
var activityMembers = _membershipService.GetMemberships(activityCode: involvementCode, username: user_name, sessionCode: "*");
var is_personAMember = activityMembers.Any(x => x.Participation != "GUEST");
return is_personAMember;
}
}


return false;
}

Expand Down
15 changes: 11 additions & 4 deletions Gordon360/Controllers/MembershipsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ public ActionResult<IEnumerable<MembershipView>> GetMemberships(string? involvem
sessionCode: sessionCode,
participationTypes: participationTypes);

// When user is null, only SiteAdmin and Police can see all the memberships.
if ((username is null) && !(viewerGroups.Contains(AuthGroup.SiteAdmin)
|| viewerGroups.Contains(AuthGroup.Police)))
{
memberships = _membershipService.RemovePrivateMemberships(memberships, authenticatedUserUsername);
return Ok(memberships);
}
// Only user, siteAdmin and Police can see all the user's memberships.
if (
(username is null || username != authenticatedUserUsername)
&& !(viewerGroups.Contains(AuthGroup.SiteAdmin) || viewerGroups.Contains(AuthGroup.Police))
)
else if ((username is not null) && !(username == authenticatedUserUsername
|| viewerGroups.Contains(AuthGroup.SiteAdmin)
|| viewerGroups.Contains(AuthGroup.Police)
))
{
memberships = _membershipService.RemovePrivateMemberships(memberships, authenticatedUserUsername);
}
Expand Down
10 changes: 5 additions & 5 deletions Gordon360/Controllers/ProfilesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,18 +442,18 @@ public async Task<ActionResult> ResetImage()
}

/// <summary>
/// Update the profile social media links
/// Update CUSTOM_PROFILE component
/// </summary>
/// <param name="type">The type of social media</param>
/// <param name="path">The path of the links</param>
/// <param name="type">The type of component</param>
/// <param name="value">The value to change the component to</param>
/// <returns></returns>
[HttpPut]
[Route("{type}")]
public async Task<ActionResult> UpdateLinkAsync(string type, CUSTOM_PROFILE path)
public async Task<ActionResult> UpdateCustomProfile(string type,[FromBody] CUSTOM_PROFILE value)
{
var authenticatedUserUsername = AuthUtils.GetUsername(User);

await _profileService.UpdateProfileLinkAsync(authenticatedUserUsername, type, path);
await _profileService.UpdateCustomProfileAsync(authenticatedUserUsername, type, value);

return Ok();
}
Expand Down
14 changes: 7 additions & 7 deletions Gordon360/Documentation/Gordon360.xml

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

11 changes: 9 additions & 2 deletions Gordon360/Models/CCT/Context/CCTContextProcedures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ public virtual async Task<int> CREATE_RIDEAsync(string RIDEID, string DESTINATIO
return _;
}

public virtual async Task<int> CREATE_SOCIAL_LINKSAsync(string USERNAME, string FACEBOOK, string TWITTER, string INSTAGRAM, string LINKEDIN, string HANDSHAKE, OutputParameter<int> returnValue = null, CancellationToken cancellationToken = default)
public virtual async Task<int> CREATE_SOCIAL_LINKSAsync(string USERNAME, string FACEBOOK, string TWITTER, string INSTAGRAM, string LINKEDIN, string HANDSHAKE, string CALENDAR, OutputParameter<int> returnValue = null, CancellationToken cancellationToken = default)
{
var parameterreturnValue = new SqlParameter
{
Expand Down Expand Up @@ -692,9 +692,16 @@ public virtual async Task<int> CREATE_SOCIAL_LINKSAsync(string USERNAME, string
Value = HANDSHAKE ?? Convert.DBNull,
SqlDbType = System.Data.SqlDbType.VarChar,
},
new SqlParameter
{
ParameterName = "CALENDAR",
Size = -1,
Value = CALENDAR ?? Convert.DBNull,
SqlDbType = System.Data.SqlDbType.VarChar,
},
parameterreturnValue,
};
var _ = await _context.Database.ExecuteSqlRawAsync("EXEC @returnValue = [dbo].[CREATE_SOCIAL_LINKS] @USERNAME, @FACEBOOK, @TWITTER, @INSTAGRAM, @LINKEDIN, @HANDSHAKE", sqlParameters, cancellationToken);
var _ = await _context.Database.ExecuteSqlRawAsync("EXEC @returnValue = [dbo].[CREATE_SOCIAL_LINKS] @USERNAME, @FACEBOOK, @TWITTER, @INSTAGRAM, @LINKEDIN, @HANDSHAKE, @CALENDAR", sqlParameters, cancellationToken);

returnValue?.SetValue(parameterreturnValue.Value);

Expand Down
2 changes: 1 addition & 1 deletion Gordon360/Models/CCT/Context/ICCTContextProcedures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial interface ICCTContextProcedures
Task<List<CREATE_MESSAGE_ROOMResult>> CREATE_MESSAGE_ROOMAsync(string name, bool? group, byte[] roomImage, OutputParameter<int> returnValue = null, CancellationToken cancellationToken = default);
Task<int> CREATE_MYSCHEDULEAsync(string EVENTID, string GORDONID, string LOCATION, string DESCRIPTION, string MON_CDE, string TUE_CDE, string WED_CDE, string THU_CDE, string FRI_CDE, string SAT_CDE, string SUN_CDE, int? IS_ALLDAY, TimeSpan? BEGINTIME, TimeSpan? ENDTIME, OutputParameter<int> returnValue = null, CancellationToken cancellationToken = default);
Task<int> CREATE_RIDEAsync(string RIDEID, string DESTINATION, string MEETINGPOINT, DateTime? STARTTIME, DateTime? ENDTIME, int? CAPACITY, string NOTES, byte? CANCELED, OutputParameter<int> returnValue = null, CancellationToken cancellationToken = default);
Task<int> CREATE_SOCIAL_LINKSAsync(string USERNAME, string FACEBOOK, string TWITTER, string INSTAGRAM, string LINKEDIN, string HANDSHAKE, OutputParameter<int> returnValue = null, CancellationToken cancellationToken = default);
Task<int> CREATE_SOCIAL_LINKSAsync(string USERNAME, string FACEBOOK, string TWITTER, string INSTAGRAM, string LINKEDIN, string HANDSHAKE, string CALENDAR, OutputParameter<int> returnValue = null, CancellationToken cancellationToken = default);
Task<List<CURRENT_SESSIONResult>> CURRENT_SESSIONAsync(OutputParameter<int> returnValue = null, CancellationToken cancellationToken = default);
Task<int> DELETE_AA_APARTMENT_CHOICEAsync(int? APPLICATION_ID, string HALL_NAME, OutputParameter<int> returnValue = null, CancellationToken cancellationToken = default);
Task<int> DELETE_AA_APPLICANTAsync(int? APPLICATION_ID, string USERNAME, string SESS_CDE, OutputParameter<int> returnValue = null, CancellationToken cancellationToken = default);
Expand Down
6 changes: 5 additions & 1 deletion Gordon360/Models/ViewModels/ProfileCustomViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class ProfileCustomViewModel
public string Instagram { get; set; }
public string LinkedIn { get; set; }
public string Handshake { get; set; }
public string PlannedGradYear { get; set; }
public string Calendar { get; set; }

public static implicit operator ProfileCustomViewModel?(CUSTOM_PROFILE? pro)
{
Expand All @@ -22,7 +24,9 @@ public class ProfileCustomViewModel
Twitter = pro.twitter ?? "",
Instagram = pro.instagram ?? "",
LinkedIn = pro.linkedin ?? "",
Handshake = pro.handshake ?? ""
Handshake = pro.handshake ?? "",
PlannedGradYear = pro.PlannedGradYear ?? "",
Calendar = pro.calendar ?? ""
};
}
}
Expand Down
5 changes: 3 additions & 2 deletions Gordon360/Models/ViewModels/ProfileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public record ProfileViewModel(
string Instagram,
string LinkedIn,
string Handshake,
string MobilePhone,

string Calendar,

// Student Only
string OnOffCampus,
Expand All @@ -52,6 +51,8 @@ public record ProfileViewModel(
string Minor3,
string Minor3Description,
string GradDate,
string PlannedGradYear,
string MobilePhone,
bool IsMobilePhonePrivate,
int? ChapelRequired,
int? ChapelAttended,
Expand Down
2 changes: 2 additions & 0 deletions Gordon360/Models/ViewModels/PublicStudentProfileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class PublicStudentProfileViewModel
public string Email { get; set; }
public string Gender { get; set; }
public string grad_student { get; set; }
public string PlannedGradYear { get; set; }
public string MobilePhone { get; set; }
public string HomePhone { get; set; }
public string AD_Username { get; set; }
Expand Down Expand Up @@ -59,6 +60,7 @@ public static implicit operator PublicStudentProfileViewModel(StudentProfileView
Hall = stu.BuildingDescription ?? "",
Cohort = stu.Cohort ?? "",
grad_student = stu.grad_student ?? "",
PlannedGradYear = stu.PlannedGradYear ?? "",
KeepPrivate = stu.KeepPrivate ?? "",
Email = stu.Email ?? "",
Gender = stu.Gender ?? "",
Expand Down
2 changes: 2 additions & 0 deletions Gordon360/Models/ViewModels/StudentProfileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public record StudentProfileViewModel
string Gender,
string grad_student,
string GradDate,
string PlannedGradYear,
string MobilePhone,
bool IsMobilePhonePrivate,
string AD_Username,
Expand Down Expand Up @@ -123,6 +124,7 @@ public record StudentProfileViewModel
stu.Gender ?? "",
stu.grad_student ?? "",
stu.GradDate ?? "",
stu.PlannedGradYear ?? "",
stu.MobilePhone ?? "",
stu.IsMobilePhonePrivate == 1 ? true : false,
stu.AD_Username ?? "", // Just in case some random record has a null email field
Expand Down
1 change: 1 addition & 0 deletions Gordon360/Services/MembershipService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public IEnumerable<MembershipView> GetMemberships(
{
IQueryable<MembershipView> memberships = _context.MembershipView;
if (username is not null) memberships = memberships.Where(m => EF.Functions.Like(m.Username, username));

if (activityCode is not null) memberships = memberships.Where(m => m.ActivityCode == activityCode);

// Null sessionCode defaults to current session
Expand Down
29 changes: 18 additions & 11 deletions Gordon360/Services/ProfileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
using Gordon360.Models.ViewModels;
using Gordon360.Models.webSQL.Context;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Mail;
Expand Down Expand Up @@ -236,46 +238,51 @@ public async Task UpdateProfileImageAsync(string username, string? path, string?


/// <summary>
/// Sets the path for the profile links.
/// Sets the component of the Custom_profile.
/// </summary>
/// <param name="username">The username</param>
/// <param name="type"></param>
/// <param name="links"></param>
public async Task UpdateProfileLinkAsync(string username, string type, CUSTOM_PROFILE links)
/// <param name="content"></param>
public async Task UpdateCustomProfileAsync(string username, string type, CUSTOM_PROFILE content)
{
var original = await _context.CUSTOM_PROFILE.FindAsync(username);

if (original == null)
{
await _context.CUSTOM_PROFILE.AddAsync(new CUSTOM_PROFILE { username = username, calendar = links.calendar, facebook = links.facebook, twitter = links.twitter, instagram = links.instagram, linkedin = links.linkedin, handshake = links.handshake });
await _context.CUSTOM_PROFILE.AddAsync(new CUSTOM_PROFILE { username = username, calendar = content.calendar, facebook = content.facebook, twitter = content.twitter, instagram = content.instagram, linkedin = content.linkedin, handshake = content.handshake, PlannedGradYear = content.PlannedGradYear });

}
else
{

switch (type)
{

case "calendar":
original.calendar = links.calendar;
original.calendar = content.calendar;
break;

case "facebook":
original.facebook = links.facebook;
original.facebook = content.facebook;
break;

case "twitter":
original.twitter = links.twitter;
original.twitter = content.twitter;
break;

case "instagram":
original.instagram = links.instagram;
original.instagram = content.instagram;
break;

case "linkedin":
original.linkedin = links.linkedin;
original.linkedin = content.linkedin;
break;

case "handshake":
original.handshake = links.handshake;
original.handshake = content.handshake;
break;
case "plannedGradYear":
original.PlannedGradYear = content.PlannedGradYear;
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Gordon360/Services/ServiceInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface IProfileService
IEnumerable<EmergencyContactViewModel> GetEmergencyContact(string username);
ProfileCustomViewModel? GetCustomUserInfo(string username);
Task<PhotoPathViewModel?> GetPhotoPathAsync(string username);
Task UpdateProfileLinkAsync(string username, string type, CUSTOM_PROFILE path);
Task UpdateCustomProfileAsync(string username, string type, CUSTOM_PROFILE content);
Task<StudentProfileViewModel> UpdateMobilePhoneNumberAsync(string username, string newMobilePhoneNumber);
Task<FacultyStaffProfileViewModel> UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom);
Task<FacultyStaffProfileViewModel> UpdateOfficeHoursAsync(string username, string newHours);
Expand Down

0 comments on commit 7fd260c

Please sign in to comment.