Implement the ChangeListService in terms of ReviewDb's ChangeAccess
We now support showing the dashboard of any user via the "dashboard,$id" URL syntax. Since they are all public hyperlinks anyway its not really a security issue to show our internal database key in the URL. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -16,16 +16,16 @@ package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.Link;
|
||||
import com.google.gerrit.client.data.ChangeHeader;
|
||||
import com.google.gerrit.client.data.ChangeInfo;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.google.gwt.user.client.History;
|
||||
import com.google.gwt.user.client.ui.Hyperlink;
|
||||
|
||||
public class ChangeLink extends Hyperlink {
|
||||
private ChangeHeader change;
|
||||
private ChangeInfo change;
|
||||
|
||||
public ChangeLink(final String text, final ChangeHeader c) {
|
||||
public ChangeLink(final String text, final ChangeInfo c) {
|
||||
super(text, Link.toChange(c));
|
||||
change = c;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// 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.changes;
|
||||
|
||||
import com.google.gerrit.client.data.AccountDashboardInfo;
|
||||
import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwtjsonrpc.client.RemoteJsonService;
|
||||
|
||||
public interface ChangeListService extends RemoteJsonService {
|
||||
void forAccount(Account.Id id, AsyncCallback<AccountDashboardInfo> callback);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.data.AccountCache;
|
||||
import com.google.gerrit.client.data.AccountDashboardInfo;
|
||||
import com.google.gerrit.client.data.AccountInfo;
|
||||
import com.google.gerrit.client.data.ChangeInfo;
|
||||
import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gerrit.client.reviewdb.Change;
|
||||
import com.google.gerrit.client.reviewdb.ChangeAccess;
|
||||
import com.google.gerrit.client.reviewdb.ReviewDb;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwtjsonrpc.client.CookieAccess;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.ResultSet;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChangeListServiceImpl implements ChangeListService {
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
|
||||
public ChangeListServiceImpl(final SchemaFactory<ReviewDb> rdf) {
|
||||
schema = rdf;
|
||||
}
|
||||
|
||||
public void forAccount(Account.Id id,
|
||||
AsyncCallback<AccountDashboardInfo> callback) {
|
||||
if (id == null) {
|
||||
id = idFromCookie();
|
||||
}
|
||||
if (id == null) {
|
||||
callback.onFailure(new IllegalArgumentException("No Account.Id"));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final ReviewDb db = schema.open();
|
||||
try {
|
||||
final AccountCache accts = new AccountCache(db);
|
||||
final Account user = accts.get(id);
|
||||
if (user == null) {
|
||||
callback.onFailure(new IllegalArgumentException("No such user"));
|
||||
return;
|
||||
}
|
||||
|
||||
final ChangeAccess changes = db.changes();
|
||||
final AccountDashboardInfo d;
|
||||
|
||||
d = new AccountDashboardInfo(new AccountInfo(user));
|
||||
d.setByOwner(toInfoList(changes.byOwnerOpen(user.getId()), accts));
|
||||
d.setClosed(toInfoList(changes.byOwnerMerged(user.getId()), accts));
|
||||
callback.onSuccess(d);
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
} catch (OrmException e) {
|
||||
callback.onFailure(e);
|
||||
}
|
||||
}
|
||||
|
||||
private List<ChangeInfo> toInfoList(final ResultSet<Change> rs,
|
||||
final AccountCache accts) throws OrmException {
|
||||
final ArrayList<ChangeInfo> r = new ArrayList<ChangeInfo>();
|
||||
for (final Change c : rs) {
|
||||
r.add(new ChangeInfo(c, accts));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private static Account.Id idFromCookie() {
|
||||
final String myid = CookieAccess.getTokenText(Gerrit.ACCOUNT_COOKIE);
|
||||
if (myid != null && myid.length() > 0) {
|
||||
try {
|
||||
return new Account.Id(Integer.parseInt(myid));
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.client.Screen;
|
||||
import com.google.gerrit.client.data.ChangeHeader;
|
||||
import com.google.gerrit.client.data.ChangeInfo;
|
||||
|
||||
|
||||
public class ChangeScreen extends Screen {
|
||||
@@ -23,7 +23,7 @@ public class ChangeScreen extends Screen {
|
||||
super("Loading Change " + id);
|
||||
}
|
||||
|
||||
public ChangeScreen(final ChangeHeader c) {
|
||||
super(c.subject);
|
||||
public ChangeScreen(final ChangeInfo c) {
|
||||
super(c.getSubject());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,10 @@
|
||||
|
||||
package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.client.data.ChangeHeader;
|
||||
import com.google.gerrit.client.Link;
|
||||
import com.google.gerrit.client.data.ChangeInfo;
|
||||
import com.google.gwt.user.client.ui.FlexTable;
|
||||
import com.google.gwt.user.client.ui.Hyperlink;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -62,19 +64,20 @@ public class ChangeTable extends FlexTable {
|
||||
setStyleName(row, C_ID, "gerrit-ChangeTable-ColumnID");
|
||||
}
|
||||
|
||||
private void populateChangeRow(final int row, final ChangeHeader c) {
|
||||
setWidget(row, C_ID, new ChangeLink(String.valueOf(c.id), c));
|
||||
private void populateChangeRow(final int row, final ChangeInfo c) {
|
||||
setWidget(row, C_ID, new ChangeLink(String.valueOf(c.getId().get()), c));
|
||||
|
||||
String s = c.subject;
|
||||
if (c.status != null) {
|
||||
s += " (" + c.status + ")";
|
||||
String s = c.getSubject();
|
||||
if (c.getStatus() != null) {
|
||||
s += " (" + c.getStatus().name() + ")";
|
||||
}
|
||||
setWidget(row, C_SUBJECT, new ChangeLink(s, c));
|
||||
|
||||
setText(row, C_OWNER, c.owner.fullName);
|
||||
setWidget(row, C_OWNER, new Hyperlink(c.getOwner().getFullName(), Link
|
||||
.toAccountDashboard(c.getOwner())));
|
||||
setText(row, C_REVIEWERS, "TODO");
|
||||
setText(row, C_PROJECT, c.project.name);
|
||||
setText(row, C_LAST_UPDATE, c.lastUpdate.toString());
|
||||
setText(row, C_PROJECT, c.getProject().getName());
|
||||
setText(row, C_LAST_UPDATE, "TODO");
|
||||
}
|
||||
|
||||
private void setStyleName(final int row, final int col, final String name) {
|
||||
@@ -142,7 +145,7 @@ public class ChangeTable extends FlexTable {
|
||||
this.titleText = titleText;
|
||||
}
|
||||
|
||||
public void display(final List<ChangeHeader> changeList) {
|
||||
public void display(final List<ChangeInfo> changeList) {
|
||||
final int sz = changeList != null ? changeList.size() : 0;
|
||||
final boolean hadData = rows > 0;
|
||||
|
||||
|
||||
@@ -15,30 +15,35 @@
|
||||
package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.client.Screen;
|
||||
import com.google.gerrit.client.data.MineResult;
|
||||
import com.google.gerrit.client.data.AccountDashboardInfo;
|
||||
import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
|
||||
public class MineScreen extends Screen {
|
||||
private ChangeTable table;
|
||||
private ChangeTable.Section byMe;
|
||||
private ChangeTable.Section byOwner;
|
||||
private ChangeTable.Section forReview;
|
||||
private ChangeTable.Section closed;
|
||||
|
||||
public MineScreen() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public MineScreen(final Account.Id id) {
|
||||
super(Util.C.mineHeading());
|
||||
|
||||
table = new ChangeTable();
|
||||
byMe = new ChangeTable.Section(Util.C.mineByMe());
|
||||
byOwner = new ChangeTable.Section(Util.C.mineByMe());
|
||||
forReview = new ChangeTable.Section(Util.C.mineForReview());
|
||||
closed = new ChangeTable.Section(Util.C.mineClosed());
|
||||
|
||||
Util.LIST_SVC.mine(new AsyncCallback<MineResult>() {
|
||||
public void onSuccess(final MineResult r) {
|
||||
byMe.display(r.byMe);
|
||||
forReview.display(r.forReview);
|
||||
closed.display(r.closed);
|
||||
|
||||
Util.LIST_SVC.forAccount(id, new AsyncCallback<AccountDashboardInfo>() {
|
||||
public void onSuccess(final AccountDashboardInfo r) {
|
||||
byOwner.display(r.getByOwner());
|
||||
forReview.display(r.getForReview());
|
||||
closed.display(r.getClosed());
|
||||
}
|
||||
|
||||
public void onFailure(final Throwable caught) {
|
||||
@@ -46,7 +51,7 @@ public class MineScreen extends Screen {
|
||||
}
|
||||
});
|
||||
|
||||
table.addSection(byMe);
|
||||
table.addSection(byOwner);
|
||||
table.addSection(forReview);
|
||||
table.addSection(closed);
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.client.changes;
|
||||
|
||||
import com.google.gerrit.client.data.ChangeListService;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.rpc.ServiceDefTarget;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user