Search in sources :

Example 11 with ViewDTO

use of org.graylog.plugins.views.search.views.ViewDTO in project graylog2-server by Graylog2.

the class DashboardV1FacadeTest method setUp.

@Before
public void setUp() throws IOException {
    objectMapper.registerSubtypes(new NamedType(AggregationConfigDTO.class, AggregationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(MessageListConfigDTO.class, MessageListConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(LineVisualizationConfigDTO.class, LineVisualizationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(BarVisualizationConfigDTO.class, BarVisualizationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(NumberVisualizationConfigDTO.class, NumberVisualizationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(TimeHistogramConfigDTO.class, TimeHistogramConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(ValueConfigDTO.class, ValueConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(PivotSortConfig.class, PivotSortConfig.Type));
    objectMapper.registerSubtypes(new NamedType(PivotEntity.class, PivotEntity.NAME));
    objectMapper.registerSubtypes(new NamedType(PivotSort.class, PivotSort.Type));
    objectMapper.registerSubtypes(new NamedType(OrFilter.class, OrFilter.NAME));
    objectMapper.registerSubtypes(new NamedType(StreamFilter.class, StreamFilter.NAME));
    objectMapper.registerSubtypes(new NamedType(QueryStringFilter.class, QueryStringFilter.NAME));
    objectMapper.registerSubtypes(new NamedType(AutoIntervalDTO.class, AutoIntervalDTO.type));
    final MongoConnection mongoConnection = mongodb.mongoConnection();
    final MongoJackObjectMapperProvider mapper = new MongoJackObjectMapperProvider(objectMapper);
    searchDbService = new ViewFacadeTest.TestSearchDBService(mongoConnection, mapper);
    viewService = new ViewFacadeTest.TestViewService(mongoConnection, mapper, null);
    viewSummaryService = new ViewFacadeTest.TestViewSummaryService(mongoConnection, mapper);
    userService = mock(UserService.class);
    final UserImpl fakeUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "testuser"));
    when(userService.load("testuser")).thenReturn(fakeUser);
    final DashboardWidgetConverter dashboardWidgetConverter = new DashboardWidgetConverter();
    final EntityConverter entityConverter = new EntityConverter(dashboardWidgetConverter);
    facade = new DashboardV1Facade(objectMapper, searchDbService, entityConverter, viewService, viewSummaryService, userService);
    final URL resourceUrl = Resources.getResource(DashboardV1Facade.class, "content-pack-dashboard-v1.json");
    final ContentPack contentPack = objectMapper.readValue(resourceUrl, ContentPack.class);
    assertThat(contentPack).isInstanceOf(ContentPackV1.class);
    final ContentPackV1 contentPackV1 = (ContentPackV1) contentPack;
    final Entity entity = contentPackV1.entities().iterator().next();
    final StreamImpl stream = new StreamImpl(Collections.emptyMap());
    final Map<EntityDescriptor, Object> nativeEntities = new HashMap<>(1);
    nativeEntities.put(EntityDescriptor.create("58b3d55a-51ad-4b3e-865c-85776016a151", ModelTypes.STREAM_V1), stream);
    final NativeEntity<ViewDTO> nativeEntity = facade.createNativeEntity(entity, ImmutableMap.of(), nativeEntities, "testuser");
    assertThat(nativeEntity).isNotNull();
    viewDTO = nativeEntity.entity();
}
Also used : NumberVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.NumberVisualizationConfigDTO) EntityConverter(org.graylog2.contentpacks.facades.dashboardV1.EntityConverter) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) PivotEntity(org.graylog2.contentpacks.model.entities.PivotEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) HashMap(java.util.HashMap) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) TimeHistogramConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.TimeHistogramConfigDTO) AutoIntervalDTO(org.graylog.plugins.views.search.views.widgets.aggregation.AutoIntervalDTO) PivotSortConfig(org.graylog.plugins.views.search.views.widgets.aggregation.sort.PivotSortConfig) StreamFilter(org.graylog.plugins.views.search.filter.StreamFilter) QueryStringFilter(org.graylog.plugins.views.search.filter.QueryStringFilter) DashboardV1Facade(org.graylog2.contentpacks.facades.dashboardV1.DashboardV1Facade) URL(java.net.URL) AggregationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.AggregationConfigDTO) ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) PasswordAlgorithmFactory(org.graylog2.security.PasswordAlgorithmFactory) MessageListConfigDTO(org.graylog.plugins.views.search.views.widgets.messagelist.MessageListConfigDTO) ContentPackV1(org.graylog2.contentpacks.model.ContentPackV1) UserImpl(org.graylog2.users.UserImpl) Permissions(org.graylog2.shared.security.Permissions) DashboardWidgetConverter(org.graylog2.contentpacks.facades.dashboardV1.DashboardWidgetConverter) BarVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.BarVisualizationConfigDTO) UserService(org.graylog2.shared.users.UserService) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ContentPack(org.graylog2.contentpacks.model.ContentPack) OrFilter(org.graylog.plugins.views.search.filter.OrFilter) LineVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.LineVisualizationConfigDTO) PivotSort(org.graylog.plugins.views.search.searchtypes.pivot.PivotSort) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) StreamImpl(org.graylog2.streams.StreamImpl) ValueConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.ValueConfigDTO) MongoConnection(org.graylog2.database.MongoConnection) PivotEntity(org.graylog2.contentpacks.model.entities.PivotEntity) Before(org.junit.Before)

Example 12 with ViewDTO

use of org.graylog.plugins.views.search.views.ViewDTO in project graylog2-server by Graylog2.

the class ViewFacadeTest method itShouldRemoveAViewByDTO.

@Test
@MongoDBFixtures("ViewFacadeTest.json")
public void itShouldRemoveAViewByDTO() {
    final ViewDTO viewDTO = viewService.get(viewId).orElseThrow(() -> new NotFoundException("Missing view with id: " + viewId));
    assertThat(facade.listEntityExcerpts()).hasSize(1);
    facade.delete(viewDTO);
    assertThat(facade.listEntityExcerpts()).hasSize(0);
}
Also used : ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) NotFoundException(javax.ws.rs.NotFoundException) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 13 with ViewDTO

use of org.graylog.plugins.views.search.views.ViewDTO in project graylog2-server by Graylog2.

the class UserPermissionsToGrantsMigrationTest method migrateAllUserPermissions.

@Test
void migrateAllUserPermissions() {
    final ViewDTO view1 = mock(ViewDTO.class);
    final ViewDTO view2 = mock(ViewDTO.class);
    when(view1.type()).thenReturn(ViewDTO.Type.DASHBOARD);
    when(view2.type()).thenReturn(ViewDTO.Type.SEARCH);
    when(viewService.get("5c40ad603c034441a56943be")).thenReturn(Optional.of(view1));
    when(viewService.get("5c40ad603c034441a56943c0")).thenReturn(Optional.of(view2));
    User testuser1 = userService.load("testuser1");
    assertThat(testuser1).isNotNull();
    assertThat(testuser1.getPermissions().size()).isEqualTo(11 + userSelfEditPermissionCount);
    assertThat(dbGrantService.getForGranteesOrGlobal(ImmutableSet.of(grnRegistry.ofUser(testuser1)))).isEmpty();
    migration.upgrade();
    // check created grants for testuser1
    final ImmutableSet<GrantDTO> grants = dbGrantService.getForGranteesOrGlobal(ImmutableSet.of(grnRegistry.ofUser(testuser1)));
    assertGrantInSet(grants, "grn::::dashboard:5e2afc66cd19517ec2dabadd", Capability.VIEW);
    assertGrantInSet(grants, "grn::::dashboard:5e2afc66cd19517ec2dabadf", Capability.MANAGE);
    assertGrantInSet(grants, "grn::::stream:5c40ad603c034441a56942bd", Capability.VIEW);
    assertGrantInSet(grants, "grn::::stream:5e2f5cfb4868e67ad4da562d", Capability.VIEW);
    assertGrantInSet(grants, "grn::::dashboard:5c40ad603c034441a56943be", Capability.MANAGE);
    assertGrantInSet(grants, "grn::::search:5c40ad603c034441a56943c0", Capability.VIEW);
    assertGrantInSet(grants, "grn::::event_definition:5c40ad603c034441a56942bf", Capability.MANAGE);
    assertGrantInSet(grants, "grn::::event_definition:5c40ad603c034441a56942c0", Capability.VIEW);
    assertThat(grants.size()).isEqualTo(8);
    // reload user and check that all migrated permissions have been removed
    testuser1 = userService.load("testuser1");
    assertThat(testuser1).isNotNull();
    assertThat(testuser1.getPermissions().size()).isEqualTo(userSelfEditPermissionCount);
}
Also used : GrantDTO(org.graylog.security.GrantDTO) ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) User(org.graylog2.plugin.database.users.User) Test(org.junit.jupiter.api.Test)

Example 14 with ViewDTO

use of org.graylog.plugins.views.search.views.ViewDTO in project graylog2-server by Graylog2.

the class ViewsResource method delete.

@DELETE
@Path("{id}")
@ApiOperation("Delete view")
@AuditEvent(type = ViewsAuditEventTypes.VIEW_DELETE)
public ViewDTO delete(@ApiParam(name = "id") @PathParam("id") @NotEmpty String id, @Context SearchUser searchUser) {
    final ViewDTO view = loadView(id);
    if (!searchUser.canDeleteView(view)) {
        throw new ForbiddenException("Unable to delete " + summarize(view) + ".");
    }
    dbService.delete(id);
    triggerDeletedEvent(view);
    return view;
}
Also used : ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) ForbiddenException(javax.ws.rs.ForbiddenException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 15 with ViewDTO

use of org.graylog.plugins.views.search.views.ViewDTO in project graylog2-server by Graylog2.

the class ViewFacade method exportEntity.

@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
    final ModelId modelId = entityDescriptor.id();
    final Optional<ViewDTO> optionalView = viewService.get(modelId.id());
    if (optionalView.isPresent()) {
        return Optional.of(exportNativeEntity(optionalView.get(), entityDescriptorIds));
    }
    LOG.debug("Couldn't find view {}", entityDescriptor);
    return Optional.empty();
}
Also used : ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) ModelId(org.graylog2.contentpacks.model.ModelId)

Aggregations

ViewDTO (org.graylog.plugins.views.search.views.ViewDTO)15 Test (org.junit.Test)5 ApiOperation (io.swagger.annotations.ApiOperation)4 NotFoundException (javax.ws.rs.NotFoundException)4 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)4 ForbiddenException (javax.ws.rs.ForbiddenException)3 Path (javax.ws.rs.Path)3 Search (org.graylog.plugins.views.search.Search)3 StreamFilter (org.graylog.plugins.views.search.filter.StreamFilter)3 SearchUser (org.graylog.plugins.views.search.permissions.SearchUser)3 AuditEvent (org.graylog2.audit.jersey.AuditEvent)3 Entity (org.graylog2.contentpacks.model.entities.Entity)3 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)3 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)3 PivotEntity (org.graylog2.contentpacks.model.entities.PivotEntity)3 ViewEntity (org.graylog2.contentpacks.model.entities.ViewEntity)3 ViewStateEntity (org.graylog2.contentpacks.model.entities.ViewStateEntity)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BadRequestException (javax.ws.rs.BadRequestException)2