-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from ucdavis/fix/RAPS-ux-fixes
RAPS fixes and LDAP fixes
- Loading branch information
Showing
28 changed files
with
1,707 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using Viper.Models.AAUD; | ||
using Viper.Areas.RAPS.Services; | ||
using Web.Authorization; | ||
using Viper.Classes; | ||
using Viper.Classes.SQLContext; | ||
using Viper.Areas.Directory.Models; | ||
using System.Runtime.Versioning; | ||
using System.Collections.Generic; | ||
using Viper.Areas.Directory.Services; | ||
using Viper.Classes.Utilities; | ||
|
||
namespace Viper.Areas.Directory.Controllers | ||
{ | ||
[Area("Directory")] | ||
[Permission(Allow = "SVMSecure")] | ||
[Authorize(Roles = "VMDO SVM-IT")] //locking directory for now until it's complete | ||
public class DirectoryController : AreaController | ||
{ | ||
public Classes.SQLContext.AAUDContext _aaud; | ||
private readonly RAPSContext? _rapsContext; | ||
public IUserHelper UserHelper; | ||
|
||
public DirectoryController(Classes.SQLContext.RAPSContext context) | ||
{ | ||
_aaud = new AAUDContext(); | ||
this._rapsContext = (RAPSContext?)HttpHelper.HttpContext?.RequestServices.GetService(typeof(RAPSContext)); | ||
UserHelper = new UserHelper(); | ||
} | ||
|
||
/// <summary> | ||
/// Directory home page | ||
/// </summary> | ||
[Route("/[area]/")] | ||
public async Task<ActionResult> Index(string? useExample) | ||
{ | ||
return await Task.Run(() => View("~/Areas/Directory/Views/Card.cshtml")); | ||
} | ||
|
||
/// <summary> | ||
/// Directory home page | ||
/// </summary> | ||
[Route("/[area]/nav")] | ||
public async Task<ActionResult<IEnumerable<NavMenuItem>>> Nav() | ||
{ | ||
var nav = new List<NavMenuItem> | ||
{ | ||
}; | ||
return await Task.Run(() => nav); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Directory list | ||
/// </summary> | ||
/// <param name="search">search string</param> | ||
/// <returns></returns> | ||
[SupportedOSPlatform("windows")] | ||
[Route("/[area]/search/{search}")] | ||
public async Task<ActionResult<IEnumerable<IndividualSearchResult>>> Get(string search) | ||
{ | ||
var individuals = await _aaud.AaudUsers | ||
.Where(u => (u.DisplayFirstName + " " + u.DisplayLastName).Contains(search) | ||
|| (u.MailId != null && u.MailId.Contains(search)) | ||
|| (u.LoginId != null && u.LoginId.Contains(search)) | ||
|| (u.SpridenId != null && u.SpridenId.Contains(search)) | ||
|| (u.Pidm != null && u.Pidm.Contains(search)) | ||
|| (u.MothraId != null && u.MothraId.Contains(search)) | ||
|| (u.EmployeeId != null && u.EmployeeId.Contains(search)) | ||
|| (u.IamId != null && u.IamId.Contains(search)) | ||
) | ||
.Where(u => u.Current != 0) | ||
.OrderBy(u => u.DisplayLastName) | ||
.ThenBy(u => u.DisplayFirstName) | ||
.ToListAsync(); | ||
List<IndividualSearchResult> results = new(); | ||
AaudUser? currentUser = UserHelper.GetCurrentUser(); | ||
bool hasDetailPermission = UserHelper.HasPermission(_rapsContext, currentUser, "SVMSecure.DirectoryDetail"); | ||
individuals.ForEach(m => | ||
{ | ||
LdapUserContact? l = new LdapService().GetUserByID(m.IamId); | ||
results.Add(hasDetailPermission | ||
? new IndividualSearchResultWithIDs(m, l) | ||
: new IndividualSearchResult(m, l)); | ||
|
||
var vmsearch = VMACSService.Search(results.Last().LoginId); | ||
var vm = vmsearch.Result; | ||
if (vm != null && vm.item != null && vm.item.Nextel != null && vm.item.LDPager != null) | ||
{ | ||
results.Last().Nextel = vm.item.Nextel[0]; | ||
results.Last().LDPager = vm.item.LDPager[0]; | ||
} | ||
}); | ||
return results; | ||
} | ||
|
||
/// <summary> | ||
/// Directory list | ||
/// </summary> | ||
/// <param name="search">search string</param> | ||
/// <returns></returns> | ||
[SupportedOSPlatform("windows")] | ||
[Route("/[area]/search/{search}/ucd")] | ||
public async Task<ActionResult<IEnumerable<IndividualSearchResult>>> GetUCD(string search) | ||
{ | ||
List<IndividualSearchResult> results = new(); | ||
List<LdapUserContact> ldap = LdapService.GetUsersContact(search); | ||
var individuals = await _aaud.AaudUsers | ||
.Where(u => (u.DisplayFirstName + " " + u.DisplayLastName).Contains(search) | ||
|| (u.MailId != null && u.MailId.Contains(search)) | ||
|| (u.LoginId != null && u.LoginId.Contains(search)) | ||
|| (u.SpridenId != null && u.SpridenId.Contains(search)) | ||
|| (u.Pidm != null && u.Pidm.Contains(search)) | ||
|| (u.MothraId != null && u.MothraId.Contains(search)) | ||
|| (u.EmployeeId != null && u.EmployeeId.Contains(search)) | ||
|| (u.IamId != null && u.IamId.Contains(search)) | ||
) | ||
.Where(u => u.Current != 0) | ||
.OrderBy(u => u.DisplayLastName) | ||
.ThenBy(u => u.DisplayFirstName) | ||
.ToListAsync(); | ||
AaudUser? currentUser = UserHelper.GetCurrentUser(); | ||
bool hasDetailPermission = UserHelper.HasPermission(_rapsContext, currentUser, "SVMSecure.DirectoryDetail"); | ||
foreach (var l in ldap) | ||
{ | ||
AaudUser? userInfo = individuals.Find(m => m.IamId == l.UcdPersonIamId); | ||
results.Add(hasDetailPermission | ||
? new IndividualSearchResultWithIDs(userInfo, l) | ||
: new IndividualSearchResult(userInfo, l)); | ||
}; | ||
return results; | ||
} | ||
|
||
/// <summary> | ||
/// Directory results | ||
/// </summary> | ||
/// <param name="uid">User ID</param> | ||
/// <returns></returns> | ||
[Route("/[area]/userInfo/{mothraID}")] | ||
public async Task<IActionResult> DirectoryResult(string mothraID) | ||
{ | ||
// pull in the user based on uid | ||
return await Task.Run(() => View("~/Areas/Directory/Views/UserInfo.cshtml")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.Versioning; | ||
using Viper.Areas.Directory.Services; | ||
using Viper.Models.AAUD; | ||
|
||
namespace Viper.Areas.Directory.Models | ||
{ | ||
public class IndividualSearchResult | ||
{ | ||
public string ClientId { get; set; } = string.Empty; | ||
public string MothraId { get; set; } = string.Empty; | ||
public string UCDPersonUUID { get; set; } = string.Empty; | ||
public string? LoginId { get; set; } = string.Empty; | ||
public string? MailId { get; set; } = string.Empty; | ||
public string? EmailHost { get; set; } = string.Empty; | ||
public string LastName { get; set; } = string.Empty; | ||
public string FirstName { get; set; } = string.Empty; | ||
public string? MiddleName { get; set; } = string.Empty; | ||
public string DisplayLastName { get; set; } = string.Empty; | ||
public string DisplayFirstName { get; set; } = string.Empty; | ||
public string? DisplayMiddleName { get; set; } = string.Empty; | ||
public string DisplayFullName { get; set; } = string.Empty; | ||
public string Name { get; set; } = string.Empty; | ||
public bool CurrentStudent { get; set; } = false; | ||
public bool FutureStudent { get; set; } = false; | ||
public bool CurrentEmployee { get; set; } = false; | ||
public bool FutureEmployee { get; set; } = false; | ||
public int? StudentTerm { get; set; } = null!; | ||
public int? EmployeeTerm { get; set; } = null!; | ||
public string? PpsId { get; set; } = string.Empty; | ||
public string? StudentPKey { get; set; } = string.Empty; | ||
public string? EmployeePKey { get; set; } = string.Empty; | ||
public string? Title { get; set; } = string.Empty; | ||
public string? Department { get; set; } = string.Empty; | ||
public int Current { get; set; } = -1; | ||
public int Future { get; set; } = -1; | ||
public string? IamId { get; set; } = string.Empty; | ||
public bool? Ross { get; set; } = null!; | ||
public DateTime? Added { get; set; } = null!; | ||
public string? Phone { get; set; } = null!; | ||
public string? Nextel { get; set; } = null!; | ||
public string? LDPager { get; set; } = null!; | ||
public string? Mobile { get; set; } = null!; | ||
public string? PostalAddress { get; set; } = null!; | ||
public string? UCDAffiliation { get; set; } = null!; | ||
public string? UserName { get; set; } = null!; | ||
public bool? SVM { get; set; } = null!; | ||
public string? originalObject { get; set; } = null!; | ||
|
||
public IndividualSearchResult() { } | ||
|
||
[SupportedOSPlatform("windows")] | ||
public IndividualSearchResult(AaudUser? aaudUser, LdapUserContact? ldapUserContact) | ||
{ | ||
SVM = false; | ||
originalObject = ""; | ||
if (aaudUser != null) { | ||
MothraId = aaudUser.MothraId; | ||
LoginId = aaudUser.LoginId; | ||
MailId = aaudUser.MailId; | ||
LastName = aaudUser.LastName; | ||
FirstName = aaudUser.FirstName; | ||
MiddleName = aaudUser.MiddleName; | ||
DisplayLastName = aaudUser.DisplayLastName; | ||
DisplayFirstName = aaudUser.DisplayFirstName; | ||
DisplayMiddleName = aaudUser.DisplayMiddleName; | ||
DisplayFullName = aaudUser.DisplayFullName; | ||
Name = aaudUser.DisplayFullName; | ||
CurrentStudent = aaudUser.CurrentStudent; | ||
FutureStudent = aaudUser.FutureStudent; | ||
CurrentEmployee = aaudUser.CurrentEmployee; | ||
FutureEmployee = aaudUser.FutureEmployee; | ||
StudentTerm = aaudUser.StudentTerm; | ||
EmployeeTerm = aaudUser.EmployeeTerm; | ||
PpsId = aaudUser.PpsId; | ||
StudentPKey = aaudUser.StudentPKey; | ||
EmployeePKey = aaudUser.EmployeePKey; | ||
Current = aaudUser.Current; | ||
Future = aaudUser.Future; | ||
IamId = aaudUser.IamId; | ||
Ross = aaudUser.Ross; | ||
SVM = true; | ||
Added = aaudUser.Added; | ||
UserName = aaudUser.LoginId; | ||
} | ||
if (ldapUserContact != null) | ||
{ | ||
Title = ldapUserContact.Title; | ||
//Department = ldapUserContact.Department; | ||
Phone = ldapUserContact.TelephoneNumber; | ||
Mobile = ldapUserContact.Mobile; | ||
UserName = ldapUserContact.Uid; | ||
PostalAddress = (ldapUserContact.PostalAddress ?? "").Replace("$", '\n'.ToString()); | ||
UCDAffiliation = ldapUserContact.UcdPersonAffiliation; | ||
UCDPersonUUID = ldapUserContact.UcdPersonUuid; | ||
if (string.IsNullOrEmpty(DisplayFullName)) | ||
{ | ||
DisplayFullName = ldapUserContact.DisplayName; | ||
} | ||
if (string.IsNullOrEmpty(Name)) | ||
{ | ||
Name = ldapUserContact.DisplayName; | ||
} | ||
} | ||
|
||
using (var context = new Classes.SQLContext.AAUDContext()) | ||
{ | ||
var query = $"SELECT * FROM OPENQUERY(UCDMothra,'SELECT (USERPART || ''@'' || HOSTPART) AS USERATHOST FROM MOTHRA.MAILIDS WHERE MOTHRAID = ''{MothraId}'' AND MAILID = ''{MailId}'' AND MAILSTATUS = ''A'' AND MAILTYPE = ''P''')".ToString(); | ||
var results = context.Database.SqlQuery<string>(FormattableStringFactory.Create(query)).ToList(); | ||
foreach (var r in results) | ||
{ | ||
EmailHost = r.Split("@").Last(); | ||
} | ||
} | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
web/Areas/Directory/Models/IndividualSearchResultCreator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System.Runtime.Versioning; | ||
using Viper.Models.AAUD; | ||
|
||
namespace Viper.Areas.Directory.Models | ||
{ | ||
public class IndividualSearchResultCreator | ||
{ | ||
[SupportedOSPlatform("windows")] | ||
public static IndividualSearchResult CreateIndividualSearchResult(AaudUser? aaudUser, LdapUserContact? ldapUserContact, bool includeDetail=false) | ||
{ | ||
if (includeDetail) | ||
{ | ||
IndividualSearchResultWithIDs indiv = new(); | ||
if (aaudUser != null) | ||
{ | ||
AddAaudUser(indiv, aaudUser); | ||
AddIds(indiv, aaudUser); | ||
} | ||
if (ldapUserContact != null) | ||
{ | ||
AddLdapContact(indiv, ldapUserContact); | ||
} | ||
|
||
return indiv; | ||
} | ||
else | ||
{ | ||
IndividualSearchResult indiv = new(); | ||
if (aaudUser != null) | ||
{ | ||
AddAaudUser(indiv, aaudUser); | ||
} | ||
if (ldapUserContact != null) | ||
{ | ||
AddLdapContact(indiv, ldapUserContact); | ||
} | ||
return indiv; | ||
} | ||
} | ||
|
||
private static void AddAaudUser(IndividualSearchResult indiv, AaudUser aaudUser) | ||
{ | ||
indiv.MothraId = aaudUser.MothraId; | ||
indiv.LoginId = aaudUser.LoginId; | ||
indiv.MailId = aaudUser.MailId; | ||
indiv.LastName = aaudUser.LastName; | ||
indiv.FirstName = aaudUser.FirstName; | ||
indiv.MiddleName = aaudUser.MiddleName; | ||
indiv.DisplayLastName = aaudUser.DisplayLastName; | ||
indiv.DisplayFirstName = aaudUser.DisplayFirstName; | ||
indiv.DisplayMiddleName = aaudUser.DisplayMiddleName; | ||
indiv.DisplayFullName = aaudUser.DisplayFullName; | ||
indiv.Name = aaudUser.DisplayFullName; | ||
indiv.CurrentStudent = aaudUser.CurrentStudent; | ||
indiv.FutureStudent = aaudUser.FutureStudent; | ||
indiv.CurrentEmployee = aaudUser.CurrentEmployee; | ||
indiv.FutureEmployee = aaudUser.FutureEmployee; | ||
indiv.StudentTerm = aaudUser.StudentTerm; | ||
indiv.EmployeeTerm = aaudUser.EmployeeTerm; | ||
indiv.PpsId = aaudUser.PpsId; | ||
indiv.StudentPKey = aaudUser.StudentPKey; | ||
indiv.EmployeePKey = aaudUser.EmployeePKey; | ||
indiv.Current = aaudUser.Current; | ||
indiv.Future = aaudUser.Future; | ||
indiv.IamId = aaudUser.IamId; | ||
indiv.Ross = aaudUser.Ross; | ||
indiv.Added = aaudUser.Added; | ||
} | ||
|
||
private static void AddIds(IndividualSearchResultWithIDs indiv, AaudUser aaudUser) | ||
{ | ||
indiv.SpridenId = aaudUser.SpridenId; | ||
indiv.Pidm = aaudUser.Pidm; | ||
indiv.EmployeeId = aaudUser.EmployeeId; | ||
indiv.VmacsId = aaudUser.VmacsId; | ||
indiv.UnexId = aaudUser.UnexId; | ||
indiv.MivId = aaudUser.MivId; | ||
} | ||
|
||
[SupportedOSPlatform("windows")] | ||
private static void AddLdapContact(IndividualSearchResult indiv, LdapUserContact ldapUserContact) | ||
{ | ||
indiv.Title = ldapUserContact.Title; | ||
indiv.Department = ldapUserContact.Ou; | ||
indiv.Phone = ldapUserContact.TelephoneNumber; | ||
indiv.Mobile = ldapUserContact.Mobile; | ||
indiv.UserName = ldapUserContact.Uid; | ||
if(string.IsNullOrEmpty(indiv.DisplayFullName)) | ||
{ | ||
indiv.DisplayFullName = ldapUserContact.DisplayName; | ||
} | ||
if(string.IsNullOrEmpty(indiv.Name)) | ||
{ | ||
indiv.Name = ldapUserContact.DisplayName; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.