Abandon: Fail earlier when abandon is not permitted

Move the check to the beginning of the apply method so that it will fail
sooner when the control does not allow the abandon operation.

Inline the call to asIdentifiedUser so it's not necessary to keep the
variable that's only used in the following call.

Remove unneccessary 'final' in the apply method's signature.

Change-Id: I52e3d471703b75d0576a4d0743943393b819858b
This commit is contained in:
David Pursehouse
2016-02-24 10:47:49 +09:00
parent 61d2ccbb0a
commit 7873f2ea88

View File

@@ -31,7 +31,6 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.git.BatchUpdate;
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
@@ -80,15 +79,14 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
}
@Override
public ChangeInfo apply(ChangeResource req,
final AbandonInput input)
public ChangeInfo apply(ChangeResource req, AbandonInput input)
throws RestApiException, UpdateException, OrmException {
ChangeControl control = req.getControl();
IdentifiedUser caller = control.getUser().asIdentifiedUser();
if (!control.canAbandon(dbProvider.get())) {
throw new AuthException("abandon not permitted");
}
Change change = abandon(control, input.message, caller.getAccount());
Change change = abandon(control, input.message,
control.getUser().asIdentifiedUser().getAccount());
return json.create(ChangeJson.NO_OPTIONS).format(change);
}