Skip to content

Commit

Permalink
Merge branch 's23-stateYourBuisnes-advisor' of https://github.com/gor…
Browse files Browse the repository at this point in the history
…don-cs/gordon-360-api into s23-stateYourBuisnes-advisor
  • Loading branch information
antoniavonto committed Jul 20, 2023
2 parents 3498fc0 + 6b8fa1b commit b322bd0
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 10 deletions.
35 changes: 32 additions & 3 deletions Gordon360/Controllers/ProfilesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json.Linq;
using Gordon360.Models.webSQL.Context;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -27,13 +28,15 @@ public class ProfilesController : GordonControllerBase
private readonly IAccountService _accountService;
private readonly IMembershipService _membershipService;
private readonly IConfiguration _config;
private readonly webSQLContext _webSQLContext;

public ProfilesController(IProfileService profileService, IAccountService accountService, IMembershipService membershipService, IConfiguration config)
public ProfilesController(IProfileService profileService, IAccountService accountService, IMembershipService membershipService, IConfiguration config, webSQLContext webSQLContext)
{
_profileService = profileService;
_accountService = accountService;
_membershipService = membershipService;
_config = config;
_webSQLContext = webSQLContext;
}

/// <summary>Get profile info of currently logged in user</summary>
Expand Down Expand Up @@ -469,21 +472,35 @@ public async Task<ActionResult<FacultyStaffProfileViewModel>> UpdateOfficeLocati
/// <returns></returns>
[HttpPut]
[Route("office_hours")]
public async Task<ActionResult<FacultyStaffProfileViewModel>> UpdateOfficeHours(string value)
public async Task<ActionResult<FacultyStaffProfileViewModel>> UpdateOfficeHours([FromBody]string value)
{
var username = AuthUtils.GetUsername(User);
var result = await _profileService.UpdateOfficeHoursAsync(username, value);
return Ok(result);
}

/// <summary>
/// Update mail location
/// </summary>
/// <param name="value">mail location</param>
/// <returns></returns>
[HttpPut]
[Route("mailstop")]
public async Task<ActionResult<FacultyStaffProfileViewModel>> UpdateMailStop([FromBody]string value)
{
var username = AuthUtils.GetUsername(User);
var result = await _profileService.UpdateMailStopAsync(username, value);
return Ok(result);
}

/// <summary>
/// Update privacy of mobile phone number
/// </summary>
/// <param name="value">Y or N</param>
/// <returns></returns>
[HttpPut]
[Route("mobile_privacy/{value}")]
public async Task<ActionResult> UpdateMobilePrivacyAsync(string value)
public async Task<ActionResult> UpdateMobilePrivacyAsync([FromBody]string value)
{
var authenticatedUserUsername = AuthUtils.GetUsername(User);
await _profileService.UpdateMobilePrivacyAsync(authenticatedUserUsername, value);
Expand Down Expand Up @@ -611,5 +628,17 @@ public ActionResult<IEnumerable<MembershipHistoryViewModel>> GetMembershipHistor

return Ok(membershipHistories);
}

/// <summary>
/// Return a list of mail destinations' descriptions.
/// </summary>
/// <returns> All Mail Destinations</returns>
[HttpGet]
[Route("mailstops")]
public ActionResult<IEnumerable<string>> GetMailStops()
{
var mail_stops = _profileService.GetMailStopsAsync();
return Ok(mail_stops);
}
}
}
21 changes: 21 additions & 0 deletions Gordon360/Documentation/Gordon360.xml

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

2 changes: 0 additions & 2 deletions Gordon360/Models/ViewModels/VersionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ public class VersionViewModel
public string GitHash { get; set; }
public string BuildTime { get; set; }
}


}
1 change: 0 additions & 1 deletion Gordon360/Models/webSQL/Context/efpt.webSQL.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"salt",
"SSN",
"barcode",
"mail_server",
"account_type",
"access_list",
"policy",
Expand Down
4 changes: 4 additions & 0 deletions Gordon360/Models/webSQL/Models/account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
namespace Gordon360.Models.webSQL.Models
{
[Table("account")]
[Index("mail_server", Name = "IX_account_mail_server")]
public partial class account
{
[Key]
public int account_id { get; set; }
[StringLength(20)]
[Unicode(false)]
public string mail_server { get; set; }
/// <summary>
/// Active Directory Username
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Gordon360/Models/webSQL/Models/account_profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class account_profile
{
[Key]
public int account_id { get; set; }
[StringLength(75)]
[StringLength(8000)]
[Unicode(false)]
public string office_hours { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions Gordon360/Services/AccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public IEnumerable<AdvancedSearchViewModel> GetAccountsToSearch(List<string> acc
IEnumerable<Alumni> alumni = Enumerable.Empty<Alumni>();
if (accountTypes.Contains("alumni"))
{
alumni = _context.Alumni;
alumni = _context.Alumni.Where(a => a.ShareName != "N");
}

// Do not indirectly reveal the address of facstaff and alumni who have requested to keep it private.
Expand Down Expand Up @@ -281,4 +281,4 @@ public async Task<IEnumerable<BasicInfoViewModel>> GetAllBasicInfoExceptAlumniAs
});
}
}
}
}
28 changes: 27 additions & 1 deletion Gordon360/Services/ProfileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,26 @@ public async Task<FacultyStaffProfileViewModel> UpdateOfficeHoursAsync(string us
return profile;
}

/// <summary>
/// mail location setting
/// </summary>
/// <param name="username"> The username for the user whose mail location is to be updated </param>
/// <param name="newMail">The new mail location to update the user's mail location to</param>
/// <returns>updated fac/staff profile if found</returns>
public async Task<FacultyStaffProfileViewModel> UpdateMailStopAsync(string username, string newMail)
{
var profile = GetFacultyStaffProfileByUsername(username);
if (profile == null)
{
throw new ResourceNotFoundException() { ExceptionMessage = "The account was not found" };
}
var user = _webSQLContext.accounts.FirstOrDefault(a => a.AD_Username == username);
user.mail_server = newMail;
await _webSQLContext.SaveChangesAsync();

return profile;
}

/// <summary>
/// privacy setting user profile photo.
/// </summary>
Expand Down Expand Up @@ -488,5 +508,11 @@ private static JObject MergeProfile(JObject profile, JObject profileInfo)
});
return profile;
}

public IEnumerable<string> GetMailStopsAsync()
{
return _webSQLContext.Mailstops.Select(m => m.code)
.OrderBy(d => d);
}
}
}
}
2 changes: 2 additions & 0 deletions Gordon360/Services/ServiceInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ public interface IProfileService
Task<StudentProfileViewModel> UpdateMobilePhoneNumberAsync(string username, string newMobilePhoneNumber);
Task<FacultyStaffProfileViewModel> UpdateOfficeLocationAsync(string username, string newBuilding, string newRoom);
Task<FacultyStaffProfileViewModel> UpdateOfficeHoursAsync(string username, string newHours);
Task<FacultyStaffProfileViewModel> UpdateMailStopAsync(string username, string newMail);
Task UpdateMobilePrivacyAsync(string username, string value);
Task UpdateImagePrivacyAsync(string username, string value);
Task UpdateProfileImageAsync(string username, string path, string name);
ProfileViewModel? ComposeProfile(object? student, object? alumni, object? faculty, object? customInfo);
Task InformationChangeRequest(string username, ProfileFieldViewModel[] updatedField);
IEnumerable<string> GetMailStopsAsync();
}

public interface IAddressesService
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ The backend is deployed automatically using GitHub Actions. Whenever changes are

To detect and deploy successful builds, the scheduled task `Deploy 360Api[Train]` runs every 5 minutes on the API server. It calls the powershell script `Deploy360BackEnd.ps1` (found at `F:\Scripts\Deploy`), polling GitHub's API for new builds. If it detects a new build for the relevant environment (`Train` for `develop`, `Prod` for `master`), it will backup the existing API and deploy the new one. Transcripts for these deployments can be found at `F:\Scripts\Deploy\Transcripts`.

The API server publishes its build timestamp and github SHA on the /Version endpoint, so checking this with Swagger (e.g., https://360apitrain.gordon.edu/swagger/) is a good way to see when the new version is deployed and serving.

### Deploying Manually

If there are problems with continuous deployment, or a specific need arises to revert or push manually, then this older procedure can be used.
Expand Down

0 comments on commit b322bd0

Please sign in to comment.