Display proper error message if non-existing/non-visible group is browsed
Browsing a group that does not exist or which is not visible for the user fails and Gerrit shows the error message "Application Error, Server Error, <group-id>". Since this error message looks like something severe had gone wrong in Gerrit, this change implements that now a proper error message is displayed in this case. This fix is especially important since bug 797 allows a user to see access rights for a group that is not visible to him and a link to browse the group is provided which results in the error above if the user clicks on it. Bug: issue 804 Change-Id: Ieebdfd11cdea99e561bce49d09e83fbb10ada307 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
		@@ -12,7 +12,7 @@
 | 
				
			|||||||
// See the License for the specific language governing permissions and
 | 
					// See the License for the specific language governing permissions and
 | 
				
			||||||
// limitations under the License.
 | 
					// limitations under the License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package com.google.gerrit.server.account;
 | 
					package com.google.gerrit.common.errors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.gerrit.reviewdb.AccountGroup;
 | 
					import com.google.gerrit.reviewdb.AccountGroup;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -20,12 +20,14 @@ import com.google.gerrit.reviewdb.AccountGroup;
 | 
				
			|||||||
public class NoSuchGroupException extends Exception {
 | 
					public class NoSuchGroupException extends Exception {
 | 
				
			||||||
  private static final long serialVersionUID = 1L;
 | 
					  private static final long serialVersionUID = 1L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public static final String MESSAGE = "Group Not Found: ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public NoSuchGroupException(final AccountGroup.Id key) {
 | 
					  public NoSuchGroupException(final AccountGroup.Id key) {
 | 
				
			||||||
    this(key, null);
 | 
					    this(key, null);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public NoSuchGroupException(final AccountGroup.Id key, final Throwable why) {
 | 
					  public NoSuchGroupException(final AccountGroup.Id key, final Throwable why) {
 | 
				
			||||||
    super(key.toString(), why);
 | 
					    super(MESSAGE + key.toString(), why);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public NoSuchGroupException(final AccountGroup.NameKey k) {
 | 
					  public NoSuchGroupException(final AccountGroup.NameKey k) {
 | 
				
			||||||
@@ -33,6 +35,6 @@ public class NoSuchGroupException extends Exception {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public NoSuchGroupException(final AccountGroup.NameKey k, final Throwable why) {
 | 
					  public NoSuchGroupException(final AccountGroup.NameKey k, final Throwable why) {
 | 
				
			||||||
    super(k.toString(), why);
 | 
					    super(MESSAGE + k.toString(), why);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -46,6 +46,8 @@ public interface GerritConstants extends Constants {
 | 
				
			|||||||
  String nameAlreadyUsedBody();
 | 
					  String nameAlreadyUsedBody();
 | 
				
			||||||
  String noSuchAccountTitle();
 | 
					  String noSuchAccountTitle();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  String noSuchGroupTitle();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  String inactiveAccountBody();
 | 
					  String inactiveAccountBody();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  String menuAll();
 | 
					  String menuAll();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,6 +29,8 @@ notFoundBody = The page you requested was not found.
 | 
				
			|||||||
nameAlreadyUsedBody = The name is already in use.
 | 
					nameAlreadyUsedBody = The name is already in use.
 | 
				
			||||||
noSuchAccountTitle = Code Review - Unknown User
 | 
					noSuchAccountTitle = Code Review - Unknown User
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					noSuchGroupTitle = Code Review - Unknown Group
 | 
				
			||||||
 | 
					
 | 
				
			||||||
inactiveAccountBody = This user is currently inactive.
 | 
					inactiveAccountBody = This user is currently inactive.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
menuAll = All
 | 
					menuAll = All
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,4 +22,6 @@ public interface GerritMessages extends Messages {
 | 
				
			|||||||
  String poweredBy(String version);
 | 
					  String poweredBy(String version);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  String noSuchAccountMessage(String who);
 | 
					  String noSuchAccountMessage(String who);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  String noSuchGroupMessage(String who);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,3 +4,5 @@ poweredBy = Powered by <a href="http://code.google.com/p/gerrit/" target="_blank
 | 
				
			|||||||
| <a href="http://code.google.com/p/gerrit/issues/list" target="_blank">Report Bug</a>
 | 
					| <a href="http://code.google.com/p/gerrit/issues/list" target="_blank">Report Bug</a>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
noSuchAccountMessage = {0} is not a registered user.
 | 
					noSuchAccountMessage = {0} is not a registered user.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					noSuchGroupMessage = Group {0} does not exist or is not visible to you.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,7 @@ import com.google.gerrit.common.errors.InactiveAccountException;
 | 
				
			|||||||
import com.google.gerrit.common.errors.NameAlreadyUsedException;
 | 
					import com.google.gerrit.common.errors.NameAlreadyUsedException;
 | 
				
			||||||
import com.google.gerrit.common.errors.NoSuchAccountException;
 | 
					import com.google.gerrit.common.errors.NoSuchAccountException;
 | 
				
			||||||
import com.google.gerrit.common.errors.NoSuchEntityException;
 | 
					import com.google.gerrit.common.errors.NoSuchEntityException;
 | 
				
			||||||
 | 
					import com.google.gerrit.common.errors.NoSuchGroupException;
 | 
				
			||||||
import com.google.gerrit.common.errors.NotSignedInException;
 | 
					import com.google.gerrit.common.errors.NotSignedInException;
 | 
				
			||||||
import com.google.gwt.core.client.GWT;
 | 
					import com.google.gwt.core.client.GWT;
 | 
				
			||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
 | 
					import com.google.gwt.user.client.rpc.AsyncCallback;
 | 
				
			||||||
@@ -51,6 +52,13 @@ public abstract class GerritCallback<T> implements AsyncCallback<T> {
 | 
				
			|||||||
    } else if (isNameAlreadyUsed(caught)) {
 | 
					    } else if (isNameAlreadyUsed(caught)) {
 | 
				
			||||||
      new ErrorDialog(Gerrit.C.nameAlreadyUsedBody()).center();
 | 
					      new ErrorDialog(Gerrit.C.nameAlreadyUsedBody()).center();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    } else if (isNoSuchGroup(caught)) {
 | 
				
			||||||
 | 
					      final String msg = caught.getMessage();
 | 
				
			||||||
 | 
					      final String group = msg.substring(NoSuchGroupException.MESSAGE.length());
 | 
				
			||||||
 | 
					      final ErrorDialog d = new ErrorDialog(Gerrit.M.noSuchGroupMessage(group));
 | 
				
			||||||
 | 
					      d.setText(Gerrit.C.noSuchGroupTitle());
 | 
				
			||||||
 | 
					      d.center();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    } else if (caught instanceof ServerUnavailableException) {
 | 
					    } else if (caught instanceof ServerUnavailableException) {
 | 
				
			||||||
      new ErrorDialog(RpcConstants.C.errorServerUnavailable()).center();
 | 
					      new ErrorDialog(RpcConstants.C.errorServerUnavailable()).center();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -89,4 +97,9 @@ public abstract class GerritCallback<T> implements AsyncCallback<T> {
 | 
				
			|||||||
    return caught instanceof RemoteJsonException
 | 
					    return caught instanceof RemoteJsonException
 | 
				
			||||||
        && caught.getMessage().equals(NameAlreadyUsedException.MESSAGE);
 | 
					        && caught.getMessage().equals(NameAlreadyUsedException.MESSAGE);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private static boolean isNoSuchGroup(final Throwable caught) {
 | 
				
			||||||
 | 
					    return caught instanceof RemoteJsonException
 | 
				
			||||||
 | 
					    && caught.getMessage().startsWith(NoSuchGroupException.MESSAGE);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,11 +17,11 @@ package com.google.gerrit.httpd.rpc;
 | 
				
			|||||||
import com.google.gerrit.common.errors.CorruptEntityException;
 | 
					import com.google.gerrit.common.errors.CorruptEntityException;
 | 
				
			||||||
import com.google.gerrit.common.errors.InvalidQueryException;
 | 
					import com.google.gerrit.common.errors.InvalidQueryException;
 | 
				
			||||||
import com.google.gerrit.common.errors.NoSuchEntityException;
 | 
					import com.google.gerrit.common.errors.NoSuchEntityException;
 | 
				
			||||||
 | 
					import com.google.gerrit.common.errors.NoSuchGroupException;
 | 
				
			||||||
import com.google.gerrit.reviewdb.Account;
 | 
					import com.google.gerrit.reviewdb.Account;
 | 
				
			||||||
import com.google.gerrit.reviewdb.ReviewDb;
 | 
					import com.google.gerrit.reviewdb.ReviewDb;
 | 
				
			||||||
import com.google.gerrit.server.CurrentUser;
 | 
					import com.google.gerrit.server.CurrentUser;
 | 
				
			||||||
import com.google.gerrit.server.IdentifiedUser;
 | 
					import com.google.gerrit.server.IdentifiedUser;
 | 
				
			||||||
import com.google.gerrit.server.account.NoSuchGroupException;
 | 
					 | 
				
			||||||
import com.google.gerrit.server.project.NoSuchChangeException;
 | 
					import com.google.gerrit.server.project.NoSuchChangeException;
 | 
				
			||||||
import com.google.gerrit.server.project.NoSuchProjectException;
 | 
					import com.google.gerrit.server.project.NoSuchProjectException;
 | 
				
			||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
 | 
					import com.google.gwt.user.client.rpc.AsyncCallback;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,6 +20,7 @@ import com.google.gerrit.common.errors.InactiveAccountException;
 | 
				
			|||||||
import com.google.gerrit.common.errors.NameAlreadyUsedException;
 | 
					import com.google.gerrit.common.errors.NameAlreadyUsedException;
 | 
				
			||||||
import com.google.gerrit.common.errors.NoSuchAccountException;
 | 
					import com.google.gerrit.common.errors.NoSuchAccountException;
 | 
				
			||||||
import com.google.gerrit.common.errors.NoSuchEntityException;
 | 
					import com.google.gerrit.common.errors.NoSuchEntityException;
 | 
				
			||||||
 | 
					import com.google.gerrit.common.errors.NoSuchGroupException;
 | 
				
			||||||
import com.google.gerrit.httpd.rpc.BaseServiceImplementation;
 | 
					import com.google.gerrit.httpd.rpc.BaseServiceImplementation;
 | 
				
			||||||
import com.google.gerrit.reviewdb.Account;
 | 
					import com.google.gerrit.reviewdb.Account;
 | 
				
			||||||
import com.google.gerrit.reviewdb.AccountGroup;
 | 
					import com.google.gerrit.reviewdb.AccountGroup;
 | 
				
			||||||
@@ -31,7 +32,6 @@ import com.google.gerrit.server.account.AccountCache;
 | 
				
			|||||||
import com.google.gerrit.server.account.AccountResolver;
 | 
					import com.google.gerrit.server.account.AccountResolver;
 | 
				
			||||||
import com.google.gerrit.server.account.GroupCache;
 | 
					import com.google.gerrit.server.account.GroupCache;
 | 
				
			||||||
import com.google.gerrit.server.account.GroupControl;
 | 
					import com.google.gerrit.server.account.GroupControl;
 | 
				
			||||||
import com.google.gerrit.server.account.NoSuchGroupException;
 | 
					 | 
				
			||||||
import com.google.gerrit.server.account.Realm;
 | 
					import com.google.gerrit.server.account.Realm;
 | 
				
			||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
 | 
					import com.google.gwt.user.client.rpc.AsyncCallback;
 | 
				
			||||||
import com.google.gwtjsonrpc.client.VoidResult;
 | 
					import com.google.gwtjsonrpc.client.VoidResult;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,6 +15,7 @@
 | 
				
			|||||||
package com.google.gerrit.httpd.rpc.account;
 | 
					package com.google.gerrit.httpd.rpc.account;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.gerrit.common.data.GroupDetail;
 | 
					import com.google.gerrit.common.data.GroupDetail;
 | 
				
			||||||
 | 
					import com.google.gerrit.common.errors.NoSuchGroupException;
 | 
				
			||||||
import com.google.gerrit.httpd.rpc.Handler;
 | 
					import com.google.gerrit.httpd.rpc.Handler;
 | 
				
			||||||
import com.google.gerrit.reviewdb.Account;
 | 
					import com.google.gerrit.reviewdb.Account;
 | 
				
			||||||
import com.google.gerrit.reviewdb.AccountGroup;
 | 
					import com.google.gerrit.reviewdb.AccountGroup;
 | 
				
			||||||
@@ -23,7 +24,6 @@ import com.google.gerrit.reviewdb.ReviewDb;
 | 
				
			|||||||
import com.google.gerrit.server.account.AccountInfoCacheFactory;
 | 
					import com.google.gerrit.server.account.AccountInfoCacheFactory;
 | 
				
			||||||
import com.google.gerrit.server.account.GroupCache;
 | 
					import com.google.gerrit.server.account.GroupCache;
 | 
				
			||||||
import com.google.gerrit.server.account.GroupControl;
 | 
					import com.google.gerrit.server.account.GroupControl;
 | 
				
			||||||
import com.google.gerrit.server.account.NoSuchGroupException;
 | 
					 | 
				
			||||||
import com.google.gwtorm.client.OrmException;
 | 
					import com.google.gwtorm.client.OrmException;
 | 
				
			||||||
import com.google.inject.Inject;
 | 
					import com.google.inject.Inject;
 | 
				
			||||||
import com.google.inject.assistedinject.Assisted;
 | 
					import com.google.inject.assistedinject.Assisted;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,13 +16,13 @@ package com.google.gerrit.httpd.rpc.account;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import com.google.gerrit.common.data.GroupDetail;
 | 
					import com.google.gerrit.common.data.GroupDetail;
 | 
				
			||||||
import com.google.gerrit.common.errors.NameAlreadyUsedException;
 | 
					import com.google.gerrit.common.errors.NameAlreadyUsedException;
 | 
				
			||||||
 | 
					import com.google.gerrit.common.errors.NoSuchGroupException;
 | 
				
			||||||
import com.google.gerrit.httpd.rpc.Handler;
 | 
					import com.google.gerrit.httpd.rpc.Handler;
 | 
				
			||||||
import com.google.gerrit.reviewdb.AccountGroup;
 | 
					import com.google.gerrit.reviewdb.AccountGroup;
 | 
				
			||||||
import com.google.gerrit.reviewdb.AccountGroupName;
 | 
					import com.google.gerrit.reviewdb.AccountGroupName;
 | 
				
			||||||
import com.google.gerrit.reviewdb.ReviewDb;
 | 
					import com.google.gerrit.reviewdb.ReviewDb;
 | 
				
			||||||
import com.google.gerrit.server.account.GroupCache;
 | 
					import com.google.gerrit.server.account.GroupCache;
 | 
				
			||||||
import com.google.gerrit.server.account.GroupControl;
 | 
					import com.google.gerrit.server.account.GroupControl;
 | 
				
			||||||
import com.google.gerrit.server.account.NoSuchGroupException;
 | 
					 | 
				
			||||||
import com.google.gwtorm.client.OrmDuplicateKeyException;
 | 
					import com.google.gwtorm.client.OrmDuplicateKeyException;
 | 
				
			||||||
import com.google.gwtorm.client.OrmException;
 | 
					import com.google.gwtorm.client.OrmException;
 | 
				
			||||||
import com.google.inject.Inject;
 | 
					import com.google.inject.Inject;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,6 +18,7 @@ import com.google.gerrit.common.data.ApprovalType;
 | 
				
			|||||||
import com.google.gerrit.common.data.ApprovalTypes;
 | 
					import com.google.gerrit.common.data.ApprovalTypes;
 | 
				
			||||||
import com.google.gerrit.common.data.ProjectDetail;
 | 
					import com.google.gerrit.common.data.ProjectDetail;
 | 
				
			||||||
import com.google.gerrit.common.errors.InvalidNameException;
 | 
					import com.google.gerrit.common.errors.InvalidNameException;
 | 
				
			||||||
 | 
					import com.google.gerrit.common.errors.NoSuchGroupException;
 | 
				
			||||||
import com.google.gerrit.httpd.rpc.Handler;
 | 
					import com.google.gerrit.httpd.rpc.Handler;
 | 
				
			||||||
import com.google.gerrit.reviewdb.AccountGroup;
 | 
					import com.google.gerrit.reviewdb.AccountGroup;
 | 
				
			||||||
import com.google.gerrit.reviewdb.ApprovalCategory;
 | 
					import com.google.gerrit.reviewdb.ApprovalCategory;
 | 
				
			||||||
@@ -25,7 +26,6 @@ import com.google.gerrit.reviewdb.Project;
 | 
				
			|||||||
import com.google.gerrit.reviewdb.RefRight;
 | 
					import com.google.gerrit.reviewdb.RefRight;
 | 
				
			||||||
import com.google.gerrit.reviewdb.ReviewDb;
 | 
					import com.google.gerrit.reviewdb.ReviewDb;
 | 
				
			||||||
import com.google.gerrit.server.account.GroupCache;
 | 
					import com.google.gerrit.server.account.GroupCache;
 | 
				
			||||||
import com.google.gerrit.server.account.NoSuchGroupException;
 | 
					 | 
				
			||||||
import com.google.gerrit.server.project.NoSuchProjectException;
 | 
					import com.google.gerrit.server.project.NoSuchProjectException;
 | 
				
			||||||
import com.google.gerrit.server.project.NoSuchRefException;
 | 
					import com.google.gerrit.server.project.NoSuchRefException;
 | 
				
			||||||
import com.google.gerrit.server.project.ProjectCache;
 | 
					import com.google.gerrit.server.project.ProjectCache;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.google.gerrit.server.account;
 | 
					package com.google.gerrit.server.account;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.gerrit.common.errors.NoSuchGroupException;
 | 
				
			||||||
import com.google.gerrit.reviewdb.Account;
 | 
					import com.google.gerrit.reviewdb.Account;
 | 
				
			||||||
import com.google.gerrit.reviewdb.AccountGroup;
 | 
					import com.google.gerrit.reviewdb.AccountGroup;
 | 
				
			||||||
import com.google.gerrit.server.CurrentUser;
 | 
					import com.google.gerrit.server.CurrentUser;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user