Skip to content

Commit

Permalink
feat(DbUpdate)!- View for CompanyLinkedServiceAccounts (#111)
Browse files Browse the repository at this point in the history
* add view CompanyLinkedServiceAccounts that determines which companyIds are eligible to reset a serviceAccount
* add Unit Test for view
Refs: CPLP-2841
---------
Co-authored-by: Phil Schneider <[email protected]>
Reviewed-By: Norbert Truchsess <[email protected]>
  • Loading branch information
qxz2mqe authored Jul 12, 2023
1 parent c38a7c4 commit f5d83f4
Show file tree
Hide file tree
Showing 12 changed files with 7,165 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface IServiceAccountBusinessLogic
Task<int> DeleteOwnCompanyServiceAccountAsync(Guid serviceAccountId, Guid companyId);
Task<ServiceAccountConnectorOfferData> GetOwnCompanyServiceAccountDetailsAsync(Guid serviceAccountId, Guid companyId);
Task<ServiceAccountDetails> UpdateOwnCompanyServiceAccountDetailsAsync(Guid serviceAccountId, ServiceAccountEditableDetails serviceAccountDetails, Guid companyId);
Task<ServiceAccountDetails> ResetOwnCompanyServiceAccountSecretAsync(Guid serviceAccountId, Guid companyId);
Task<ServiceAccountDetails> ExecuteResetOwnCompanyServiceAccountSecretAsync(Guid serviceAccountId, Guid companyId);
Task<Pagination.Response<CompanyServiceAccountData>> GetOwnCompanyServiceAccountsDataAsync(int page, int size, Guid companyId);
IAsyncEnumerable<UserRoleWithDescription> GetServiceAccountRolesAsync(Guid companyId, string? languageShortName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,16 @@ public async Task<ServiceAccountConnectorOfferData> GetOwnCompanyServiceAccountD
result.SubscriptionId);
}

public async Task<ServiceAccountDetails> ResetOwnCompanyServiceAccountSecretAsync(Guid serviceAccountId, Guid companyId)
public async Task<ServiceAccountDetails> ExecuteResetOwnCompanyServiceAccountSecretAsync(Guid serviceAccountId, Guid companyId)
{
if (!await _portalRepositories.GetInstance<IServiceAccountRepository>().IsCompanyServiceAccountLinkedCompany(companyId).ConfigureAwait(false))
{
throw new ForbiddenException($"The company ID is neither the owner nor the provider of the technical user");
}
return await ResetOwnCompanyServiceAccountSecretAsync(serviceAccountId, companyId);
}

private async Task<ServiceAccountDetails> ResetOwnCompanyServiceAccountSecretAsync(Guid serviceAccountId, Guid companyId)
{
var result = await _portalRepositories.GetInstance<IServiceAccountRepository>().GetOwnCompanyServiceAccountDetailedDataUntrackedAsync(serviceAccountId, companyId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public Task<ServiceAccountDetails> PutServiceAccountDetails([FromRoute] Guid ser
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status409Conflict)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status502BadGateway)]
public Task<ServiceAccountDetails> ResetServiceAccountCredentials([FromRoute] Guid serviceAccountId) =>
this.WithCompanyId(companyId => _logic.ResetOwnCompanyServiceAccountSecretAsync(serviceAccountId, companyId));
this.WithCompanyId(companyId => _logic.ExecuteResetOwnCompanyServiceAccountSecretAsync(serviceAccountId, companyId));

/// <summary>
/// Gets the service account data as pagination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ CompanyServiceAccount CreateCompanyServiceAccount(Guid identityId,
Task<CompanyServiceAccountDetailedData?> GetOwnCompanyServiceAccountDetailedDataUntrackedAsync(Guid serviceAccountId, Guid companyId);
Func<int, int, Task<Pagination.Source<CompanyServiceAccountData>?>> GetOwnCompanyServiceAccountsUntracked(Guid userCompanyId);
Task<bool> CheckActiveServiceAccountExistsForCompanyAsync(Guid technicalUserId, Guid companyId);
Task<bool> IsCompanyServiceAccountLinkedCompany(Guid companyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,9 @@ public Task<bool> CheckActiveServiceAccountExistsForCompanyAsync(Guid technicalU
sa.Identity!.UserStatusId == UserStatusId.ACTIVE &&
sa.Identity.CompanyId == companyId)
.AnyAsync();

public Task<bool> IsCompanyServiceAccountLinkedCompany(Guid companyId) =>
_dbContext.CompanyLinkedServiceAccounts
.Where(x => x.Provider == companyId || x.Owners == companyId)
.AnyAsync();
}
Loading

0 comments on commit f5d83f4

Please sign in to comment.