From fbf908c0325255fb8d683537b0525319d359fbdf Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 20 Sep 2023 22:55:37 +0200 Subject: [PATCH] Workshop - Fixed email not being detected as verified Settings - Fixed new releases not loading when there are more than 20 --- .../Settings/Tabs/ReleasesTabViewModel.cs | 17 ++++++++--------- .../Steps/LoginStepViewModel.cs | 3 +-- .../Steps/UploadStepViewModel.cs | 3 ++- .../Steps/ValidateEmailStepViewModel.cs | 4 +--- .../Steps/WelcomeStepViewModel.cs | 2 +- .../Queries/GetReleases.graphql | 10 +++------- .../Services/AuthenticationService.cs | 7 +++++++ .../Interfaces/IAuthenticationService.cs | 1 + 8 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/Artemis.UI/Screens/Settings/Tabs/ReleasesTabViewModel.cs b/src/Artemis.UI/Screens/Settings/Tabs/ReleasesTabViewModel.cs index d316b62a8..aeb214465 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/ReleasesTabViewModel.cs +++ b/src/Artemis.UI/Screens/Settings/Tabs/ReleasesTabViewModel.cs @@ -31,7 +31,6 @@ public class ReleasesTabViewModel : RoutableHostScreen private readonly IRouter _router; private readonly SourceList _releases; private bool _loading; - private IGetReleases_PublishedReleases_PageInfo? _lastPageInfo; private ReleaseViewModel? _selectedReleaseViewModel; public ReleasesTabViewModel(ILogger logger, IUpdateService updateService, IUpdatingClient updatingClient, IReleaseVmFactory releaseVmFactory, INotificationService notificationService, @@ -75,21 +74,21 @@ public class ReleasesTabViewModel : RoutableHostScreen private set => RaiseAndSetIfChanged(ref _loading, value); } - public async Task GetMoreReleases(CancellationToken cancellationToken) + public async Task GetReleases(CancellationToken cancellationToken) { - if (_lastPageInfo != null && !_lastPageInfo.HasNextPage) - return; - try { Loading = true; - IOperationResult result = await _updatingClient.GetReleases.ExecuteAsync(_updateService.Channel, Platform.Windows, 20, _lastPageInfo?.EndCursor, cancellationToken); + IOperationResult result = await _updatingClient.GetReleases.ExecuteAsync(_updateService.Channel, Platform.Windows, cancellationToken); if (result.Data?.PublishedReleases?.Nodes == null) return; - _lastPageInfo = result.Data.PublishedReleases.PageInfo; - _releases.AddRange(result.Data.PublishedReleases.Nodes); + _releases.Edit(r => + { + r.Clear(); + r.AddRange(result.Data.PublishedReleases.Nodes); + }); } catch (TaskCanceledException) { @@ -114,7 +113,7 @@ public class ReleasesTabViewModel : RoutableHostScreen public override async Task OnNavigating(NavigationArguments args, CancellationToken cancellationToken) { if (!ReleaseViewModels.Any()) - await GetMoreReleases(cancellationToken); + await GetReleases(cancellationToken); // If there is an ID parameter further down the path, preselect it if (args.RouteParameters.Length > 0 && args.RouteParameters[0] is Guid releaseId) diff --git a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/LoginStepViewModel.cs b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/LoginStepViewModel.cs index 5b6cf680b..4c9e67e07 100644 --- a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/LoginStepViewModel.cs +++ b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/LoginStepViewModel.cs @@ -33,8 +33,7 @@ public class LoginStepViewModel : SubmissionViewModel if (result != ContentDialogResult.Primary) return; - Claim? emailVerified = _authenticationService.Claims.FirstOrDefault(c => c.Type == JwtClaimTypes.EmailVerified); - if (emailVerified?.Value == "true") + if (_authenticationService.GetIsEmailVerified()) State.ChangeScreen(); else State.ChangeScreen(); diff --git a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/UploadStepViewModel.cs b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/UploadStepViewModel.cs index ab59d122f..38e6464c1 100644 --- a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/UploadStepViewModel.cs +++ b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/UploadStepViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Reactive.Disposables; using System.Reactive.Linq; using System.Threading; @@ -138,7 +139,7 @@ public class UploadStepViewModel : SubmissionViewModel long? entryId = result.Data?.AddEntry?.Id; if (result.IsErrorResult() || entryId == null) { - await _windowService.ShowConfirmContentDialog("Failed to create workshop entry", result.Errors.ToString() ?? "Not even an error message", "Close", null); + await _windowService.ShowConfirmContentDialog("Failed to create workshop entry", string.Join("\r\n", result.Errors.Select(e => e.Message)), "Close", null); State.ChangeScreen(); return null; } diff --git a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/ValidateEmailStepViewModel.cs b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/ValidateEmailStepViewModel.cs index a2a840421..d2b1a1a5f 100644 --- a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/ValidateEmailStepViewModel.cs +++ b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/ValidateEmailStepViewModel.cs @@ -54,9 +54,7 @@ public class ValidateEmailStepViewModel : SubmissionViewModel { // Use the refresh token to login again, updating claims await _authenticationService.AutoLogin(true); - - Claim? emailVerified = _authenticationService.Claims.FirstOrDefault(c => c.Type == JwtClaimTypes.EmailVerified); - if (emailVerified?.Value == "true") + if (_authenticationService.GetIsEmailVerified()) ExecuteContinue(); } catch (Exception) diff --git a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/WelcomeStepViewModel.cs b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/WelcomeStepViewModel.cs index 87c96fb7d..c65bb4de6 100644 --- a/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/WelcomeStepViewModel.cs +++ b/src/Artemis.UI/Screens/Workshop/SubmissionWizard/Steps/WelcomeStepViewModel.cs @@ -29,7 +29,7 @@ public class WelcomeStepViewModel : SubmissionViewModel } else { - if (_authenticationService.Claims.Any(c => c.Type == JwtClaimTypes.EmailVerified && c.Value == "true")) + if (_authenticationService.GetIsEmailVerified()) State.ChangeScreen(); else State.ChangeScreen(); diff --git a/src/Artemis.WebClient.Updating/Queries/GetReleases.graphql b/src/Artemis.WebClient.Updating/Queries/GetReleases.graphql index ac56e6e3a..7dad1afb1 100644 --- a/src/Artemis.WebClient.Updating/Queries/GetReleases.graphql +++ b/src/Artemis.WebClient.Updating/Queries/GetReleases.graphql @@ -1,7 +1,7 @@ -query GetReleases($branch: String!, $platform: Platform!, $take: Int!, $after: String) { +query GetReleases($branch: String!, $platform: Platform!) { publishedReleases( - first: $take - after: $after + order: {createdAt: DESC} + first: 50 where: { and: [ { branch: { eq: $branch } } @@ -9,10 +9,6 @@ query GetReleases($branch: String!, $platform: Platform!, $take: Int!, $after: S ] } ) { - pageInfo { - hasNextPage - endCursor - } nodes { id version diff --git a/src/Artemis.WebClient.Workshop/Services/AuthenticationService.cs b/src/Artemis.WebClient.Workshop/Services/AuthenticationService.cs index 5f47d2567..db90979b5 100644 --- a/src/Artemis.WebClient.Workshop/Services/AuthenticationService.cs +++ b/src/Artemis.WebClient.Workshop/Services/AuthenticationService.cs @@ -266,6 +266,13 @@ internal class AuthenticationService : CorePropertyChanged, IAuthenticationServi _isLoggedInSubject.OnNext(false); } + /// + public bool GetIsEmailVerified() + { + Claim? emailVerified = Claims.FirstOrDefault(c => c.Type == JwtClaimTypes.EmailVerified); + return emailVerified?.Value.ToLower() == "true"; + } + private async Task InternalAutoLogin(bool force = false) { if (!force && _isLoggedInSubject.Value) diff --git a/src/Artemis.WebClient.Workshop/Services/Interfaces/IAuthenticationService.cs b/src/Artemis.WebClient.Workshop/Services/Interfaces/IAuthenticationService.cs index c3a3686ba..b806c83a9 100644 --- a/src/Artemis.WebClient.Workshop/Services/Interfaces/IAuthenticationService.cs +++ b/src/Artemis.WebClient.Workshop/Services/Interfaces/IAuthenticationService.cs @@ -14,4 +14,5 @@ public interface IAuthenticationService : IProtectedArtemisService Task AutoLogin(bool force = false); Task Login(CancellationToken cancellationToken); void Logout(); + bool GetIsEmailVerified(); } \ No newline at end of file