Skip to content
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
29 changes: 14 additions & 15 deletions src/Controllers/AnalyzeModelController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
[Route("api/[action]")]
[ApiController]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
public class AnalyzeModelController : ControllerBase
public class AnalyzeModelController(
IAnalyzeModelService analyzeModelService,
IAuthenticationService authenticationService) : ControllerBase
{
private readonly IAnalyzeModelService _analyzeModelService;
private readonly IAuthenticationService _authenticationService;
private readonly IAnalyzeModelService _analyzeModelService = analyzeModelService;
private readonly IAuthenticationService _authenticationService = authenticationService;
private readonly SaveFileDialog _exportVpaxDialog = new()
{
Title = "Save VPAX",
Expand All @@ -30,12 +32,6 @@ public class AnalyzeModelController : ControllerBase
ValidateNames = true
};

public AnalyzeModelController(IAnalyzeModelService analyzeModelService, IAuthenticationService authenticationService)
{
_analyzeModelService = analyzeModelService;
_authenticationService = authenticationService;
}

/// <summary>
/// Returns a database model from the VPAX file provided as multipart form data.
/// An optional obfuscation dictionary file can be included to deobfuscate the VPAX.
Expand Down Expand Up @@ -85,10 +81,11 @@ public IActionResult GetDatabase(PBIDesktopReport report, CancellationToken canc
[ProducesDefaultResponseType]
public async Task<IActionResult> GetDatabase(PBICloudDataset dataset, CancellationToken cancellationToken)
{
if (await _authenticationService.IsPBICloudSignInRequiredAsync(cancellationToken))
var session = await _authenticationService.EnsureSignedInAsync(cancellationToken);
if (session is null)
return Unauthorized();

var database = _analyzeModelService.GetDatabase(dataset, _authenticationService.PBICloudAuthentication.AccessToken, cancellationToken);
var database = _analyzeModelService.GetDatabase(dataset, session.AuthenticationResult.AccessToken, cancellationToken);
return Ok(database);
}

Expand All @@ -105,10 +102,11 @@ public async Task<IActionResult> GetDatabase(PBICloudDataset dataset, Cancellati
[ProducesDefaultResponseType]
public async Task<IActionResult> GetDatasets(CancellationToken cancellationToken)
{
if (await _authenticationService.IsPBICloudSignInRequiredAsync(cancellationToken))
var session = await _authenticationService.EnsureSignedInAsync(cancellationToken);
if (session is null)
return Unauthorized();

var datasets = await _analyzeModelService.GetDatasetsAsync(cancellationToken);
var datasets = await _analyzeModelService.GetDatasetsAsync(session, cancellationToken);
return Ok(datasets);
}

Expand Down Expand Up @@ -202,12 +200,13 @@ public async Task<IActionResult> ExportVpax(PBICloudDataset dataset, Cancellatio
if (dialogResult != DialogResult.OK)
return NoContent();

if (await _authenticationService.IsPBICloudSignInRequiredAsync(cancellationToken))
var session = await _authenticationService.EnsureSignedInAsync(cancellationToken);
if (session is null)
return Unauthorized();

var path = _exportVpaxDialog.FileName!;
var mode = _exportVpaxDialog.FilterIndex == 1 ? ExportVpaxMode.Default : ExportVpaxMode.Obfuscated;
var accessToken = _authenticationService.PBICloudAuthentication.AccessToken;
var accessToken = session.AuthenticationResult.AccessToken;

_analyzeModelService.ExportVpax(dataset, accessToken, mode, path, cancellationToken);
return Ok();
Expand Down
26 changes: 15 additions & 11 deletions src/Controllers/AuthenticationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
{
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Sqlbi.Bravo.Infrastructure.Services.PowerBI;
using Sqlbi.Bravo.Infrastructure;
using Sqlbi.Bravo.Infrastructure.PowerBI.Cloud;
using Sqlbi.Bravo.Models;
using Sqlbi.Bravo.Models.Authentication;
using Sqlbi.Bravo.Services;

Expand All @@ -14,13 +16,11 @@
[ApiController]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
public sealed class AuthenticationController(
IPBICloudAuthenticationService pbicloudAuthenticationService,
IPBICloudService pbicloudService,
ICloudApiClient cloudApiClient,
IAuthenticationService authenticationService) : ControllerBase
{
private readonly IAuthenticationService _authenticationService = authenticationService;
private readonly IPBICloudAuthenticationService _pbicloudAuthenticationService = pbicloudAuthenticationService;
private readonly IPBICloudService _pbicloudService = pbicloudService;
private readonly ICloudApiClient _cloudApiClient = cloudApiClient;

/// <summary>
/// Returns the list of available PowerBI cloud environments for the specified email account.
Expand All @@ -35,10 +35,13 @@ public async Task<IActionResult> GetEnvironmentsAsync(
[FromQuery] GetEnvironmentsRequest request,
CancellationToken cancellationToken)
{
var environments = await _pbicloudAuthenticationService.GetEnvironmentsAsync(
var environments = await _authenticationService.GetEnvironmentsAsync(
request.Email,
cancellationToken);

if (AppEnvironment.IsDiagnosticLevelVerbose)
AppEnvironment.AddDiagnostics(DiagnosticMessageType.Json, name: $"{nameof(AuthenticationController)}.{nameof(GetEnvironmentsAsync)}", JsonSerializer.Serialize(environments));

var response = new GetEnvironmentsResponse(environments);
return Ok(response);
}
Expand All @@ -56,12 +59,12 @@ public async Task<IActionResult> SignInAsync(
SignInRequest request,
CancellationToken cancellationToken)
{
await _authenticationService.PBICloudSignInAsync(
var session = await _authenticationService.SignInAsync(
request.Email,
request.Environment.ToModel(),
cancellationToken);

var response = new SignInResponse(_authenticationService.PBICloudAuthentication.Account);
var response = new SignInResponse(session.AuthenticationResult);
return Ok(response);
}

Expand All @@ -75,7 +78,7 @@ await _authenticationService.PBICloudSignInAsync(
[ProducesDefaultResponseType]
public async Task<IActionResult> SignOutAsync(CancellationToken cancellationToken)
{
await _authenticationService.PBICloudSignOutAsync(cancellationToken);
await _authenticationService.SignOutAsync(cancellationToken);
return Ok();
}

Expand All @@ -94,10 +97,11 @@ public async Task<IActionResult> SignOutAsync(CancellationToken cancellationToke
[ProducesDefaultResponseType]
public async Task<IActionResult> GetUserAvatarAsync(CancellationToken cancellationToken)
{
if (await _authenticationService.IsPBICloudSignInRequiredAsync(cancellationToken))
var session = await _authenticationService.EnsureSignedInAsync(cancellationToken);
if (session is null)
return Unauthorized();

var avatar = await _pbicloudService.GetAccountAvatarAsync();
var avatar = await _cloudApiClient.GetUserPhotoAsync(session, cancellationToken);
if (avatar is null)
return NotFound();

Expand Down
10 changes: 6 additions & 4 deletions src/Controllers/ExportDataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public IActionResult ExportDelimitedTextFile(ExportDelimitedTextFromPBIReportReq
[ProducesDefaultResponseType]
public async Task<IActionResult> ExportDelimitedTextFile(ExportDelimitedTextFromPBICloudDatasetRequest request, CancellationToken cancellationToken)
{
if (await _authenticationService.IsPBICloudSignInRequiredAsync(cancellationToken))
var session = await _authenticationService.EnsureSignedInAsync(cancellationToken);
if (session is null)
return Unauthorized();

if (WindowDialogHelper.BrowseFolderDialog(out var path, cancellationToken))
Expand All @@ -86,7 +87,7 @@ public async Task<IActionResult> ExportDelimitedTextFile(ExportDelimitedTextFrom
return NoContent();
}

var job = _exportDataService.ExportDelimitedTextFile(request.Dataset!, request.Settings!, path, _authenticationService.PBICloudAuthentication.AccessToken, cancellationToken);
var job = _exportDataService.ExportDelimitedTextFile(request.Dataset!, request.Settings!, path, session.AuthenticationResult.AccessToken, cancellationToken);
return Ok(job);
}

Expand Down Expand Up @@ -130,12 +131,13 @@ public IActionResult ExportExcelFile(ExportExcelFromPBIReportRequest request, Ca
[ProducesDefaultResponseType]
public async Task<IActionResult> ExportExcelFile(ExportExcelFromPBICloudDatasetRequest request, CancellationToken cancellationToken)
{
if (await _authenticationService.IsPBICloudSignInRequiredAsync(cancellationToken))
var session = await _authenticationService.EnsureSignedInAsync(cancellationToken);
if (session is null)
return Unauthorized();

if (WindowDialogHelper.SaveFileDialog(fileName: request.Dataset!.DisplayName, filter: null, defaultExt: "XLSX", out var path, cancellationToken))
{
var job = _exportDataService.ExportExcelFile(request.Dataset, request.Settings!, path, _authenticationService.PBICloudAuthentication.AccessToken, cancellationToken);
var job = _exportDataService.ExportExcelFile(request.Dataset, request.Settings!, path, session.AuthenticationResult.AccessToken, cancellationToken);
return Ok(job);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Controllers/FormatDaxController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ public IActionResult Update(UpdatePBIDesktopReportRequest request)
[ProducesDefaultResponseType]
public async Task<IActionResult> Update(UpdatePBICloudDatasetRequest request, CancellationToken cancellationToken)
{
if (await _authenticationService.IsPBICloudSignInRequiredAsync(cancellationToken))
var session = await _authenticationService.EnsureSignedInAsync(cancellationToken);
if (session is null)
return Unauthorized();

var updateResult = _formatDaxService.Update(request.Dataset!, request.Measures!, _authenticationService.PBICloudAuthentication.AccessToken);
var updateResult = _formatDaxService.Update(request.Dataset!, request.Measures!, session.AuthenticationResult.AccessToken);
return Ok(updateResult);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@
[assembly: SuppressMessage("Style", "IDE0042:Deconstruct variable declaration", Justification = "<Pending>", Scope = "member", Target = "~M:Sqlbi.Bravo.Models.ManageDates.DateConfiguration.CreateFrom(Dax.Template.Package)~Sqlbi.Bravo.Models.ManageDates.DateConfiguration")]
[assembly: SuppressMessage("Style", "IDE0042:Deconstruct variable declaration", Justification = "<Pending>", Scope = "member", Target = "~M:Sqlbi.Bravo.Models.ManageDates.DateConfiguration.CopyTo(Dax.Template.Tables.TemplateConfiguration)")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>", Scope = "member", Target = "~M:Sqlbi.Bravo.Infrastructure.AppWindow.WebViewLog(System.String)")]
[assembly: SuppressMessage("Style", "IDE0290:Use primary constructor", Justification = "<Pending>", Scope = "member", Target = "~M:Sqlbi.Bravo.Infrastructure.PowerBI.Cloud.Configuration.CloudConfigurationService.#ctor(System.Net.Http.IHttpClientFactory,Sqlbi.Bravo.Infrastructure.PowerBI.ILocalConfigurationReader)")]
17 changes: 0 additions & 17 deletions src/Infrastructure/Contracts/PBIConstants.cs

This file was deleted.

115 changes: 0 additions & 115 deletions src/Infrastructure/Contracts/PBIDesktop/LocalClientSite.cs

This file was deleted.

28 changes: 0 additions & 28 deletions src/Infrastructure/Extensions/ServiceCollectionExtensions.cs

This file was deleted.

Loading
Loading