Skip to content

Commit

Permalink
Merge pull request #14 from ucdavis/feature/directory
Browse files Browse the repository at this point in the history
Addresses most of Brandon's concerns
  • Loading branch information
JasonRobertFrancis authored Jul 24, 2024
2 parents 2af7d6d + ed1f321 commit cea462e
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 95 deletions.
19 changes: 12 additions & 7 deletions web/Areas/Directory/Controllers/DirectoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ public async Task<ActionResult<IEnumerable<IndividualSearchResult>>> Get(string

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];
}
if (vm != null && vm.item != null && vm.item.Nextel != null) results.Last().Nextel = vm.item.Nextel[0];
if (vm != null && vm.item != null && vm.item.LDPager != null) results.Last().LDPager = vm.item.LDPager[0];
if (vm != null && vm.item != null && vm.item.Unit != null) results.Last().Department = vm.item.Unit[0];

});
return results;
}
Expand Down Expand Up @@ -125,11 +124,17 @@ public async Task<ActionResult<IEnumerable<IndividualSearchResult>>> GetUCD(stri
bool hasDetailPermission = UserHelper.HasPermission(_rapsContext, currentUser, "SVMSecure.DirectoryDetail");
foreach (var l in ldap)
{
AaudUser? userInfo = individuals.Find(m => m.IamId == l.UcdPersonIamId);
AaudUser? userInfo = individuals.Find(m => m.IamId == l.IamId);
results.Add(hasDetailPermission
? new IndividualSearchResultWithIDs(userInfo, l)
: new IndividualSearchResult(userInfo, l));
};

var vmsearch = VMACSService.Search(results.Last().LoginId);
var vm = vmsearch.Result;
if (vm != null && vm.item != null && vm.item.Nextel != null) results.Last().Nextel = vm.item.Nextel[0];
if (vm != null && vm.item != null && vm.item.LDPager != null) results.Last().LDPager = vm.item.LDPager[0];
if (vm != null && vm.item != null && vm.item.Unit != null) results.Last().Department = vm.item.Unit[0];
};
return results;
}

Expand Down
28 changes: 20 additions & 8 deletions web/Areas/Directory/Models/IndividualSearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ 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? Email { 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;
Expand Down Expand Up @@ -58,7 +58,8 @@ public IndividualSearchResult(AaudUser? aaudUser, LdapUserContact? ldapUserConta
if (aaudUser != null) {
MothraId = aaudUser.MothraId;
LoginId = aaudUser.LoginId;
MailId = aaudUser.MailId;
Email = aaudUser.MailId;
MailId = aaudUser.MailId?.Split("@").First();
LastName = aaudUser.LastName;
FirstName = aaudUser.FirstName;
MiddleName = aaudUser.MiddleName;
Expand Down Expand Up @@ -86,14 +87,20 @@ public IndividualSearchResult(AaudUser? aaudUser, LdapUserContact? ldapUserConta
}
if (ldapUserContact != null)
{
// displayname=Francisco Javier Acosta,ucdPersonAffiliation=student:undergraduate,ucdPersonUUID=02198608,[email protected],ucdPersonPIDM=3817514,ucdStudentSID=921084299,sn=Acosta,givenName=Francisco,employeeNumber=10665044,ucdStudentLevel=Sophomore,title=STDT 2,ucdPersonIAMID=1000459572,uid=fcobay04,ou=STUDENT HOUSING DINING SVCS
DisplayFullName = ldapUserContact.DisplayName;
FirstName = ldapUserContact.GivenName;
MiddleName = ldapUserContact.MiddleName;
LastName = ldapUserContact.Sn;
Title = ldapUserContact.Title;
//Department = ldapUserContact.Department;
Department = ldapUserContact.Ou;
Phone = ldapUserContact.TelephoneNumber;
Mobile = ldapUserContact.Mobile;
Email = ldapUserContact.Mail;
MailId = ldapUserContact.Mail?.Split("@").First();
UserName = ldapUserContact.Uid;
PostalAddress = (ldapUserContact.PostalAddress ?? "").Replace("$", '\n'.ToString());
UCDAffiliation = ldapUserContact.UcdPersonAffiliation;
UCDPersonUUID = ldapUserContact.UcdPersonUuid;
if (string.IsNullOrEmpty(DisplayFullName))
{
DisplayFullName = ldapUserContact.DisplayName;
Expand All @@ -102,15 +109,20 @@ public IndividualSearchResult(AaudUser? aaudUser, LdapUserContact? ldapUserConta
{
Name = ldapUserContact.DisplayName;
}
originalObject = ldapUserContact.originalObject;
}


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)
if (MailId != null)
{
EmailHost = r.Split("@").Last();
var query = $"SELECT * FROM OPENQUERY(UCDMothra,'SELECT (USERPART || ''@'' || HOSTPART) AS USERATHOST FROM MOTHRA.MAILIDS WHERE 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();
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions web/Areas/Directory/Models/IndividualSearchResultCreator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Runtime.Versioning;
using Viper.Models.AAUD;
using System.Text.Json;

namespace Viper.Areas.Directory.Models
{
Expand Down Expand Up @@ -40,6 +41,7 @@ public static IndividualSearchResult CreateIndividualSearchResult(AaudUser? aaud

private static void AddAaudUser(IndividualSearchResult indiv, AaudUser aaudUser)
{
indiv.originalObject = JsonSerializer.Serialize(aaudUser);
indiv.MothraId = aaudUser.MothraId;
indiv.LoginId = aaudUser.LoginId;
indiv.MailId = aaudUser.MailId;
Expand Down Expand Up @@ -80,6 +82,7 @@ private static void AddIds(IndividualSearchResultWithIDs indiv, AaudUser aaudUse
[SupportedOSPlatform("windows")]
private static void AddLdapContact(IndividualSearchResult indiv, LdapUserContact ldapUserContact)
{
indiv.originalObject = System.Text.Json.JsonSerializer.Serialize(ldapUserContact);
indiv.Title = ldapUserContact.Title;
indiv.Department = ldapUserContact.Ou;
indiv.Phone = ldapUserContact.TelephoneNumber;
Expand Down
9 changes: 6 additions & 3 deletions web/Areas/Directory/Models/IndividualSearchResultWithIDs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ public IndividualSearchResultWithIDs(AaudUser? aaudUser, LdapUserContact? ldapUs
EmployeeId = aaudUser.EmployeeId;
VmacsId = aaudUser.VmacsId;
UnexId = aaudUser.UnexId;
MothraId = aaudUser.MothraId;
IamId = aaudUser.IamId;
MivId = aaudUser.MivId;
}
else if(ldapUserContact != null)
}
else if(ldapUserContact != null)
{
Title = ldapUserContact.Title;
Department = ldapUserContact.Ou;
Expand All @@ -46,7 +48,8 @@ public IndividualSearchResultWithIDs(AaudUser? aaudUser, LdapUserContact? ldapUs
UserName = ldapUserContact.Uid;
PostalAddress = (ldapUserContact.PostalAddress ?? "").Replace("$", '\n'.ToString());
UCDAffiliation = ldapUserContact.UcdPersonAffiliation;
UCDPersonUUID = ldapUserContact.UcdPersonUuid;
MothraId = ldapUserContact.MothraId;
IamId = ldapUserContact.IamId;
if (string.IsNullOrEmpty(DisplayFullName))
{
DisplayFullName = ldapUserContact.DisplayName;
Expand Down
18 changes: 11 additions & 7 deletions web/Areas/Directory/Models/LdapUserContact.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.DirectoryServices;
using System.DirectoryServices.Protocols;
using System.Linq.Dynamic.Core;
Expand Down Expand Up @@ -29,9 +30,10 @@ public class LdapUserContact
public string UcdStudentSid { get; set; } = null!;
public string UcdPersonPidm { get; set; } = null!;
public string EmployeeNumber { get; set; } = null!;
public string UcdPersonUuid { get; set; } = null!;
public string UcdPersonIamId { get; set; } = null!;
public string MothraId { get; set; } = null!;
public string IamId { get; set; } = null!;
public string UcdPersonAffiliation { get; set; } = null!;
public string originalObject { get; set; } = null!;

/*
Expand Down Expand Up @@ -297,9 +299,11 @@ public LdapUserContact(SearchResult? ldapSearchResult)

public LdapUserContact(SearchResultEntry entry)
{
var or = new List<string>();
foreach (DirectoryAttribute attr in entry.Attributes.Values)
{
var v = attr[0];
or.Add(attr.Name + "=" + v.ToString());
switch (attr.Name)
{
case "uid": Uid = v.ToString(); break;
Expand All @@ -309,7 +313,7 @@ public LdapUserContact(SearchResultEntry entry)

case "givenName": GivenName = v.ToString(); break;
case "middleName": MiddleName = v.ToString(); break;
case "displayName": DisplayName = v.ToString(); break;
case "displayname": DisplayName = v.ToString(); break;
case "eduPersonNickname": EduPersonNickname = v.ToString(); break;

case "title": Title = v.ToString(); break;
Expand All @@ -318,18 +322,18 @@ public LdapUserContact(SearchResultEntry entry)
case "mobile": Mobile = v.ToString(); break;
case "mail": Mail = v.ToString(); break;

case "employeeNumber": EmployeeNumber = v.ToString(); break;
case "ucdStudentLevel": UcdStudentLevel = v.ToString(); break;
case "ucdStudentSID": UcdStudentSid = v.ToString(); break;
case "ucdPersonPIDM": UcdPersonPidm = v.ToString(); break;
case "employeeNumber": EmployeeNumber = v.ToString(); break;
case "ucdPersonUUID": UcdPersonUuid = v.ToString(); break;
case "ucdPersonIAMID": UcdPersonIamId = v.ToString(); break;
case "ucdPersonUUID": MothraId = v.ToString(); break;
case "ucdPersonIAMID": IamId = v.ToString(); break;
case "ucdPersonAffiliation": UcdPersonAffiliation = v.ToString(); break;

default: break;
}

}
originalObject = string.Join(",", or);
}
}
}
5 changes: 3 additions & 2 deletions web/Areas/Directory/Services/VMACSService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public VMACSService() { }
/// <returns></returns>
public static async Task<VMACSQuery?> Search (String? loginID)
{
string request = $"/trust/query.xml?dbfile=3&index=CampusLoginId&find={loginID}&format=CHRIS4&AUTH=06232005".ToString();

string request = $"/trust/query.xml?dbfile=3&index=CampusLoginId&find={loginID}&format=CHRIS4&AUTH=06232005".ToString();
using HttpResponseMessage response = await sharedClient.GetAsync(request);
if (response.IsSuccessStatusCode == false){
return null;
Expand All @@ -38,7 +39,7 @@ public VMACSService() { }
var serializer = new XmlSerializer(typeof(VMACSQuery));
//return Encoding.ASCII.GetString(stream.ToArray());
var vmacs_api = (VMACSQuery?)serializer.Deserialize(stream);
if (vmacs_api != null && vmacs_api.item != null && vmacs_api.item.Nextel != null)
if (vmacs_api != null && vmacs_api.item != null)
{
return vmacs_api;
}
Expand Down
Loading

0 comments on commit cea462e

Please sign in to comment.