Skip to content

Commit

Permalink
Merge pull request #645 from bcgov/yj
Browse files Browse the repository at this point in the history
chore: create aps user returns id
  • Loading branch information
ychung-mot committed Sep 16, 2024
2 parents 9f5820e + 914f594 commit b6c91e9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 9 deletions.
55 changes: 55 additions & 0 deletions gateway/strdata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,61 @@ services:
config:
header: GW-JWT
include_credential_type: false
- name: strdata-uat
host: uat.strdata.gov.bc.ca
tags: [ns.strdata]
port: 443
protocol: https
retries: 0
routes:
- name: strdata-uat
tags: [ns.strdata]
hosts:
- strdata-uat.api.gov.bc.ca
methods:
- GET
paths: [/api/organizations/strrequirements]
strip_path: false
https_redirect_status_code: 426
path_handling: v0
request_buffering: true
response_buffering: true
plugins:
- name: jwt-keycloak
tags: [ns.strdata]
enabled: true
config:
allowed_iss: [https://test.loginproxy.gov.bc.ca/auth/realms/apigw]
allowed_aud: gateway-strdata
run_on_preflight: true
iss_key_grace_period: 10
maximum_expiration: 0
algorithm: RS256
claims_to_verify:
- exp
uri_param_names:
- jwt
cookie_names: []
scope:
roles:
realm_roles:
client_roles:
anonymous:
consumer_match: true
consumer_match_claim: azp
consumer_match_claim_custom_id: true
consumer_match_ignore_not_found: false
- name: request-transformer
tags: [ns.strdata]
enabled: true
config:
http_method:
- name: kong-upstream-jwt
enabled: true
tags: [ns.strdata]
config:
header: GW-JWT
include_credential_type: false
- name: strdata-prod
host: strdata.gov.bc.ca
tags: [ns.strdata]
Expand Down
4 changes: 2 additions & 2 deletions server/StrDss.Api/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ public async Task<ActionResult> GetBceidUserInfo()
[HttpPost("aps", Name = "CreateApsUser")]
public async Task<ActionResult> CreateApsUser(ApsUserCreateDto dto)
{
var errors = await _userService.CreateApsUserAsync(dto);
var (errors, userId) = await _userService.CreateApsUserAsync(dto);

if (errors.Count > 0)
{
return ValidationUtils.GetValidationErrorResult(errors, ControllerContext);
}

return Ok();
return Ok(userId);
}
}
}
6 changes: 4 additions & 2 deletions server/StrDss.Data/Repositories/UserRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface IUserRepository
Task<List<DropdownStrDto>> GetAccessRequestStatuses();
Task AcceptTermsConditions();
Task UpdateUserNamesAsync(long userId, string firstName, string lastName);
Task CreateApsUserAsync(ApsUserCreateDto dto);
Task<DssUserIdentity> CreateApsUserAsync(ApsUserCreateDto dto);
Task<bool> ApsUserExists(string clientId);
}
public class UserRepository : RepositoryBase<DssUserIdentity>, IUserRepository
Expand Down Expand Up @@ -235,7 +235,7 @@ public async Task UpdateUserNamesAsync(long userId, string firstName, string las
entity.GivenNm = firstName;
}

public async Task CreateApsUserAsync(ApsUserCreateDto dto)
public async Task<DssUserIdentity> CreateApsUserAsync(ApsUserCreateDto dto)
{
dto.FamilyNm = dto.DisplayNm;

Expand All @@ -252,6 +252,8 @@ public async Task CreateApsUserAsync(ApsUserCreateDto dto)
}

await _dbContext.AddAsync(userEntity);

return userEntity;
}

public async Task<bool> ApsUserExists(string clientId)
Expand Down
10 changes: 5 additions & 5 deletions server/StrDss.Service/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface IUserService
Task<UserDto?> GetUserByIdAsync(long userId);
Task<Dictionary<string, List<string>>> UpdateUserAsync(UserUpdateDto dto);
Task<BceidAccount?> GetBceidUserInfo();
Task<Dictionary<string, List<string>>> CreateApsUserAsync(ApsUserCreateDto dto);
Task<(Dictionary<string, List<string>>, long)> CreateApsUserAsync(ApsUserCreateDto dto);
Task<(UserDto? user, List<string> permissions)> GetUserByDisplayNameAsync(string displayName);
}
public class UserService : ServiceBase, IUserService
Expand Down Expand Up @@ -529,7 +529,7 @@ private async Task ValidateOrgAndRoles(IOrgRoles dto, Dictionary<string, List<st
return null;
}

public async Task<Dictionary<string, List<string>>> CreateApsUserAsync(ApsUserCreateDto dto)
public async Task<(Dictionary<string, List<string>>, long)> CreateApsUserAsync(ApsUserCreateDto dto)
{
var errors = new Dictionary<string, List<string>>();

Expand All @@ -545,13 +545,13 @@ public async Task<Dictionary<string, List<string>>> CreateApsUserAsync(ApsUserCr
errors.AddItem("client_id", $"The client ID {dto.DisplayNm} already exists.");
}

if (errors.Any()) return errors;
if (errors.Any()) return (errors, 0);

await _userRepo.CreateApsUserAsync(dto);
var entity = await _userRepo.CreateApsUserAsync(dto);

_unitOfWork.Commit();

return errors;
return (errors, entity.UserIdentityId);
}
}
}

0 comments on commit b6c91e9

Please sign in to comment.