use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class DefaultContextualAuthorizationManagerTest method checkAccess.
// Tests
@Test
public void checkAccess() throws Exception {
LocalDocumentReference localReference = new LocalDocumentReference("space", "page");
this.mocker.getComponentUnderTest().checkAccess(Right.VIEW, localReference);
verify(this.authorizationManager).checkAccess(same(Right.VIEW), isNull(DocumentReference.class), eq(new DocumentReference(localReference, this.currentWikiReference)));
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class UIExtensionTest method setUp.
@Before
public void setUp() throws Exception {
// Delete pages that we create in the test
getUtil().rest().delete(new LocalDocumentReference(getTestClassName(), HELLOWORLD_UIX_PAGE));
getUtil().rest().delete(new LocalDocumentReference(getTestClassName(), HELLOWIKIWORLD_UIX_PAGE));
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class CopyPageTest method testCopyOverwritePage.
@Test
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146")
public void testCopyOverwritePage() throws Exception {
String sourceSpaceName = getTestClassName();
String sourcePageName = getTestMethodName();
String targetSpaceName = getTestClassName() + "Copy";
String targetPageName = getTestMethodName() + "Copy";
// Delete page that may already exist
getUtil().rest().deletePage(sourceSpaceName, sourcePageName);
getUtil().rest().deletePage(targetSpaceName, targetPageName);
// Create a new page that will be overwritten.
getUtil().rest().savePage(new LocalDocumentReference(targetSpaceName, targetPageName), OVERWRITTEN_PAGE_CONTENT, targetPageName);
// Create a new page that will be copied.
ViewPage viewPage = getUtil().createPage(sourceSpaceName, sourcePageName, PAGE_CONTENT, sourcePageName);
// Click on Copy from the Page top menu.
viewPage.copy();
CopyPage copyPage = new CopyPage();
// Fill the target destination the page to be copied to.
DocumentPicker documentPicker = copyPage.getDocumentPicker();
documentPicker.setTitle(targetPageName);
documentPicker.browseDocuments();
DocumentPickerModal documentPickerModal = new DocumentPickerModal();
documentPickerModal.waitForDocumentSelected(sourceSpaceName, "WebHome").selectDocument(targetSpaceName, "WebHome");
documentPicker.waitForLocation(Arrays.asList("", targetSpaceName, targetPageName));
Assert.assertEquals(targetSpaceName, copyPage.getTargetSpaceName());
// Click copy button
CopyOverwritePromptPage copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
// Check overwrite warning
Assert.assertEquals(OVERWRITE_PROMPT1 + targetSpaceName + '.' + targetPageName + OVERWRITE_PROMPT2, copyOverwritePrompt.getWarningMessage());
// Cancel the copy
viewPage = copyOverwritePrompt.clickCancelButton();
// Verify that we have been sent back to the original page
Assert.assertEquals(sourcePageName, viewPage.getDocumentTitle());
// Click on Copy from the Page top menu.
viewPage.copy();
copyPage = new CopyPage();
// Fill the target destination the page to be copied to.
copyPage.getDocumentPicker().toggleLocationAdvancedEdit().setParent(targetSpaceName).setName(targetPageName);
// Click copy button
copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
// Click change target
copyOverwritePrompt.clickChangeTargetButton();
copyPage = new CopyPage();
// Check the source document
Assert.assertEquals(Arrays.asList("", sourceSpaceName, sourcePageName), copyPage.getSourceLocation().getPath());
Assert.assertEquals(sourceSpaceName, copyPage.getSourceSpaceName());
Assert.assertEquals(sourcePageName, copyPage.getSourcePageName());
// Check the default target document.
documentPicker = copyPage.getDocumentPicker();
Assert.assertEquals(sourcePageName, documentPicker.getTitle());
Assert.assertEquals(Arrays.asList("", sourceSpaceName, sourcePageName), documentPicker.getLocation().getPath());
Assert.assertEquals(sourceSpaceName, copyPage.getTargetSpaceName());
Assert.assertEquals(sourcePageName, copyPage.getTargetPageName());
// Fill the target destination the page to be copied to.
documentPicker.setTitle("My copy").toggleLocationAdvancedEdit().setParent(targetSpaceName).setName(targetPageName);
// Copy and confirm overwrite
copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
CopyOrRenameStatusPage copyStatusPage = copyOverwritePrompt.clickCopyButton().waitUntilFinished();
// Check successful copy confirmation
Assert.assertEquals(COPY_SUCCESSFUL, copyStatusPage.getInfoMessage());
viewPage = copyStatusPage.gotoNewPage();
// Verify that the title of the copy has been updated (independent from the name of the copy).
Assert.assertEquals("My copy", viewPage.getDocumentTitle());
Assert.assertEquals(PAGE_CONTENT, viewPage.getContent());
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class XarPackage method readDescriptorFiles.
private void readDescriptorFiles(Element files) {
NodeList children = files.getChildNodes();
for (int i = 0; i < children.getLength(); ++i) {
Node node = children.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
if (element.getTagName().equals(XarModel.ELEMENT_FILES_FILE)) {
String localeString = element.getAttribute(XarModel.ATTRIBUTE_LOCALE);
String defaultActionString = element.getAttribute(XarModel.ATTRIBUTE_DEFAULTACTION);
String referenceString = element.getTextContent();
// Parse reference
LocalDocumentReference reference = new LocalDocumentReference(XarUtils.RESOLVER.resolve(referenceString, EntityType.DOCUMENT), LocaleUtils.toLocale(localeString));
// Parse default action
int defaultAction = Integer.valueOf(defaultActionString);
// Get entry name associated to the document
String entryName = getEntryName(reference);
// Create entry
XarEntry packageFile = new XarEntry(reference, entryName, defaultAction);
// Register package file entry
this.packageFiles.put(packageFile, packageFile);
// Update existing entry default action
updateEntryDefaultAction(packageFile);
}
}
}
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class AdministrationTest method testCodeToExecutionAndAutoSandboxing.
/*
* If CodeToExecute is defined in a configurable app, then it should be evaluated.
* Also header should be evaluated and not just printed.
* If XWiki.ConfigurableClass is saved with programming rights, it should resave itself so that it doesn't have them.
*/
@Test
public void testCodeToExecutionAndAutoSandboxing() throws Exception {
String space = "Main";
String page = "TestConfigurable";
String codeToExecute = "#set($code = 's sh')" + "Thi${code}ould be displayed." + "#if($xcontext.hasProgrammingRights())" + "This should not be displayed." + "#end";
String heading = "#set($code = 'his sho')" + "T${code}uld also be displayed.";
createConfigurableApplication(space, page, "TestSection6", true);
open(space, page, "edit", "editor=object");
expandObject("XWiki.ConfigurableClass", 0);
setFieldValue("XWiki.ConfigurableClass_0_codeToExecute", codeToExecute);
setFieldValue("XWiki.ConfigurableClass_0_heading", heading);
setFieldValue("XWiki.ConfigurableClass_0_configurationClass", "");
clickEditSaveAndView();
Page restPage = getUtil().rest().get(new LocalDocumentReference("XWiki", "ConfigurableClass"));
String standardContent = restPage.getContent();
try {
// Modify content
restPage.setContent(standardContent + "\n\n{{velocity}}Has Programming permission: $xcontext.hasProgrammingRights(){{/velocity}}");
// Our admin will foolishly save XWiki.ConfigurableClass, giving it programming rights.
getUtil().setDefaultCredentials(TestUtils.ADMIN_CREDENTIALS);
getUtil().rest().save(restPage);
// Now we look at the section for our configurable.
open("XWiki", "ConfigurableClass", "view", "editor=globaladmin§ion=TestSection6");
assertTextPresent("This should be displayed.");
assertTextPresent("This should also be displayed.");
assertTextNotPresent("This should not be displayed.");
assertTextPresent("Has Programming permission: false");
// Make sure javascript has not added a Save button.
assertElementNotPresent("//div/div/p/span/input[@type='submit'][@value='Save']");
} finally {
// Restore initial content
restPage.setContent(standardContent);
// Save
getUtil().rest().save(restPage);
}
}
Aggregations