GrantRevertPermission only adds the permisions once
Until now, if the permission somehow already existed, it will add
it another time.
This change ensures that it only adds the permission once.
Also, this change adds a minor reformat to the other test.
Change-Id: If68f0def0fe042b1a3f669b7118e8138aa29e7fb
(cherry picked from commit 5164b2cb5a)
This commit is contained in:
@@ -18,6 +18,7 @@ import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS
|
||||
import static com.google.gerrit.server.schema.AclUtil.grant;
|
||||
|
||||
import com.google.gerrit.common.data.AccessSection;
|
||||
import com.google.gerrit.common.data.GroupReference;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.entities.Project;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
@@ -57,12 +58,18 @@ public class GrantRevertPermission {
|
||||
}
|
||||
|
||||
public void execute(Project.NameKey projectName) throws IOException, ConfigInvalidException {
|
||||
GroupReference registeredUsers = systemGroupBackend.getGroup(REGISTERED_USERS);
|
||||
try (Repository repo = repoManager.openRepository(projectName)) {
|
||||
MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, projectName, repo);
|
||||
ProjectConfig projectConfig = projectConfigFactory.read(md);
|
||||
AccessSection heads = projectConfig.getAccessSection(AccessSection.HEADS, true);
|
||||
|
||||
grant(projectConfig, heads, Permission.REVERT, systemGroupBackend.getGroup(REGISTERED_USERS));
|
||||
Permission permission = heads.getPermission(Permission.REVERT);
|
||||
if (permission != null && permission.getRule(registeredUsers) != null) {
|
||||
// permission already exists, don't do anything.
|
||||
return;
|
||||
}
|
||||
grant(projectConfig, heads, Permission.REVERT, registeredUsers);
|
||||
|
||||
md.getCommitBuilder().setAuthor(serverUser);
|
||||
md.getCommitBuilder().setCommitter(serverUser);
|
||||
|
||||
Reference in New Issue
Block a user