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;
|
package com.google.gerrit.server.project;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
import com.google.gerrit.common.ChangeHooks;
|
||||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||||
import com.google.gerrit.extensions.restapi.RestView;
|
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;
|
||||||
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
|
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
|
||||||
import com.google.gerrit.reviewdb.client.Project.SubmitType;
|
import com.google.gerrit.reviewdb.client.Project.SubmitType;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
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.MetaDataUpdate;
|
||||||
import com.google.gerrit.server.git.ProjectConfig;
|
import com.google.gerrit.server.git.ProjectConfig;
|
||||||
import com.google.gerrit.server.git.TransferConfig;
|
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.ConfigInvalidException;
|
||||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||||
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -56,6 +62,7 @@ public class PutConfig implements RestModifyView<ProjectResource, Input> {
|
|||||||
private final TransferConfig config;
|
private final TransferConfig config;
|
||||||
private final DynamicMap<RestView<ProjectResource>> views;
|
private final DynamicMap<RestView<ProjectResource>> views;
|
||||||
private final Provider<CurrentUser> currentUser;
|
private final Provider<CurrentUser> currentUser;
|
||||||
|
private final ChangeHooks hooks;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PutConfig(MetaDataUpdate.User metaDataUpdateFactory,
|
PutConfig(MetaDataUpdate.User metaDataUpdateFactory,
|
||||||
@ -64,6 +71,7 @@ public class PutConfig implements RestModifyView<ProjectResource, Input> {
|
|||||||
ProjectState.Factory projectStateFactory,
|
ProjectState.Factory projectStateFactory,
|
||||||
TransferConfig config,
|
TransferConfig config,
|
||||||
DynamicMap<RestView<ProjectResource>> views,
|
DynamicMap<RestView<ProjectResource>> views,
|
||||||
|
ChangeHooks hooks,
|
||||||
Provider<CurrentUser> currentUser) {
|
Provider<CurrentUser> currentUser) {
|
||||||
this.metaDataUpdateFactory = metaDataUpdateFactory;
|
this.metaDataUpdateFactory = metaDataUpdateFactory;
|
||||||
this.projectCache = projectCache;
|
this.projectCache = projectCache;
|
||||||
@ -71,6 +79,7 @@ public class PutConfig implements RestModifyView<ProjectResource, Input> {
|
|||||||
this.projectStateFactory = projectStateFactory;
|
this.projectStateFactory = projectStateFactory;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.views = views;
|
this.views = views;
|
||||||
|
this.hooks = hooks;
|
||||||
this.currentUser = currentUser;
|
this.currentUser = currentUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +137,15 @@ public class PutConfig implements RestModifyView<ProjectResource, Input> {
|
|||||||
|
|
||||||
md.setMessage("Modified project settings\n");
|
md.setMessage("Modified project settings\n");
|
||||||
try {
|
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()))
|
(new PerRequestProjectControlCache(projectCache, self.get()))
|
||||||
.evict(projectConfig.getProject());
|
.evict(projectConfig.getProject());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -16,6 +16,7 @@ package com.google.gerrit.server.project;
|
|||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.base.Strings;
|
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.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
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.ResourceNotFoundException;
|
||||||
import com.google.gerrit.extensions.restapi.Response;
|
import com.google.gerrit.extensions.restapi.Response;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
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.reviewdb.client.Project;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
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.ConfigInvalidException;
|
||||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||||
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -46,13 +49,16 @@ class PutDescription implements RestModifyView<ProjectResource, Input> {
|
|||||||
private final ProjectCache cache;
|
private final ProjectCache cache;
|
||||||
private final MetaDataUpdate.Server updateFactory;
|
private final MetaDataUpdate.Server updateFactory;
|
||||||
private final GitRepositoryManager gitMgr;
|
private final GitRepositoryManager gitMgr;
|
||||||
|
private final ChangeHooks hooks;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PutDescription(ProjectCache cache,
|
PutDescription(ProjectCache cache,
|
||||||
MetaDataUpdate.Server updateFactory,
|
MetaDataUpdate.Server updateFactory,
|
||||||
|
ChangeHooks hooks,
|
||||||
GitRepositoryManager gitMgr) {
|
GitRepositoryManager gitMgr) {
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
this.updateFactory = updateFactory;
|
this.updateFactory = updateFactory;
|
||||||
|
this.hooks = hooks;
|
||||||
this.gitMgr = gitMgr;
|
this.gitMgr = gitMgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +91,14 @@ class PutDescription implements RestModifyView<ProjectResource, Input> {
|
|||||||
}
|
}
|
||||||
md.setAuthor(user);
|
md.setAuthor(user);
|
||||||
md.setMessage(msg);
|
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());
|
cache.evict(ctl.getProject());
|
||||||
gitMgr.setProjectDescription(
|
gitMgr.setProjectDescription(
|
||||||
resource.getNameKey(),
|
resource.getNameKey(),
|
||||||
|
Loading…
Reference in New Issue
Block a user