use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiCreator method createDescriptor.
private WikiDescriptor createDescriptor(String wikiId, String wikiAlias) throws WikiManagerException {
// Create the descriptor
WikiDescriptor descriptor = new DefaultWikiDescriptor(wikiId, wikiAlias);
try {
// Build the document
wikiDescriptorBuilder.save(descriptor);
// Reload the descriptor from the cache because it should have been seen by the DescriptorListener.
descriptor = wikiDescriptorManager.getById(wikiId);
} catch (WikiDescriptorBuilderException e) {
throw new WikiManagerException("Failed to build the descriptor document.", e);
}
return descriptor;
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiTemplateManager method isTemplate.
@Override
public boolean isTemplate(String wikiId) throws WikiTemplateManagerException {
try {
// Get the descriptor
WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
// Get the property group
WikiTemplatePropertyGroup group = (WikiTemplatePropertyGroup) descriptor.getPropertyGroup(WikiTemplatePropertyGroupProvider.GROUP_NAME);
// Return the value
return group.isTemplate();
} catch (WikiManagerException e) {
throw new WikiTemplateManagerException(String.format(errorMessageNoDescriptor, wikiId), e);
}
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class WikiTemplateManagerScript method setTemplate.
/**
* Set if the specified wiki is a template or not.
*
* @param wikiId the ID of the wiki to specify
* @param value whether or not the wiki is a template
* @return true if the action succeed
*/
public boolean setTemplate(String wikiId, boolean value) {
XWikiContext context = xcontextProvider.get();
try {
// Check if the current script has the programing rights
authorizationManager.checkAccess(Right.PROGRAM, context.getDoc().getAuthorReference(), context.getDoc().getDocumentReference());
// Get the descriptor
WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
// Get the wiki owner
String owner = descriptor.getOwnerId();
// Check right access
WikiReference wikiReference = new WikiReference(descriptor.getId());
String currentUser = entityReferenceSerializer.serialize(context.getUserReference());
if (!currentUser.equals(owner)) {
authorizationManager.checkAccess(Right.ADMIN, context.getUserReference(), wikiReference);
}
// Do the job
wikiTemplateManager.setTemplate(wikiId, value);
// Return success
return true;
} catch (WikiTemplateManagerException e) {
error(String.format("Failed to set the template value [%s] for the wiki [%s].", value, wikiId), e);
return false;
} catch (AccessDeniedException e) {
error(String.format("Access denied for [%s] to change the template value of the wiki [%s]. The user has" + " not the right to perform this operation or the script has not the programming right.", context.getUserReference(), wikiId), e);
return false;
} catch (WikiManagerException e) {
error(String.format("Failed to get the descriptor of the wiki [%s].", wikiId), e);
return false;
}
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class WikiTemplateManagerScriptTest method getTemplatesError.
@Test
public void getTemplatesError() throws Exception {
Exception exception = new WikiTemplateManagerException("Error in getTemplates");
when(wikiTemplateManager.getTemplates()).thenThrow(exception);
Collection<WikiDescriptor> results = mocker.getComponentUnderTest().getTemplates();
assertTrue(results.isEmpty());
assertEquals(exception, mocker.getComponentUnderTest().getLastError());
verify(mocker.getMockedLogger()).error("Error while getting all the wiki templates.", exception);
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class WikiTemplateManagerScriptTest method setTemplateWithoutAdminRight.
@Test
public void setTemplateWithoutAdminRight() throws Exception {
Exception exception = currentUserHasNotAdminRight();
WikiDescriptor wikiDescriptor = new WikiDescriptor("wikiId", "wikiAlias");
when(wikiDescriptorManager.getById("wikiId")).thenReturn(wikiDescriptor);
boolean result = mocker.getComponentUnderTest().setTemplate("wikiId", true);
assertFalse(result);
assertEquals(exception, mocker.getComponentUnderTest().getLastError());
verify(mocker.getMockedLogger()).error("Access denied for [mainWiki:XWiki.User] to change the template value" + " of the wiki [wikiId]. The user has not the right to perform this operation or the script has not " + "the programming right.", exception);
}
Aggregations