use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class WikiCreationJobScriptServices method createWiki.
/**
* Asynchronously create a wiki.
*
* @param request creation wiki request containing all information about the wiki to create
* @return the creationjob that creates the wiki
*/
public Job createWiki(WikiCreationRequest request) {
try {
// Verify that the user has the CREATE_WIKI right
XWikiContext xcontext = xcontextProvider.get();
WikiReference mainWikiReference = new WikiReference(wikiDescriptorManager.getMainWikiId());
authorizationManager.checkAccess(Right.CREATE_WIKI, xcontext.getUserReference(), mainWikiReference);
// Verify that if an extension id is provided, this extension is authorized.
if (request.getExtensionId() != null) {
if (!isAuthorizedExtension(request.getExtensionId())) {
throw new WikiCreationException(String.format("The extension [%s] is not authorized.", request.getExtensionId()));
}
}
return wikiCreator.createWiki(request);
} catch (WikiCreationException e) {
setLastError(e);
logger.warn("Failed to create a new wiki.", e);
} catch (AccessDeniedException e) {
setLastError(e);
}
return null;
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class WikiCreationJobScriptServicesTest method createWikiWhenNoCreateWikiRight.
@Test
public void createWikiWhenNoCreateWikiRight() throws Exception {
DocumentReference currentUser = new DocumentReference("xwiki", "XWiki", "User");
when(xcontext.getUserReference()).thenReturn(currentUser);
AccessDeniedException exception = new AccessDeniedException(Right.CREATE_WIKI, currentUser, new WikiReference("mainWikiId"));
doThrow(exception).when(authorizationManager).checkAccess(eq(Right.CREATE_WIKI), eq(currentUser), eq(new WikiReference("mainWikiId")));
WikiCreationRequest wikiCreationRequest = new WikiCreationRequest();
wikiCreationRequest.setExtensionId("authorized-extension", "1.0");
assertNull(mocker.getComponentUnderTest().createWiki(wikiCreationRequest));
Exception lastError = mocker.getComponentUnderTest().getLastError();
assertNotNull(lastError);
assertEquals(exception, lastError);
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class WatchListMessageDataExtractorTest method relativeTemplateDefaultTemplateMainWiki.
@Test
public void relativeTemplateDefaultTemplateMainWiki() throws Exception {
// Setup the user profile data to extract.
setUpUserObject();
// Setup the template
String templateStringReference = "Some.Template";
parameters.put(WatchListEventMimeMessageFactory.TEMPLATE_PARAMETER, templateStringReference);
DocumentReference userWikiTemplateReference = new DocumentReference(testSubscriberReference.getWikiReference().getName(), "Some", "Template");
when(mockExplicitDocumentReferenceResolver.resolve(templateStringReference, testSubscriberReference.getWikiReference())).thenReturn(userWikiTemplateReference);
when(mockWiki.exists(userWikiTemplateReference, mockContext)).thenReturn(false);
String currentWikiId = "someWiki";
when(mockContext.getWikiId()).thenReturn(currentWikiId);
WikiReference currentWikiReference = new WikiReference(currentWikiId);
DocumentReference currentWikiTemplateReference = new DocumentReference(currentWikiId, "Some", "Template");
when(mockExplicitDocumentReferenceResolver.resolve(templateStringReference, currentWikiReference)).thenReturn(currentWikiTemplateReference);
when(mockWiki.exists(currentWikiTemplateReference, mockContext)).thenReturn(false);
DocumentReference defaultCurrentWikiTemplateReference = new DocumentReference(currentWikiId, "XWiki", "WatchListMessage");
when(mockExplicitDocumentReferenceResolver.resolve(WatchListJob.DEFAULT_EMAIL_TEMPLATE, currentWikiReference)).thenReturn(defaultCurrentWikiTemplateReference);
when(mockWiki.exists(defaultCurrentWikiTemplateReference, mockContext)).thenReturn(false);
String mainWikiId = "xwiki";
when(mockContext.getMainXWiki()).thenReturn(mainWikiId);
WikiReference mainWikiReference = new WikiReference(mainWikiId);
DocumentReference defaultMainWikiTemplateReference = new DocumentReference(mainWikiId, "XWiki", "WatchListMessage");
when(mockExplicitDocumentReferenceResolver.resolve(WatchListJob.DEFAULT_EMAIL_TEMPLATE, mainWikiReference)).thenReturn(defaultMainWikiTemplateReference);
testTemplateReference = defaultMainWikiTemplateReference;
// Run the extraction.
WatchListMessageData result = extractor.extract(testSubscriberReference, mockDocument, mockUserObject);
// Check the extracted data.
assertResult(result);
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class WatchListMessageDataExtractorTest method relativeTemplateContextWiki.
@Test
public void relativeTemplateContextWiki() throws Exception {
// Setup the user profile data to extract.
setUpUserObject();
// Setup the template
String templateStringReference = "Some.Template";
parameters.put(WatchListEventMimeMessageFactory.TEMPLATE_PARAMETER, templateStringReference);
DocumentReference userWikiTemplateReference = new DocumentReference("wiki", "Some", "Template");
when(mockExplicitDocumentReferenceResolver.resolve(templateStringReference, testSubscriberReference.getWikiReference())).thenReturn(userWikiTemplateReference);
when(mockWiki.exists(userWikiTemplateReference, mockContext)).thenReturn(false);
String currentWikiId = "xwiki";
when(mockContext.getWikiId()).thenReturn(currentWikiId);
WikiReference currentWikiReference = new WikiReference(currentWikiId);
DocumentReference currentWikiTemplateReference = new DocumentReference(currentWikiId, "Some", "Template");
when(mockExplicitDocumentReferenceResolver.resolve(templateStringReference, currentWikiReference)).thenReturn(currentWikiTemplateReference);
when(mockWiki.exists(currentWikiTemplateReference, mockContext)).thenReturn(true);
testTemplateReference = currentWikiTemplateReference;
// Run the extraction.
WatchListMessageData result = extractor.extract(testSubscriberReference, mockDocument, mockUserObject);
// Check the extracted data.
assertResult(result);
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class TemporaryChartImageWriterTest method getStorageLocation.
@Test
public void getStorageLocation() throws Exception {
WikiReference currentWikiReference = new WikiReference("wiki");
ModelContext modelContext = this.componentManager.getInstance(ModelContext.class);
when(modelContext.getCurrentEntityReference()).thenReturn(currentWikiReference);
Environment environment = this.componentManager.getInstance(Environment.class);
when(environment.getTemporaryDirectory()).thenReturn(new File("/tmpdir"));
File location = this.componentManager.getComponentUnderTest().getStorageLocation(new ImageId(new ChartMacroParameters()));
Assert.assertTrue("Got: " + location.toString(), location.toString().matches("/tmpdir/temp/chart/wiki/space/page/.*\\.png"));
}
Aggregations