Emit ref-updated event when editing project access via web UI
3daa739e13
took care of firing the ref-updated event for updates via the
web UI access pane, but not changes via the web UI general pane, which
uses the REST 'PUT /projects/:project-name/config' endpoint. This commit
takes care of that case, as well as the REST
'PUT /projects/:project-name/description' endpoint.
Note: there's still no ref-updated event for the case of changing a
project from "hidden" state back to read-only or "active" as hooks are
suppressed for hidden projects deeper in the code.
Bug: Issue 2571
Change-Id: I0a260011c0968193ccb5900a18935e654d25f042
This commit is contained in:
parent
483f12b8dc
commit
701218b8d0
@ -14,17 +14,22 @@
|
||||
|
||||
package com.google.gerrit.server.project;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.common.ChangeHooks;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
|
||||
import com.google.gerrit.reviewdb.client.Project.SubmitType;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.git.TransferConfig;
|
||||
@ -34,6 +39,7 @@ import com.google.inject.Provider;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -56,6 +62,7 @@ public class PutConfig implements RestModifyView<ProjectResource, Input> {
|
||||
private final TransferConfig config;
|
||||
private final DynamicMap<RestView<ProjectResource>> views;
|
||||
private final Provider<CurrentUser> currentUser;
|
||||
private final ChangeHooks hooks;
|
||||
|
||||
@Inject
|
||||
PutConfig(MetaDataUpdate.User metaDataUpdateFactory,
|
||||
@ -64,6 +71,7 @@ public class PutConfig implements RestModifyView<ProjectResource, Input> {
|
||||
ProjectState.Factory projectStateFactory,
|
||||
TransferConfig config,
|
||||
DynamicMap<RestView<ProjectResource>> views,
|
||||
ChangeHooks hooks,
|
||||
Provider<CurrentUser> currentUser) {
|
||||
this.metaDataUpdateFactory = metaDataUpdateFactory;
|
||||
this.projectCache = projectCache;
|
||||
@ -71,6 +79,7 @@ public class PutConfig implements RestModifyView<ProjectResource, Input> {
|
||||
this.projectStateFactory = projectStateFactory;
|
||||
this.config = config;
|
||||
this.views = views;
|
||||
this.hooks = hooks;
|
||||
this.currentUser = currentUser;
|
||||
}
|
||||
|
||||
@ -128,7 +137,15 @@ public class PutConfig implements RestModifyView<ProjectResource, Input> {
|
||||
|
||||
md.setMessage("Modified project settings\n");
|
||||
try {
|
||||
projectConfig.commit(md);
|
||||
ObjectId baseRev = projectConfig.getRevision();
|
||||
ObjectId commitRev = projectConfig.commit(md);
|
||||
// Only fire hook if project was actually changed.
|
||||
if (!Objects.equal(baseRev, commitRev)) {
|
||||
IdentifiedUser user = (IdentifiedUser) currentUser.get();
|
||||
hooks.doRefUpdatedHook(
|
||||
new Branch.NameKey(projectName, GitRepositoryManager.REF_CONFIG),
|
||||
baseRev, commitRev, user.getAccount());
|
||||
};
|
||||
(new PerRequestProjectControlCache(projectCache, self.get()))
|
||||
.evict(projectConfig.getProject());
|
||||
} catch (IOException e) {
|
||||
|
@ -16,6 +16,7 @@ package com.google.gerrit.server.project;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.common.ChangeHooks;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||
@ -23,6 +24,7 @@ import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
@ -33,6 +35,7 @@ import com.google.inject.Inject;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -46,13 +49,16 @@ class PutDescription implements RestModifyView<ProjectResource, Input> {
|
||||
private final ProjectCache cache;
|
||||
private final MetaDataUpdate.Server updateFactory;
|
||||
private final GitRepositoryManager gitMgr;
|
||||
private final ChangeHooks hooks;
|
||||
|
||||
@Inject
|
||||
PutDescription(ProjectCache cache,
|
||||
MetaDataUpdate.Server updateFactory,
|
||||
ChangeHooks hooks,
|
||||
GitRepositoryManager gitMgr) {
|
||||
this.cache = cache;
|
||||
this.updateFactory = updateFactory;
|
||||
this.hooks = hooks;
|
||||
this.gitMgr = gitMgr;
|
||||
}
|
||||
|
||||
@ -85,7 +91,14 @@ class PutDescription implements RestModifyView<ProjectResource, Input> {
|
||||
}
|
||||
md.setAuthor(user);
|
||||
md.setMessage(msg);
|
||||
config.commit(md);
|
||||
ObjectId baseRev = config.getRevision();
|
||||
ObjectId commitRev = config.commit(md);
|
||||
// Only fire hook if project was actually changed.
|
||||
if (!Objects.equal(baseRev, commitRev)) {
|
||||
hooks.doRefUpdatedHook(
|
||||
new Branch.NameKey(resource.getNameKey(), GitRepositoryManager.REF_CONFIG),
|
||||
baseRev, commitRev, user.getAccount());
|
||||
}
|
||||
cache.evict(ctl.getProject());
|
||||
gitMgr.setProjectDescription(
|
||||
resource.getNameKey(),
|
||||
|
Loading…
Reference in New Issue
Block a user