Automatically move away from screens that require account info

If a screen requires user account information we can move off it
when the user signs out of the application.  This doesn't fix the
browser history however.  If the user moves backwards they would
try to visit a page that needs account data, and probably get an
error instead.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2008-11-27 16:54:01 -08:00
parent 53046651df
commit 7f05174435
6 changed files with 51 additions and 7 deletions

View File

@@ -75,6 +75,10 @@ public class Gerrit implements EntryPoint {
Cookies.removeCookie(ACCOUNT_COOKIE);
Cookies.removeCookie(OPENIDUSER_COOKIE);
refreshMenuBar();
if (currentScreen != null && currentScreen.isRequiresSignIn()) {
History.newItem(Link.ALL);
}
}
public void onModuleLoad() {
@@ -96,7 +100,11 @@ public class Gerrit implements EntryPoint {
refreshMenuBar();
if ("".equals(History.getToken())) {
if (isSignedIn()) {
History.newItem(Link.MINE);
} else {
History.newItem(Link.ALL);
}
} else {
History.fireCurrentHistoryState();
}

View File

@@ -15,11 +15,11 @@
package com.google.gerrit.client.account;
import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.ui.Screen;
import com.google.gerrit.client.ui.AccountScreen;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
public class AccountSettings extends Screen {
public class AccountSettings extends AccountScreen {
public AccountSettings() {
super(Util.C.accountSettingsHeading());

View File

@@ -16,12 +16,12 @@ package com.google.gerrit.client.changes;
import com.google.gerrit.client.data.AccountDashboardInfo;
import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.ui.Screen;
import com.google.gerrit.client.ui.AccountScreen;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
public class MineScreen extends Screen {
public class MineScreen extends AccountScreen {
private ChangeTable table;
private ChangeTable.Section byOwner;
private ChangeTable.Section forReview;

View File

@@ -14,10 +14,10 @@
package com.google.gerrit.client.changes;
import com.google.gerrit.client.ui.Screen;
import com.google.gerrit.client.ui.AccountScreen;
public class MineStarredScreen extends Screen {
public class MineStarredScreen extends AccountScreen {
private ChangeTable table;
private ChangeTable.Section starred;

View File

@@ -0,0 +1,23 @@
// Copyright 2008 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.client.ui;
/** A screen that requires the user to be signed-into their account. */
public class AccountScreen extends Screen {
public AccountScreen(final String heading) {
super(heading);
setRequiresSignIn(true);
}
}

View File

@@ -14,11 +14,14 @@
package com.google.gerrit.client.ui;
import com.google.gerrit.client.Gerrit;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.FlowPanel;
public class Screen extends FlowPanel {
private boolean requiresSignIn;
public Screen(final String heading) {
setStyleName("gerrit-Screen");
@@ -26,4 +29,14 @@ public class Screen extends FlowPanel {
DOM.setInnerText(h, heading);
DOM.appendChild(getElement(), h);
}
/** Set whether or not {@link Gerrit#isSignedIn()} must be true. */
public void setRequiresSignIn(final boolean b) {
requiresSignIn = b;
}
/** Does {@link Gerrit#isSignedIn()} have to be true to be on this screen? */
public boolean isRequiresSignIn() {
return requiresSignIn;
}
}