use of com.enonic.xp.site.SiteConfigs in project xp by enonic.
the class CreateNodeParamsFactory method produce.
public CreateNodeParams produce() {
final PropertyTree contentAsData = contentDataSerializer.toCreateNodeData(params);
final PropertySet extraDataSet = contentAsData.getPropertySet(PropertyPath.from(ContentPropertyNames.EXTRA_DATA));
final String language = contentAsData.getString(PropertyPath.from(ContentPropertyNames.LANGUAGE));
final SiteConfigs siteConfigs = new SiteConfigsDataSerializer().fromProperties(contentAsData.getPropertySet(PropertyPath.from(ContentPropertyNames.DATA))).build();
final Page page = contentAsData.hasProperty(COMPONENTS) ? contentDataSerializer.fromPageData(contentAsData.getRoot()) : null;
final ExtraDatas extraData = extraDataSet != null ? contentDataSerializer.fromExtraData(extraDataSet) : null;
final ContentIndexConfigFactory.Builder indexConfigFactoryBuilder = ContentIndexConfigFactory.create().contentTypeName(params.getType()).siteConfigs(siteConfigs).siteService(siteService).xDataService(xDataService).contentTypeService(contentTypeService);
if (page != null) {
indexConfigFactoryBuilder.page(page).pageDescriptorService(pageDescriptorService).partDescriptorService(partDescriptorService).layoutDescriptorService(layoutDescriptorService);
}
if (extraData != null) {
indexConfigFactoryBuilder.extraDatas(extraData);
}
if (!nullToEmpty(language).isBlank()) {
indexConfigFactoryBuilder.language(language);
}
final IndexConfigDocument indexConfigDocument = indexConfigFactoryBuilder.build().produce();
final CreateNodeParams.Builder builder = CreateNodeParams.create().name(resolveNodeName(params.getName())).parent(ContentNodeHelper.translateContentParentToNodeParentPath(params.getParent())).data(contentAsData).indexConfigDocument(indexConfigDocument).permissions(params.getPermissions()).inheritPermissions(params.isInheritPermissions()).childOrder(params.getChildOrder()).nodeType(ContentConstants.CONTENT_NODE_COLLECTION);
for (final CreateAttachment attachment : params.getCreateAttachments()) {
builder.attachBinary(attachment.getBinaryReference(), attachment.getByteSource());
}
return builder.build();
}
use of com.enonic.xp.site.SiteConfigs in project xp by enonic.
the class SiteConfigProcessorTest method test_site_config_with_html_area.
@Test
public void test_site_config_with_html_area() throws Exception {
final Form form = Form.create().addFormItem(Input.create().name("text1").label("text1").inputType(InputTypeName.HTML_AREA).build()).build();
final SiteConfigs siteConfigs = SiteConfigs.create().add(SiteConfig.create().application(applicationKey1).config(new PropertyTree()).build()).build();
final PatternIndexConfigDocument result = processConfigs(siteConfigs, form);
assertEquals(1, result.getPathIndexConfigs().size());
assertEquals("htmlStripper", result.getConfigForPath(PropertyPath.from(ContentPropertyNames.DATA, SITECONFIG, "config", "text1")).getIndexValueProcessors().get(0).getName());
}
use of com.enonic.xp.site.SiteConfigs in project xp by enonic.
the class SiteConfigProcessorTest method test_multiple_site_configs_with_same_path.
@Test
public void test_multiple_site_configs_with_same_path() throws Exception {
final Form form1 = Form.create().addFormItem(Input.create().name("text1").label("text1").inputType(InputTypeName.HTML_AREA).build()).build();
final Form form2 = Form.create().addFormItem(Input.create().name("text1").label("text1").inputType(InputTypeName.HTML_AREA).build()).build();
final SiteConfigs siteConfigs = SiteConfigs.create().add(SiteConfig.create().application(applicationKey1).config(new PropertyTree()).build()).add(SiteConfig.create().application(applicationKey2).config(new PropertyTree()).build()).build();
final PatternIndexConfigDocument result = processConfigs(siteConfigs, form1, form2);
assertEquals(1, result.getPathIndexConfigs().size());
assertEquals("htmlStripper", result.getConfigForPath(PropertyPath.from(ContentPropertyNames.DATA, SITECONFIG, "config", "text1")).getIndexValueProcessors().get(0).getName());
}
use of com.enonic.xp.site.SiteConfigs in project xp by enonic.
the class SiteConfigProcessorTest method test_multiple_site_configs_with_html_areas.
@Test
public void test_multiple_site_configs_with_html_areas() throws Exception {
final Form form1 = Form.create().addFormItem(Input.create().name("text1").label("text1").inputType(InputTypeName.HTML_AREA).build()).build();
final Form form2 = Form.create().addFormItem(Input.create().name("text2").label("text2").inputType(InputTypeName.HTML_AREA).build()).build();
final SiteConfigs siteConfigs = SiteConfigs.create().add(SiteConfig.create().application(applicationKey1).config(new PropertyTree()).build()).add(SiteConfig.create().application(applicationKey2).config(new PropertyTree()).build()).build();
final PatternIndexConfigDocument result = processConfigs(siteConfigs, form1, form2);
assertEquals(2, result.getPathIndexConfigs().size());
assertEquals("htmlStripper", result.getConfigForPath(PropertyPath.from(ContentPropertyNames.DATA, SITECONFIG, "config", "text1")).getIndexValueProcessors().get(0).getName());
assertEquals("htmlStripper", result.getConfigForPath(PropertyPath.from(ContentPropertyNames.DATA, SITECONFIG, "config", "text2")).getIndexValueProcessors().get(0).getName());
}
use of com.enonic.xp.site.SiteConfigs in project xp by enonic.
the class ProjectAccessSiteProcessor method processUpdate.
@Override
public ProcessUpdateResult processUpdate(final ProcessUpdateParams params) {
final Site editedSite = (Site) params.getEditedContent();
final SiteConfigs editedSiteConfigs = editedSite.getSiteConfigs();
final Site originalSite = (Site) params.getOriginalContent();
final SiteConfigs originalSiteConfigs = originalSite.getSiteConfigs();
final Context context = ContextAccessor.current();
final AuthenticationInfo authenticationInfo = context.getAuthInfo();
final ProjectName projectName = ProjectName.from(context.getRepositoryId());
if (!Objects.equals(originalSiteConfigs, editedSiteConfigs)) {
if (!ProjectAccessHelper.hasAdminAccess(authenticationInfo)) {
if (ProjectConstants.DEFAULT_PROJECT_NAME.equals(projectName)) {
throw new ProjectAccessRequiredException(authenticationInfo.getUser().getKey());
} else if (!this.projectPermissionsContextManager.hasAnyProjectRole(authenticationInfo, projectName, Set.of(ProjectRole.OWNER))) {
throw new ProjectAccessRequiredException(authenticationInfo.getUser().getKey(), ProjectRole.OWNER);
}
}
}
return null;
}
Aggregations