Skip to content

Commit

Permalink
feat: add thirdPartyUser supports update claimData
Browse files Browse the repository at this point in the history
  • Loading branch information
wzh425 committed May 8, 2024
1 parent 38b9895 commit d0dbcc1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Masa.Auth.Service.Admin.Application.Subjects.Commands;

public record AddThirdPartyUserCommand(AddThirdPartyUserDto ThirdPartyUser, bool WhenExisReturn = false) : Command
public record AddThirdPartyUserCommand(AddThirdPartyUserDto ThirdPartyUser, bool WhenExisReturn = false, bool WhenExisUpdateClaimData = false) : Command
{
public UserModel Result { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Masa.Auth.Service.Admin.Application.Subjects.Commands;

public record AddThirdPartyUserExternalCommand(AddThirdPartyUserModel ThirdPartyUser, bool WhenExisReturn = false) : Command
public record AddThirdPartyUserExternalCommand(AddThirdPartyUserModel ThirdPartyUser, bool WhenExisReturn = false, bool WhenExisUpdateClaimData = false) : Command
{
public UserModel Result { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,21 @@ public async Task AddThirdPartyUserAsync(AddThirdPartyUserCommand command)
var thirdPartyUserDto = command.ThirdPartyUser;
var (thirdPartyUser, exception) = await _thirdPartyUserDomainService.VerifyRepeatAsync(thirdPartyUserDto.ThirdPartyIdpId, thirdPartyUserDto.ThridPartyIdentity);

if (command.WhenExisReturn && thirdPartyUser != null)
if (thirdPartyUser != null)
{
command.Result = thirdPartyUser.User.Adapt<UserModel>();
return;
if (command.WhenExisUpdateClaimData)
{
thirdPartyUser.UpdateClaimData(thirdPartyUserDto.ClaimData);
await _thirdPartyUserRepository.UpdateAsync(thirdPartyUser);
}

if (command.WhenExisReturn)
{
command.Result = thirdPartyUser.User.Adapt<UserModel>();
return;
}
}

if (exception is not null)
{
throw exception;
Expand Down Expand Up @@ -183,7 +193,7 @@ public async Task AddThirdPartyUserExternalAsync(AddThirdPartyUserExternalComman
addThirdPartyUserDto.IsLdap = true;
}

var addThirdPartyUserCommand = new AddThirdPartyUserCommand(addThirdPartyUserDto, command.WhenExisReturn);
var addThirdPartyUserCommand = new AddThirdPartyUserCommand(addThirdPartyUserDto, command.WhenExisReturn, command.WhenExisUpdateClaimData);
await _eventBus.PublishAsync(addThirdPartyUserCommand);
command.Result = addThirdPartyUserCommand.Result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ private async Task<UserModel> UpsertThirdPartyUserExternalAsync(IEventBus eventB
private async Task<UserModel> AddThirdPartyUserAsync(
IEventBus eventBus,
[FromQuery] bool whenExistReturn,
[FromQuery] bool whenExisUpdateClaimData,
AddThirdPartyUserModel model)
{
var query = new AddThirdPartyUserExternalCommand(model, whenExistReturn);
var query = new AddThirdPartyUserExternalCommand(model, whenExistReturn, whenExisUpdateClaimData);
await eventBus.PublishAsync(query);
return query.Result;
}
Expand Down

0 comments on commit d0dbcc1

Please sign in to comment.