use of com.enonic.xp.site.Site in project xp by enonic.
the class GetCurrentSiteScriptTest method insufficientRights.
@Test
public void insufficientRights() {
final Site site = TestDataFixtures.newSite().permissions(AccessControlList.of(AccessControlEntry.create().principal(RoleKeys.ADMIN).allow(Permission.READ).build())).build();
this.portalRequest.setSite(site);
runFunction("/test/getCurrentSite-test.js", "noCurrentSite");
}
use of com.enonic.xp.site.Site in project xp by enonic.
the class GetCurrentSiteConfigScriptTest method currentSite.
@Test
public void currentSite() {
final Site site = TestDataFixtures.newSite().build();
this.portalRequest.setSite(site);
runFunction("/test/getCurrentSiteConfig-test.js", "currentSite");
}
use of com.enonic.xp.site.Site in project xp by enonic.
the class ContentResolver method resolveInEditMode.
private ContentResolverResult resolveInEditMode(final ContentPath contentPath) {
final ContentId contentId = ContentId.from(contentPath.toString().substring(1));
final Content content = Optional.ofNullable(getContentById(contentId)).orElseGet(() -> getContentByPath(contentPath));
final boolean contentExists = content != null || contentExistsById(contentId) || contentExistsByPath(contentPath);
final Site site = content != null ? callAsContentAdmin(() -> this.contentService.getNearestSite(content.getId())) : null;
return new ContentResolverResult(content, contentExists, site, siteRelativePath(site, content == null ? null : content.getPath()), contentPath.toString());
}
use of com.enonic.xp.site.Site in project xp by enonic.
the class ExceptionRendererImpl method doRenderCustomError.
private PortalResponse doRenderCustomError(final PortalRequest req, final WebException cause, final String handlerMethod) {
final PortalError portalError = PortalError.create().status(cause.getStatus()).message(cause.getMessage()).exception(cause).request(req).build();
final Site siteInRequest = req.getSite();
final Site site = siteInRequest != null ? siteInRequest : callAsContentAdmin(() -> this.contentService.findNearestSiteByPath(req.getContentPath()));
if (site != null) {
req.setSite(site);
try {
for (SiteConfig siteConfig : site.getSiteConfigs()) {
final ApplicationKey applicationKey = siteConfig.getApplicationKey();
for (final String scriptPath : SITE_ERROR_SCRIPT_PATHS) {
final PortalResponse response = renderApplicationCustomError(applicationKey, scriptPath, portalError, handlerMethod);
if (response != null) {
if (response.isPostProcess()) {
req.setApplicationKey(applicationKey);
}
return response;
}
}
}
} finally {
req.setSite(siteInRequest);
}
} else if (req.getApplicationKey() != null) {
final ApplicationKey applicationKey = req.getApplicationKey();
final PortalResponse response = renderApplicationCustomError(applicationKey, GENERIC_ERROR_SCRIPT_PATH, portalError, handlerMethod);
if (response != null) {
if (response.isPostProcess()) {
req.setApplicationKey(applicationKey);
}
return response;
}
}
return null;
}
use of com.enonic.xp.site.Site in project xp by enonic.
the class ContentResolverTest method resolve_non_existing_in_live_mode.
@Test
void resolve_non_existing_in_live_mode() {
final Site site = newSite();
final PortalRequest request = new PortalRequest();
final ContentPath contentPath = ContentPath.from("/mysite/landing-page/non-existing");
request.setContentPath(contentPath);
when(this.contentService.getByPath(contentPath)).thenThrow(new ContentNotFoundException(contentPath, null));
when(this.contentService.contentExists(contentPath)).thenReturn(false);
when(this.contentService.findNearestSiteByPath(contentPath)).thenReturn(site);
final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
assertNull(result.getContent());
assertSame(site, result.getNearestSite());
assertEquals("/landing-page/non-existing", result.getSiteRelativePath());
final WebException e = assertThrows(WebException.class, result::getContentOrElseThrow);
assertEquals(HttpStatus.NOT_FOUND, e.getStatus());
}
Aggregations