use of com.enonic.xp.admin.widget.WidgetDescriptor in project xp by enonic.
the class WidgetHandlerWorker method execute.
@Override
public PortalResponse execute() throws Exception {
if (this.request.getMode() != RenderMode.ADMIN) {
throw WebException.forbidden("Render mode must be ADMIN.");
}
// Retrieves the WidgetDescriptor
final WidgetDescriptor widgetDescriptor = widgetDescriptorService.getByKey(descriptorKey);
if (widgetDescriptor == null) {
throw WebException.notFound(String.format("Widget [%s] not found", descriptorKey));
}
// Checks if the access to WidgetDescriptor is allowed
final PrincipalKeys principals = ContextAccessor.current().getAuthInfo().getPrincipals();
if (!widgetDescriptor.isAccessAllowed(principals)) {
throw WebException.forbidden(String.format("You don't have permission to access [%s]", descriptorKey));
}
// Renders the widget
this.request.setApplicationKey(this.descriptorKey.getApplicationKey());
final ResourceKey scriptDir = ResourceKey.from(descriptorKey.getApplicationKey(), "admin/widgets/" + descriptorKey.getName());
final ControllerScript controllerScript = this.controllerScriptFactory.fromDir(scriptDir);
return controllerScript.execute(this.request);
}
use of com.enonic.xp.admin.widget.WidgetDescriptor in project xp by enonic.
the class WidgetDescriptorLoader method load.
@Override
public WidgetDescriptor load(final DescriptorKey key, final Resource resource) {
final WidgetDescriptor.Builder builder = WidgetDescriptor.create();
builder.key(key);
final String descriptorXml = resource.readString();
parseXml(key.getApplicationKey(), builder, descriptorXml);
final Icon icon = loadIcon(key);
builder.setIcon(icon);
return builder.build();
}
use of com.enonic.xp.admin.widget.WidgetDescriptor in project xp by enonic.
the class WidgetHandlerTest method mockDescriptor.
private void mockDescriptor(boolean hasAccess) {
WidgetDescriptor descriptor = Mockito.mock(WidgetDescriptor.class);
Mockito.when(descriptor.isAccessAllowed(Mockito.any(PrincipalKeys.class))).thenReturn(hasAccess);
Mockito.when(this.widgetDescriptorService.getByKey(Mockito.any(DescriptorKey.class))).thenReturn(descriptor);
}
use of com.enonic.xp.admin.widget.WidgetDescriptor in project xp by enonic.
the class WidgetDescriptorLoaderTest method testPostProcess.
@Test
public void testPostProcess() {
final WidgetDescriptor descriptor = WidgetDescriptor.create().key(DescriptorKey.from("myapp:a")).build();
assertSame(descriptor, this.loader.postProcess(descriptor));
}
use of com.enonic.xp.admin.widget.WidgetDescriptor in project xp by enonic.
the class WidgetDescriptorLoaderTest method testLoadMin.
@Test
public void testLoadMin() {
final DescriptorKey descriptorKey = DescriptorKey.from("myapp1:widget2");
final ResourceKey resourceKey = this.loader.toResource(descriptorKey);
final Resource resource = this.resourceService.getResource(resourceKey);
final WidgetDescriptor descriptor = this.loader.load(descriptorKey, resource);
assertEquals("MyWidget2", descriptor.getDisplayName());
assertEquals("MyWidget2 description", descriptor.getDescription());
assertEquals(1, descriptor.getInterfaces().size());
assertTrue(descriptor.getInterfaces().contains("com.enonic.xp.my-interface"));
assertNull(descriptor.getAllowedPrincipals());
}
Aggregations