Search in sources :

Example 1 with CapabilityDefinition

use of com.google.gerrit.extensions.config.CapabilityDefinition in project gerrit by GerritCodeReview.

the class TestPluginModule method configure.

@Override
protected void configure() {
    bind(CapabilityDefinition.class).annotatedWith(Exports.named(PLUGIN_CAPABILITY)).toInstance(new CapabilityDefinition() {

        @Override
        public String getDescription() {
            return "Print Hello";
        }
    });
    install(new RestApiModule() {

        @Override
        protected void configure() {
            DynamicMap.mapOf(binder(), PLUGIN_KIND);
            child(CONFIG_KIND, PLUGIN_COLLECTION).to(PluginCollection.class);
            get(PLUGIN_KIND).to(GetTestPlugin.class);
            create(PLUGIN_KIND).to(CreateTestPlugin.class);
        }
    });
}
Also used : RestApiModule(com.google.gerrit.extensions.restapi.RestApiModule) CapabilityDefinition(com.google.gerrit.extensions.config.CapabilityDefinition)

Example 2 with CapabilityDefinition

use of com.google.gerrit.extensions.config.CapabilityDefinition in project gerrit by GerritCodeReview.

the class PluginAccessIT method createModule.

@Override
public Module createModule() {
    return new AbstractModule() {

        @Override
        protected void configure() {
            bind(CapabilityDefinition.class).annotatedWith(Exports.named(TEST_PLUGIN_CAPABILITY)).toInstance(new CapabilityDefinition() {

                @Override
                public String getDescription() {
                    return "A Plugin Capability";
                }
            });
            bind(PluginProjectPermissionDefinition.class).annotatedWith(Exports.named(TEST_PLUGIN_PROJECT_PERMISSION)).toInstance(new PluginProjectPermissionDefinition() {

                @Override
                public String getDescription() {
                    return "A Plugin Project Permission";
                }
            });
        }
    };
}
Also used : CapabilityDefinition(com.google.gerrit.extensions.config.CapabilityDefinition) PluginProjectPermissionDefinition(com.google.gerrit.extensions.config.PluginProjectPermissionDefinition) AbstractModule(com.google.inject.AbstractModule)

Example 3 with CapabilityDefinition

use of com.google.gerrit.extensions.config.CapabilityDefinition in project gerrit by GerritCodeReview.

the class AccessIT method addPluginGlobalCapability.

@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);
        assertThatMap(updatedAccessSectionInfo.local.get(AccessSection.GLOBAL_CAPABILITIES).permissions).keys().containsAtLeastElementsIn(accessSectionInfo.permissions.keySet());
    }
}
Also used : PermissionInfo(com.google.gerrit.extensions.api.access.PermissionInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PermissionRuleInfo(com.google.gerrit.extensions.api.access.PermissionRuleInfo) ProjectAccessInfo(com.google.gerrit.extensions.api.access.ProjectAccessInfo) AccessSectionInfo(com.google.gerrit.extensions.api.access.AccessSectionInfo) ProjectAccessInput(com.google.gerrit.extensions.api.access.ProjectAccessInput) CapabilityDefinition(com.google.gerrit.extensions.config.CapabilityDefinition) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with CapabilityDefinition

use of com.google.gerrit.extensions.config.CapabilityDefinition in project gerrit by GerritCodeReview.

the class ListCapabilitiesTest method setUp.

@Before
public void setUp() throws Exception {
    AbstractModule mod = new AbstractModule() {

        @Override
        protected void configure() {
            DynamicMap.mapOf(binder(), CapabilityDefinition.class);
            DynamicMap.mapOf(binder(), PluginProjectPermissionDefinition.class);
            bind(CapabilityDefinition.class).annotatedWith(Exports.named("foo")).toInstance(new CapabilityDefinition() {

                @Override
                public String getDescription() {
                    return "Print Hello";
                }
            });
            bind(CapabilityDefinition.class).annotatedWith(Exports.named("bar")).toInstance(new CapabilityDefinition() {

                @Override
                public String getDescription() {
                    return "Print Hello";
                }
            });
            bind(PermissionBackend.class).to(FakePermissionBackend.class);
        }
    };
    injector = Guice.createInjector(mod);
}
Also used : PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) CapabilityDefinition(com.google.gerrit.extensions.config.CapabilityDefinition) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Aggregations

CapabilityDefinition (com.google.gerrit.extensions.config.CapabilityDefinition)4 AbstractModule (com.google.inject.AbstractModule)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)1 AccessSectionInfo (com.google.gerrit.extensions.api.access.AccessSectionInfo)1 PermissionInfo (com.google.gerrit.extensions.api.access.PermissionInfo)1 PermissionRuleInfo (com.google.gerrit.extensions.api.access.PermissionRuleInfo)1 ProjectAccessInfo (com.google.gerrit.extensions.api.access.ProjectAccessInfo)1 ProjectAccessInput (com.google.gerrit.extensions.api.access.ProjectAccessInput)1 PluginProjectPermissionDefinition (com.google.gerrit.extensions.config.PluginProjectPermissionDefinition)1 RestApiModule (com.google.gerrit.extensions.restapi.RestApiModule)1 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)1 Before (org.junit.Before)1 Test (org.junit.Test)1