public static AuthorizationDoc fromDto(IndexType indexType, IndexPermissions dto) {
    AuthorizationDoc res = new AuthorizationDoc(indexType, dto.getEntityUuid());
    if (dto.isAllowAnyone()) {
      return res.setAllowAnyone();
    }
    return res.setRestricted(dto.getGroupUuids(), dto.getUserUuids());
  }
@Test
  public void fromDto_ignores_userIds_and_groupUuids_if_allowAnyone_is_true() {
    IndexPermissions underTest = new IndexPermissions(randomAlphabetic(3), randomAlphabetic(4));
    IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(String::valueOf).forEach(underTest::addUserUuid);
    IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(Integer::toString).forEach(underTest::addGroupUuid);
    underTest.allowAnyone();

    AuthorizationDoc doc = AuthorizationDoc.fromDto(IndexType.main(Index.simple("foo"), "bar"), underTest);

    boolean auth_allowAnyone = doc.getField("auth_allowAnyone");
    assertThat(auth_allowAnyone).isTrue();
    try {
      doc.getField("auth_userIds");
      fail("should have thrown IllegalStateException");
    } catch (IllegalStateException e) {
      assertThat(e).hasMessage("Field auth_userIds not specified in query options");
    }
    try {
      doc.getField("auth_groupUuids");
      fail("should have thrown IllegalStateException");
    } catch (IllegalStateException e) {
      assertThat(e).hasMessage("Field auth_groupUuids not specified in query options");
    }
  }