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

psso-add org mapping code #659

Merged
merged 1 commit into from
Jan 5, 2024
Merged
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
15 changes: 9 additions & 6 deletions src/Spd.Manager.Membership/UserProfile/UserProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ public async Task<IdirUserProfileResponse> Handle(ManageIdirUserCommand cmd, Can
});
_logger.LogDebug($"userGuid = {cmd.IdirUserIdentity.UserGuid}");
_logger.LogDebug($"from webservice orgCode = {idirDetail.MinistryCode}");

OrgsQryResult orgResult = (OrgsQryResult)await _orgRepository.QueryOrgAsync(new OrgsQry(OrgCode: idirDetail.MinistryCode), ct);
Guid orgId = orgId = orgResult.OrgResults?.FirstOrDefault()?.Id ?? SpdConstants.BC_GOV_ORG_ID;

var existingIdentities = await _idRepository.Query(new IdentityQry(cmd.IdirUserIdentity.UserGuid, null, IdentityProviderTypeEnum.Idir), ct);
var identity = existingIdentities.Items.FirstOrDefault();
Guid? identityId = identity?.Id;
Expand All @@ -182,7 +186,7 @@ public async Task<IdirUserProfileResponse> Handle(ManageIdirUserCommand cmd, Can
bool isFirstTimeLogin = false;
if (identity == null)
{
var id = await _idRepository.Manage(new CreateIdentityCmd(cmd.IdirUserIdentity.UserGuid, SpdConstants.BC_GOV_ORG_ID, IdentityProviderTypeEnum.Idir), ct);
var id = await _idRepository.Manage(new CreateIdentityCmd(cmd.IdirUserIdentity.UserGuid, orgId, IdentityProviderTypeEnum.Idir), ct);
identityId = id?.Id;
isFirstTimeLogin = true;
}
Expand All @@ -199,7 +203,7 @@ public async Task<IdirUserProfileResponse> Handle(ManageIdirUserCommand cmd, Can
{
CreatePortalUserCmd createUserCmd = new CreatePortalUserCmd()
{
OrgId = SpdConstants.BC_GOV_ORG_ID,
OrgId = orgId,
EmailAddress = cmd.IdirUserIdentity.Email,
FirstName = cmd.IdirUserIdentity.FirstName,
LastName = cmd.IdirUserIdentity.LastName,
Expand All @@ -213,7 +217,7 @@ public async Task<IdirUserProfileResponse> Handle(ManageIdirUserCommand cmd, Can
UpdatePortalUserCmd updateUserCmd = new UpdatePortalUserCmd()
{
Id = result.Id,
OrgId = SpdConstants.BC_GOV_ORG_ID,
OrgId = orgId,
EmailAddress = cmd.IdirUserIdentity.Email,
FirstName = cmd.IdirUserIdentity.FirstName,
LastName = cmd.IdirUserIdentity.LastName,
Expand All @@ -227,8 +231,7 @@ public async Task<IdirUserProfileResponse> Handle(ManageIdirUserCommand cmd, Can
response.UserDisplayName = cmd.IdirUserIdentity?.DisplayName;
response.IdirUserName = cmd.IdirUserIdentity?.IdirUserName;
response.IsFirstTimeLogin = isFirstTimeLogin;
//todo: temp hardcode
response.OrgId = Guid.Parse("64540211-d346-ee11-b845-00505683fbf4");
response.OrgId = orgId;
return response;
}
else
Expand All @@ -254,7 +257,7 @@ public async Task<IdirUserProfileResponse> Handle(ManageIdirUserCommand cmd, Can
response.UserGuid = qry.IdirUserIdentity?.UserGuid;
response.UserDisplayName = qry.IdirUserIdentity?.DisplayName;
response.IdirUserName = qry.IdirUserIdentity?.IdirUserName;
response.OrgId = Guid.Parse("64540211-d346-ee11-b845-00505683fbf4");
response.OrgId = result.OrganizationId ?? SpdConstants.BC_GOV_ORG_ID;
return response;
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Spd.Resource.Organizations/Org/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public record OrgManageResult(OrgResult Org);

//query
public abstract record OrgQry;
public record OrgsQry(Guid? OrgGuid, Guid? ParentOrgId = null, bool IncludeInactive = false) : OrgQry;
public record OrgsQry(Guid? OrgGuid = null, Guid? ParentOrgId = null, bool IncludeInactive = false, string? OrgCode = null) : OrgQry;
public record OrgByIdentifierQry(Guid? OrgId, string? AccessCode = null) : OrgQry;
public record SearchOrgQry : OrgQry
{
Expand Down
4 changes: 3 additions & 1 deletion src/Spd.Resource.Organizations/Org/OrgRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ private async Task<OrgsQryResult> GetOrgsAsync(OrgsQry query, CancellationToken
accounts = accounts.Where(a => a.spd_orgguid == query.OrgGuid.ToString());
if (query.ParentOrgId != null)
accounts = accounts.Where(a => a._parentaccountid_value == query.ParentOrgId);

if (query.OrgCode != null)
accounts = accounts.Where(a => a.spd_orgcode == query.OrgCode);

return new OrgsQryResult(_mapper.Map<IEnumerable<OrgResult>>(accounts.ToList()));
}

Expand Down
Loading