Access LabelTypes through ProjectState rather than globally

We want to allow projects to define their own labels, so we can't
assume the label list is global. In typical cases, we can access it
through a ProjectControl, ChangeControl, or related factory. This does
result in a few more places where we propagate
NoSuchProject/ChangeExceptions where there were none before. This is
intended: operations that query/modify labels on, say, a bare
Change.Id now do need to verify that the project/change exists.

For now, leave code in LabelTypesProvider, but try not to inject
LabelTypes where at all possible.

Change-Id: I4936ccafdb41848aaac3e335adf4648369d6abbc
This commit is contained in:
Dave Borowitz
2013-02-14 17:11:25 -08:00
parent 742a046fd0
commit 6cae753a4c
32 changed files with 212 additions and 156 deletions

View File

@@ -22,7 +22,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.gerrit.common.ChangeHooks;
import com.google.gerrit.common.data.GroupDescription;
import com.google.gerrit.common.data.LabelTypes;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.extensions.restapi.AuthException;
@@ -84,7 +83,6 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
private final Provider<ReviewDb> db;
private final IdentifiedUser currentUser;
private final IdentifiedUser.GenericFactory identifiedUserFactory;
private final ApprovalCategory.Id addReviewerCategoryId;
private final Config cfg;
private final ChangeHooks hooks;
private final AccountCache accountCache;
@@ -100,7 +98,6 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
Provider<ReviewDb> db,
IdentifiedUser currentUser,
IdentifiedUser.GenericFactory identifiedUserFactory,
LabelTypes labelTypes,
@GerritServerConfig Config cfg,
ChangeHooks hooks,
AccountCache accountCache,
@@ -118,9 +115,6 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
this.hooks = hooks;
this.accountCache = accountCache;
this.json = json;
this.addReviewerCategoryId = Iterables.getLast(labelTypes.getLabelTypes())
.getApprovalCategoryId();
}
@Override
@@ -234,7 +228,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
continue;
}
ChangeControl control = rsrc.getControl().forUser(user);
PatchSetApproval psa = dummyApproval(control.getChange(), psid, id);
PatchSetApproval psa = dummyApproval(control, psid, id);
result.reviewers.add(json.format(
new ReviewerInfo(id), control, ImmutableList.of(psa)));
toInsert.add(psa);
@@ -283,12 +277,13 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
|| AccountGroup.REGISTERED_USERS.equals(groupUUID));
}
private PatchSetApproval dummyApproval(Change change, PatchSet.Id patchSetId,
Account.Id reviewerId) {
PatchSetApproval dummyApproval =
new PatchSetApproval(new PatchSetApproval.Key(patchSetId, reviewerId,
addReviewerCategoryId), (short) 0);
dummyApproval.cache(change);
private PatchSetApproval dummyApproval(ChangeControl ctl,
PatchSet.Id patchSetId, Account.Id reviewerId) {
ApprovalCategory.Id id = new ApprovalCategory.Id(
Iterables.getLast(ctl.getLabelTypes().getLabelTypes()).getId());
PatchSetApproval dummyApproval = new PatchSetApproval(
new PatchSetApproval.Key(patchSetId, reviewerId, id), (short) 0);
dummyApproval.cache(ctl.getChange());
return dummyApproval;
}
}