Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Always default to GitHub login #2479

Merged
merged 7 commits into from
Mar 17, 2020
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
21 changes: 1 addition & 20 deletions src/GitHub.App/ViewModels/Dialog/LoginCredentialsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.ComponentModel.Composition;
using System.Reactive.Linq;
using GitHub.App;
using GitHub.Primitives;
using GitHub.Services;
using ReactiveUI;

Expand All @@ -28,8 +26,7 @@ public LoginCredentialsViewModel(
(x, y) => x.Value || y.Value
).ToProperty(this, vm => vm.IsLoginInProgress);

UpdateLoginMode();
connectionManager.Connections.CollectionChanged += (_, __) => UpdateLoginMode();
LoginMode = LoginMode.DotComOrEnterprise;

Done = Observable.Merge(
loginToGitHubViewModel.Login,
Expand All @@ -55,21 +52,5 @@ public LoginMode LoginMode
public bool IsLoginInProgress { get { return isLoginInProgress.Value; } }

public IObservable<object> Done { get; }

void UpdateLoginMode()
{
var result = LoginMode.DotComOrEnterprise;

foreach (var connection in ConnectionManager.Connections)
{
if (connection.IsLoggedIn)
{
result &= ~((connection.HostAddress == HostAddress.GitHubDotComHostAddress) ?
LoginMode.DotComOnly : LoginMode.EnterpriseOnly);
}
}

LoginMode = result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ public async Task AllowsLoginFromEnterpriseAfterGitHubLoginHasFailedAsync()
public class TheLoginModeProperty : TestBaseClass
{
[Test]
public void LoginModeTracksAvailableConnections()
public void LoginModeIgnoresAvailableConnections()
{
// We always want to option to log-in to GitHub or GitHub Enterprise

var connectionManager = Substitute.For<IConnectionManager>();
var connections = new ObservableCollectionEx<IConnection>();
var gitHubLogin = Substitute.For<ILoginToGitHubViewModel>();
Expand All @@ -96,13 +98,13 @@ public void LoginModeTracksAvailableConnections()
Assert.That(LoginMode.DotComOrEnterprise, Is.EqualTo(loginViewModel.LoginMode));

connections.Add(enterpriseConnection);
Assert.That(LoginMode.DotComOnly, Is.EqualTo(loginViewModel.LoginMode));
Assert.That(LoginMode.DotComOrEnterprise, Is.EqualTo(loginViewModel.LoginMode));

connections.Add(gitHubConnection);
Assert.That(LoginMode.None, Is.EqualTo(loginViewModel.LoginMode));
Assert.That(LoginMode.DotComOrEnterprise, Is.EqualTo(loginViewModel.LoginMode));

connections.RemoveAt(0);
Assert.That(LoginMode.EnterpriseOnly, Is.EqualTo(loginViewModel.LoginMode));
Assert.That(LoginMode.DotComOrEnterprise, Is.EqualTo(loginViewModel.LoginMode));
}
}

Expand Down