/** * Creates a type that requires to verify that user has the read permission * when searching for documents. * * Both types {@code typeName} and "authorization" are created. Documents * must be created with _parent and _routing having the parent uuid as values. * * @see NewIndex.NewIndexType#requireProjectAuthorization() */ private static NewIndex.NewIndexType enableProjectAuthorization(NewIndex.NewIndexType type) { type.setAttribute("_parent", ImmutableMap.of("type", TYPE_AUTHORIZATION)); type.setAttribute("_routing", ImmutableMap.of("required", true)); NewIndex.NewIndexType authType = type.getIndex().createType(TYPE_AUTHORIZATION); authType.setAttribute("_routing", ImmutableMap.of("required", true)); authType.createLongField(FIELD_GROUP_IDS); authType.createLongField(FIELD_USER_IDS); authType.createBooleanField(FIELD_ALLOW_ANYONE); authType.setEnableSource(false); return type; }
@Test public void index_with_source() { NewIndex index = new NewIndex("issues", defaultSettingsConfiguration); NewIndex.NewIndexType mapping = index.createType("issue"); mapping.setEnableSource(true); mapping = index.getTypes().get("issue"); assertThat(mapping).isNotNull(); assertThat(getAttributeAsMap(mapping, "_source")).containsExactly(entry("enabled", true)); }
@Test public void index_without_source() { NewIndex index = new NewIndex("issues", defaultSettingsConfiguration); NewIndex.NewIndexType mapping = index.createType("issue"); mapping.setEnableSource(false); mapping = index.getTypes().get("issue"); assertThat(mapping).isNotNull(); assertThat(getAttributeAsMap(mapping, "_source")).containsExactly(entry("enabled", false)); }
activeRuleMapping.setEnableSource(enableSource); activeRuleMapping.setAttribute("_parent", ImmutableMap.of("type", INDEX_TYPE_RULE.getType())); ruleExtensionType.setEnableSource(enableSource); ruleExtensionType.setAttribute("_parent", ImmutableMap.of("type", INDEX_TYPE_RULE.getType())); ruleMapping.setEnableSource(enableSource);
type.setEnableSource(enableSource);
.build(); mapping.createDateTimeField(FIELD_ANALYSED_AT); mapping.setEnableSource(false);
/** * Creates a type that requires to verify that user has the read permission * when searching for documents. * It relies on a parent type named "authorization" that is automatically * populated by {@link org.sonar.server.permission.index.PermissionIndexer}. * * Both types {@code typeName} and "authorization" are created. Documents * must be created with _parent and _routing having the parent uuid as values. * * @see NewIndex.NewIndexType#requireProjectAuthorization() */ public static NewIndex.NewIndexType enableProjectAuthorization(NewIndex.NewIndexType type) { type.setAttribute("_parent", ImmutableMap.of("type", TYPE_AUTHORIZATION)); type.setAttribute("_routing", ImmutableMap.of("required", true)); NewIndex.NewIndexType authType = type.getIndex().createType(TYPE_AUTHORIZATION); authType.setAttribute("_routing", ImmutableMap.of("required", true)); authType.createLongField(FIELD_GROUP_IDS); authType.createLongField(FIELD_USER_IDS); authType.createBooleanField(FIELD_ALLOW_ANYONE); authType.setEnableSource(false); return type; }
activeRuleMapping.setEnableSource(enableSource); activeRuleMapping.setAttribute("_parent", ImmutableMap.of("type", INDEX_TYPE_RULE.getType())); ruleExtensionType.setEnableSource(enableSource); ruleExtensionType.setAttribute("_parent", ImmutableMap.of("type", INDEX_TYPE_RULE.getType())); ruleMapping.setEnableSource(enableSource);
type.setEnableSource(enableSource);
.build(); mapping.createDateTimeField(FIELD_ANALYSED_AT); mapping.setEnableSource(false);