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

Commit d7d97ba

Browse files
authored
Merge pull request #1203 from github/fixes/1201-gists-logout
Removed LogoutRequired flow for Gists
2 parents 2e2957a + 7cedbe1 commit d7d97ba

24 files changed

+21
-481
lines changed

src/GitHub.App/Api/ApiClient.cs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public partial class ApiClient : IApiClient
2626
const string ScopesHeader = "X-OAuth-Scopes";
2727
const string ProductName = Info.ApplicationInfo.ApplicationDescription;
2828
static readonly Logger log = LogManager.GetCurrentClassLogger();
29-
static readonly Uri userEndpoint = new Uri("user", UriKind.Relative);
3029

3130
readonly IObservableGitHubClient gitHubClient;
3231
// There are two sets of authorization scopes, old and new:
@@ -96,30 +95,9 @@ public IObservable<Gist> CreateGist(NewGist newGist)
9695
return gitHubClient.Gist.Create(newGist);
9796
}
9897

99-
public IObservable<UserAndScopes> GetUser()
98+
public IObservable<User> GetUser()
10099
{
101-
return GetUserInternal().ToObservable();
102-
}
103-
104-
async Task<UserAndScopes> GetUserInternal()
105-
{
106-
var response = await gitHubClient.Connection.Get<User>(
107-
userEndpoint, null, null).ConfigureAwait(false);
108-
var scopes = default(string[]);
109-
110-
if (response.HttpResponse.Headers.ContainsKey(ScopesHeader))
111-
{
112-
scopes = response.HttpResponse.Headers[ScopesHeader]
113-
.Split(',')
114-
.Select(x => x.Trim())
115-
.ToArray();
116-
}
117-
else
118-
{
119-
log.Error($"Error reading scopes: /user succeeded but {ScopesHeader} was not present.");
120-
}
121-
122-
return new UserAndScopes(response.Body, scopes);
100+
return gitHubClient.User.Current();
123101
}
124102

125103
public IObservable<ApplicationAuthorization> GetOrCreateApplicationAuthenticationCode(

src/GitHub.App/Controllers/UIController.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ void ConfigureUIHandlingStates()
319319
ConfigureEntriesExitsForView(UIViewType.Login);
320320
ConfigureEntriesExitsForView(UIViewType.TwoFactor);
321321
ConfigureEntriesExitsForView(UIViewType.Gist);
322-
ConfigureEntriesExitsForView(UIViewType.LogoutRequired);
323322
ConfigureEntriesExitsForView(UIViewType.StartPageClone);
324323

325324
uiStateMachine.Configure(UIViewType.End)
@@ -421,7 +420,6 @@ void ConfigureLogicStates()
421420
ConfigureSingleViewLogic(UIControllerFlow.Create, UIViewType.Create);
422421
ConfigureSingleViewLogic(UIControllerFlow.Gist, UIViewType.Gist);
423422
ConfigureSingleViewLogic(UIControllerFlow.Home, UIViewType.PRList);
424-
ConfigureSingleViewLogic(UIControllerFlow.LogoutRequired, UIViewType.LogoutRequired);
425423
ConfigureSingleViewLogic(UIControllerFlow.Publish, UIViewType.Publish);
426424
ConfigureSingleViewLogic(UIControllerFlow.PullRequestList, UIViewType.PRList);
427425
ConfigureSingleViewLogic(UIControllerFlow.PullRequestDetail, UIViewType.PRDetail);
@@ -448,11 +446,7 @@ UIControllerFlow SelectActiveFlow()
448446
{
449447
var host = connection != null ? hosts.LookupHost(connection.HostAddress) : null;
450448
var loggedIn = host?.IsLoggedIn ?? false;
451-
if (!loggedIn || selectedFlow != UIControllerFlow.Gist)
452-
return loggedIn ? selectedFlow : UIControllerFlow.Authentication;
453-
454-
var supportsGist = host?.SupportsGist ?? false;
455-
return supportsGist ? selectedFlow : UIControllerFlow.LogoutRequired;
449+
return loggedIn ? selectedFlow : UIControllerFlow.Authentication;
456450
}
457451

458452
/// <summary>

src/GitHub.App/GitHub.App.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@
216216
<Compile Include="ViewModels\NotAGitRepositoryViewModel.cs" />
217217
<Compile Include="ViewModels\NotAGitHubRepositoryViewModel.cs" />
218218
<Compile Include="ViewModels\LoggedOutViewModel.cs" />
219-
<Compile Include="ViewModels\LogoutRequiredViewModel.cs" />
220219
<Compile Include="ViewModels\PullRequestCreationViewModel.cs" />
221220
<Compile Include="ViewModels\PullRequestDetailViewModel.cs" />
222221
<Compile Include="ViewModels\PullRequestDirectoryNode.cs" />

src/GitHub.App/Models/DisconnectedRepositoryHosts.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public DisconnectedRepositoryHost()
2525

2626
public bool IsLoggedIn { get; private set; }
2727
public bool IsLoggingIn { get; private set; }
28-
public bool SupportsGist { get; private set; }
2928
public ReactiveList<IAccount> Organizations { get; private set; }
3029
public ReactiveList<IAccount> Accounts { get; private set; }
3130
public string Title { get; private set; }

src/GitHub.App/Models/RepositoryHost.cs

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ namespace GitHub.Models
2727
public class RepositoryHost : ReactiveObject, IRepositoryHost
2828
{
2929
static readonly Logger log = LogManager.GetCurrentClassLogger();
30-
static readonly UserAndScopes unverifiedUser = new UserAndScopes(null, null);
3130

3231
readonly ILoginManager loginManager;
3332
readonly HostAddress hostAddress;
@@ -65,8 +64,6 @@ public bool IsLoggedIn
6564
private set { this.RaiseAndSetIfChanged(ref isLoggedIn, value); }
6665
}
6766

68-
public bool SupportsGist { get; private set; }
69-
7067
public string Title { get; private set; }
7168

7269
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
@@ -81,7 +78,7 @@ public IObservable<AuthenticationResult> LogInFromCache()
8178
usage.IncrementLoginCount().Forget();
8279
await ModelService.InsertUser(accountCacheItem);
8380

84-
if (user != unverifiedUser.User)
81+
if (user != null)
8582
{
8683
IsLoggedIn = true;
8784
return AuthenticationResult.Success;
@@ -112,7 +109,7 @@ public IObservable<AuthenticationResult> LogIn(string usernameOrEmail, string pa
112109
usage.IncrementLoginCount().Forget();
113110
await ModelService.InsertUser(accountCacheItem);
114111

115-
if (user != unverifiedUser.User)
112+
if (user != null)
116113
{
117114
IsLoggedIn = true;
118115
return Observable.Return(AuthenticationResult.Success);
@@ -149,53 +146,6 @@ public IObservable<Unit> LogOut()
149146
});
150147
}
151148

152-
static IObservable<AuthenticationResult> GetAuthenticationResultForUser(UserAndScopes account)
153-
{
154-
return Observable.Return(account == null ? AuthenticationResult.CredentialFailure
155-
: account == unverifiedUser
156-
? AuthenticationResult.VerificationFailure
157-
: AuthenticationResult.Success);
158-
}
159-
160-
IObservable<AuthenticationResult> LoginWithApiUser(UserAndScopes userAndScopes)
161-
{
162-
return GetAuthenticationResultForUser(userAndScopes)
163-
.SelectMany(result =>
164-
{
165-
if (result.IsSuccess())
166-
{
167-
var accountCacheItem = new AccountCacheItem(userAndScopes.User);
168-
usage.IncrementLoginCount().Forget();
169-
return ModelService.InsertUser(accountCacheItem).Select(_ => result);
170-
}
171-
172-
if (result == AuthenticationResult.VerificationFailure)
173-
{
174-
return loginCache.EraseLogin(Address).Select(_ => result);
175-
}
176-
return Observable.Return(result);
177-
})
178-
.ObserveOn(RxApp.MainThreadScheduler)
179-
.Do(result =>
180-
{
181-
if (result.IsSuccess())
182-
{
183-
SupportsGist = userAndScopes.Scopes?.Contains("gist") ?? true;
184-
IsLoggedIn = true;
185-
}
186-
187-
log.Info("Log in from cache for login '{0}' to host '{1}' {2}",
188-
userAndScopes?.User?.Login ?? "(null)",
189-
hostAddress.ApiUri,
190-
result.IsSuccess() ? "SUCCEEDED" : "FAILED");
191-
});
192-
}
193-
194-
IObservable<UserAndScopes> GetUserFromApi()
195-
{
196-
return Observable.Defer(() => ApiClient.GetUser());
197-
}
198-
199149
protected virtual void Dispose(bool disposing)
200150
{}
201151

src/GitHub.App/Resources.Designer.cs

Lines changed: 0 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GitHub.App/Resources.resx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,6 @@
159159
<data name="LoginTitle" xml:space="preserve">
160160
<value>Connect To GitHub</value>
161161
</data>
162-
<data name="LogoutRequiredFeatureGist" xml:space="preserve">
163-
<value>create a Gist</value>
164-
</data>
165-
<data name="LogoutRequiredMessage" xml:space="preserve">
166-
<value>To {0} you need to sign out and back in.</value>
167-
</data>
168-
<data name="LogoutRequiredTitle" xml:space="preserve">
169-
<value>Sign Out Required</value>
170-
</data>
171162
<data name="PasswordValidatorEmpty" xml:space="preserve">
172163
<value>Please enter your password</value>
173164
</data>

src/GitHub.App/SampleData/SampleViewModels.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,6 @@ public bool IsLoggedIn
276276
private set;
277277
}
278278

279-
public bool SupportsGist
280-
{
281-
get;
282-
private set;
283-
}
284-
285279
public IModelService ModelService
286280
{
287281
get;

src/GitHub.App/ViewModels/LogoutRequiredViewModel.cs

Lines changed: 0 additions & 108 deletions
This file was deleted.

src/GitHub.Exports.Reactive/Api/IApiClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface IApiClient
1515

1616
IObservable<Repository> CreateRepository(NewRepository repository, string login, bool isUser);
1717
IObservable<Gist> CreateGist(NewGist newGist);
18-
IObservable<UserAndScopes> GetUser();
18+
IObservable<User> GetUser();
1919
IObservable<Organization> GetOrganizations();
2020
/// <summary>
2121
/// Retrieves all repositories that belong to this user.

0 commit comments

Comments
 (0)