SetAccess: Test adding a plugin global capability
Signed-off-by: Edwin Kempin <ekempin@google.com> Change-Id: If01d2b0f83c54b890190bcce3368b2b59eddf5db
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
package com.google.gerrit.acceptance;
|
package com.google.gerrit.acceptance;
|
||||||
|
|
||||||
import com.google.gerrit.extensions.api.changes.ActionVisitor;
|
import com.google.gerrit.extensions.api.changes.ActionVisitor;
|
||||||
|
import com.google.gerrit.extensions.config.CapabilityDefinition;
|
||||||
import com.google.gerrit.extensions.config.DownloadScheme;
|
import com.google.gerrit.extensions.config.DownloadScheme;
|
||||||
import com.google.gerrit.extensions.events.AccountIndexedListener;
|
import com.google.gerrit.extensions.events.AccountIndexedListener;
|
||||||
import com.google.gerrit.extensions.events.ChangeIndexedListener;
|
import com.google.gerrit.extensions.events.ChangeIndexedListener;
|
||||||
@@ -47,6 +48,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ExtensionRegistry {
|
public class ExtensionRegistry {
|
||||||
|
public static final String PLUGIN_NAME = "myPlugin";
|
||||||
|
|
||||||
private final DynamicSet<AccountIndexedListener> accountIndexedListeners;
|
private final DynamicSet<AccountIndexedListener> accountIndexedListeners;
|
||||||
private final DynamicSet<ChangeIndexedListener> changeIndexedListeners;
|
private final DynamicSet<ChangeIndexedListener> changeIndexedListeners;
|
||||||
private final DynamicSet<GroupIndexedListener> groupIndexedListeners;
|
private final DynamicSet<GroupIndexedListener> groupIndexedListeners;
|
||||||
@@ -71,6 +74,7 @@ public class ExtensionRegistry {
|
|||||||
accountActivationValidationListeners;
|
accountActivationValidationListeners;
|
||||||
private final DynamicSet<OnSubmitValidationListener> onSubmitValidationListeners;
|
private final DynamicSet<OnSubmitValidationListener> onSubmitValidationListeners;
|
||||||
private final DynamicSet<WorkInProgressStateChangedListener> workInProgressStateChangedListeners;
|
private final DynamicSet<WorkInProgressStateChangedListener> workInProgressStateChangedListeners;
|
||||||
|
private final DynamicMap<CapabilityDefinition> capabilityDefinitions;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ExtensionRegistry(
|
ExtensionRegistry(
|
||||||
@@ -96,7 +100,8 @@ public class ExtensionRegistry {
|
|||||||
DynamicSet<GroupBackend> groupBackends,
|
DynamicSet<GroupBackend> groupBackends,
|
||||||
DynamicSet<AccountActivationValidationListener> accountActivationValidationListeners,
|
DynamicSet<AccountActivationValidationListener> accountActivationValidationListeners,
|
||||||
DynamicSet<OnSubmitValidationListener> onSubmitValidationListeners,
|
DynamicSet<OnSubmitValidationListener> onSubmitValidationListeners,
|
||||||
DynamicSet<WorkInProgressStateChangedListener> workInProgressStateChangedListeners) {
|
DynamicSet<WorkInProgressStateChangedListener> workInProgressStateChangedListeners,
|
||||||
|
DynamicMap<CapabilityDefinition> capabilityDefinitions) {
|
||||||
this.accountIndexedListeners = accountIndexedListeners;
|
this.accountIndexedListeners = accountIndexedListeners;
|
||||||
this.changeIndexedListeners = changeIndexedListeners;
|
this.changeIndexedListeners = changeIndexedListeners;
|
||||||
this.groupIndexedListeners = groupIndexedListeners;
|
this.groupIndexedListeners = groupIndexedListeners;
|
||||||
@@ -120,6 +125,7 @@ public class ExtensionRegistry {
|
|||||||
this.accountActivationValidationListeners = accountActivationValidationListeners;
|
this.accountActivationValidationListeners = accountActivationValidationListeners;
|
||||||
this.onSubmitValidationListeners = onSubmitValidationListeners;
|
this.onSubmitValidationListeners = onSubmitValidationListeners;
|
||||||
this.workInProgressStateChangedListeners = workInProgressStateChangedListeners;
|
this.workInProgressStateChangedListeners = workInProgressStateChangedListeners;
|
||||||
|
this.capabilityDefinitions = capabilityDefinitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Registration newRegistration() {
|
public Registration newRegistration() {
|
||||||
@@ -227,6 +233,10 @@ public class ExtensionRegistry {
|
|||||||
return add(workInProgressStateChangedListeners, workInProgressStateChangedListener);
|
return add(workInProgressStateChangedListeners, workInProgressStateChangedListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Registration add(CapabilityDefinition capabilityDefinition, String exportName) {
|
||||||
|
return add(capabilityDefinitions, capabilityDefinition, exportName);
|
||||||
|
}
|
||||||
|
|
||||||
private <T> Registration add(DynamicSet<T> dynamicSet, T extension) {
|
private <T> Registration add(DynamicSet<T> dynamicSet, T extension) {
|
||||||
return add(dynamicSet, extension, "gerrit");
|
return add(dynamicSet, extension, "gerrit");
|
||||||
}
|
}
|
||||||
@@ -240,7 +250,7 @@ public class ExtensionRegistry {
|
|||||||
private <T> Registration add(DynamicMap<T> dynamicMap, T extension, String exportName) {
|
private <T> Registration add(DynamicMap<T> dynamicMap, T extension, String exportName) {
|
||||||
RegistrationHandle registrationHandle =
|
RegistrationHandle registrationHandle =
|
||||||
((PrivateInternals_DynamicMapImpl<T>) dynamicMap)
|
((PrivateInternals_DynamicMapImpl<T>) dynamicMap)
|
||||||
.put("myPlugin", exportName, Providers.of(extension));
|
.put(PLUGIN_NAME, exportName, Providers.of(extension));
|
||||||
registrationHandles.add(registrationHandle);
|
registrationHandles.add(registrationHandle);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import com.google.gerrit.extensions.client.ChangeStatus;
|
|||||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||||
import com.google.gerrit.extensions.common.GroupInfo;
|
import com.google.gerrit.extensions.common.GroupInfo;
|
||||||
import com.google.gerrit.extensions.common.WebLinkInfo;
|
import com.google.gerrit.extensions.common.WebLinkInfo;
|
||||||
|
import com.google.gerrit.extensions.config.CapabilityDefinition;
|
||||||
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.ResourceNotFoundException;
|
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||||
@@ -455,6 +456,41 @@ public class AccessIT extends AbstractDaemonTest {
|
|||||||
.containsAtLeastElementsIn(accessSectionInfo.permissions.keySet());
|
.containsAtLeastElementsIn(accessSectionInfo.permissions.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addPluginGlobalCapability() throws Exception {
|
||||||
|
try (Registration registration =
|
||||||
|
extensionRegistry
|
||||||
|
.newRegistration()
|
||||||
|
.add(
|
||||||
|
new CapabilityDefinition() {
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "A Plugin Global Capability";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fooCapability")) {
|
||||||
|
ProjectAccessInput accessInput = newProjectAccessInput();
|
||||||
|
AccessSectionInfo accessSectionInfo = newAccessSectionInfo();
|
||||||
|
|
||||||
|
PermissionInfo foo = newPermissionInfo();
|
||||||
|
PermissionRuleInfo pri = new PermissionRuleInfo(PermissionRuleInfo.Action.ALLOW, false);
|
||||||
|
foo.rules.put(SystemGroupBackend.REGISTERED_USERS.get(), pri);
|
||||||
|
accessSectionInfo.permissions.put(ExtensionRegistry.PLUGIN_NAME + "-fooCapability", foo);
|
||||||
|
|
||||||
|
accessInput.add.put(AccessSection.GLOBAL_CAPABILITIES, accessSectionInfo);
|
||||||
|
|
||||||
|
ProjectAccessInfo updatedAccessSectionInfo =
|
||||||
|
gApi.projects().name(allProjects.get()).access(accessInput);
|
||||||
|
assertThat(
|
||||||
|
updatedAccessSectionInfo
|
||||||
|
.local
|
||||||
|
.get(AccessSection.GLOBAL_CAPABILITIES)
|
||||||
|
.permissions
|
||||||
|
.keySet())
|
||||||
|
.containsAtLeastElementsIn(accessSectionInfo.permissions.keySet());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addPermissionAsGlobalCapability() throws Exception {
|
public void addPermissionAsGlobalCapability() throws Exception {
|
||||||
ProjectAccessInput accessInput = newProjectAccessInput();
|
ProjectAccessInput accessInput = newProjectAccessInput();
|
||||||
|
|||||||
Reference in New Issue
Block a user