Search in sources :

Example 56 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class ContentResolverTest method resolve_self_in_edit_mode.

@Test
void resolve_self_in_edit_mode() {
    final Site site = newSite();
    final PortalRequest request = new PortalRequest();
    request.setMode(RenderMode.EDIT);
    request.setContentPath(ContentPath.from("/c8da0c10-0002-4b68-b407-87412f3e45c9"));
    when(this.contentService.getById(ContentId.from("c8da0c10-0002-4b68-b407-87412f3e45c9"))).thenReturn(site);
    when(this.contentService.getNearestSite(ContentId.from("c8da0c10-0002-4b68-b407-87412f3e45c9"))).thenReturn(site);
    final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
    assertSame(site, result.getContent());
    assertSame(site, result.getNearestSite());
    assertEquals("/", result.getSiteRelativePath());
}
Also used : Site(com.enonic.xp.site.Site) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 57 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class ContentResolverTest method resolve_in_live_mode.

@Test
void resolve_in_live_mode() {
    final Content content = newContent();
    final Site site = newSite();
    final PortalRequest request = new PortalRequest();
    request.setContentPath(ContentPath.from("/mysite/landing-page"));
    when(this.contentService.getByPath(ContentPath.from("/mysite/landing-page"))).thenReturn(content);
    when(this.contentService.findNearestSiteByPath(ContentPath.from("/mysite/landing-page"))).thenReturn(site);
    final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
    assertSame(content, result.getContent());
    assertSame(site, result.getNearestSite());
    assertEquals("/landing-page", result.getSiteRelativePath());
}
Also used : Site(com.enonic.xp.site.Site) Content(com.enonic.xp.content.Content) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 58 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class HtmlLinkProcessor method getStyleDescriptors.

private StyleDescriptors getStyleDescriptors(final PortalRequest portalRequest) {
    final ImmutableList.Builder<ApplicationKey> applicationKeyList = new ImmutableList.Builder<ApplicationKey>().add(SYSTEM_APPLICATION_KEY);
    if (portalRequest != null) {
        final Site site = portalRequest.getSite();
        if (site != null) {
            final ImmutableSet<ApplicationKey> siteApplicationKeySet = site.getSiteConfigs().getApplicationKeys();
            applicationKeyList.addAll(siteApplicationKeySet);
        }
    }
    final ApplicationKeys applicationKeys = ApplicationKeys.from(applicationKeyList.build());
    return styleDescriptorService.getByApplications(applicationKeys);
}
Also used : Site(com.enonic.xp.site.Site) ApplicationKey(com.enonic.xp.app.ApplicationKey) ApplicationKeys(com.enonic.xp.app.ApplicationKeys) ImmutableList(com.google.common.collect.ImmutableList)

Example 59 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class UpdateNodeParamsFactory method toNodeEditor.

private NodeEditor toNodeEditor(final UpdateContentTranslatorParams params) {
    final Content content = params.getEditedContent();
    final PropertyTree nodeData = contentDataSerializer.toUpdateNodeData(params);
    final ContentIndexConfigFactory indexConfigFactory = ContentIndexConfigFactory.create().contentTypeService(contentTypeService).pageDescriptorService(pageDescriptorService).partDescriptorService(partDescriptorService).layoutDescriptorService(layoutDescriptorService).siteService(this.siteService).xDataService(this.xDataService).contentTypeName(content.getType()).page(content.getPage()).siteConfigs(content.isSite() ? ((Site) content).getSiteConfigs() : null).extraDatas(content.getAllExtraData()).language(content.getLanguage() != null ? content.getLanguage().getLanguage() : null).build();
    return editableNode -> {
        editableNode.indexConfigDocument = indexConfigFactory.produce();
        editableNode.data = nodeData;
        editableNode.manualOrderValue = content.getManualOrderValue();
        editableNode.permissions = content.getPermissions();
        editableNode.inheritPermissions = content.inheritsPermissions();
    };
}
Also used : PartDescriptorService(com.enonic.xp.region.PartDescriptorService) SiteService(com.enonic.xp.site.SiteService) Content(com.enonic.xp.content.Content) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) ContentTypeService(com.enonic.xp.schema.content.ContentTypeService) NodeId(com.enonic.xp.node.NodeId) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) Site(com.enonic.xp.site.Site) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) ContentDataSerializer(com.enonic.xp.core.impl.content.serializer.ContentDataSerializer) Preconditions(com.google.common.base.Preconditions) ContentIndexConfigFactory(com.enonic.xp.core.impl.content.index.ContentIndexConfigFactory) UpdateContentTranslatorParams(com.enonic.xp.content.UpdateContentTranslatorParams) NodeEditor(com.enonic.xp.node.NodeEditor) XDataService(com.enonic.xp.schema.xdata.XDataService) PropertyTree(com.enonic.xp.data.PropertyTree) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentIndexConfigFactory(com.enonic.xp.core.impl.content.index.ContentIndexConfigFactory)

Example 60 with Site

use of com.enonic.xp.site.Site 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;
}
Also used : Site(com.enonic.xp.site.Site) Context(com.enonic.xp.context.Context) ProjectName(com.enonic.xp.project.ProjectName) SiteConfigs(com.enonic.xp.site.SiteConfigs) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo)

Aggregations

Site (com.enonic.xp.site.Site)78 Test (org.junit.jupiter.api.Test)51 Content (com.enonic.xp.content.Content)41 PortalRequest (com.enonic.xp.portal.PortalRequest)17 PropertyTree (com.enonic.xp.data.PropertyTree)14 Page (com.enonic.xp.page.Page)12 ContentId (com.enonic.xp.content.ContentId)10 ContentPath (com.enonic.xp.content.ContentPath)10 SiteConfig (com.enonic.xp.site.SiteConfig)10 WebException (com.enonic.xp.web.WebException)10 ApplicationKey (com.enonic.xp.app.ApplicationKey)9 PageTemplate (com.enonic.xp.page.PageTemplate)8 PortalResponse (com.enonic.xp.portal.PortalResponse)7 ControllerMappingDescriptor (com.enonic.xp.site.mapping.ControllerMappingDescriptor)7 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 DescriptorKey (com.enonic.xp.page.DescriptorKey)5 SiteConfigs (com.enonic.xp.site.SiteConfigs)5 Branch (com.enonic.xp.branch.Branch)4 ContentService (com.enonic.xp.content.ContentService)4