use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method setUserScopeError.
@Test
public void setUserScopeError() throws Exception {
// Mocks
WikiUserManagerException expectedException = new WikiUserManagerException("error in setUserScope");
doThrow(expectedException).when(wikiUserManager).setUserScope(any(), any(UserScope.class));
// Test
boolean result = mocker.getComponentUnderTest().setUserScope("subwiki", "LOCAL_ONLY");
// Asserts
assertFalse(result);
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class DefaultWikiUserConfigurationHelper method saveConfiguration.
@Override
public void saveConfiguration(WikiUserConfiguration configuration, String wikiId) throws WikiUserManagerException {
XWikiContext context = xcontextProvider.get();
// Get the document
XWikiDocument document = getDocument(wikiId);
// Fill the object
BaseObject object = document.getXObject(WikiUserClassDocumentInitializer.CONFIGURATION_CLASS, true, context);
object.setStringValue(WikiUserClassDocumentInitializer.FIELD_USERSCOPE, configuration.getUserScope().name().toLowerCase());
if (configuration.getMembershipType() != null) {
object.setStringValue(WikiUserClassDocumentInitializer.FIELD_MEMBERSHIPTYPE, configuration.getMembershipType().name().toLowerCase());
}
// Save the document
try {
XWiki xwiki = context.getWiki();
document.setHidden(true);
// The document must have a creator
if (document.getCreatorReference() == null) {
document.setCreatorReference(context.getUserReference());
}
// The document must have an author
if (document.getAuthorReference() == null) {
document.setAuthorReference(context.getUserReference());
}
xwiki.saveDocument(document, "Changed configuration.", context);
} catch (XWikiException e) {
throw new WikiUserManagerException(String.format("Fail to save the confguration document for wiki [%s].", wikiId), e);
}
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class DefaultWikiUserConfigurationHelper method getConfiguration.
@Override
public WikiUserConfiguration getConfiguration(String wikiId) throws WikiUserManagerException {
// Create the configuration object to return
WikiUserConfiguration configuration = new WikiUserConfiguration();
// Get the document
XWikiDocument document = getDocument(wikiId);
// Get the XWiki object
BaseObject object = document.getXObject(WikiUserClassDocumentInitializer.CONFIGURATION_CLASS);
if (object != null) {
// Get the user scope
String scopeValue = object.getStringValue(WikiUserClassDocumentInitializer.FIELD_USERSCOPE);
UserScope userScope;
try {
userScope = UserScope.valueOf(scopeValue.toUpperCase());
} catch (Exception e) {
// Default value
userScope = UserScope.LOCAL_AND_GLOBAL;
}
configuration.setUserScope(userScope);
// Get the membershipType value
String membershipTypeValue = object.getStringValue(WikiUserClassDocumentInitializer.FIELD_MEMBERSHIPTYPE);
MembershipType membershipType;
try {
membershipType = MembershipType.valueOf(membershipTypeValue.toUpperCase());
} catch (Exception e) {
// Default value
membershipType = MembershipType.INVITE;
}
configuration.setMembershipType(membershipType);
}
return configuration;
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class DefaultWikiUserConfigurationHelper method getDocument.
private XWikiDocument getDocument(String wikiId) throws WikiUserManagerException {
try {
XWikiContext context = xcontextProvider.get();
XWiki xwiki = context.getWiki();
DocumentReference reference = new DocumentReference(wikiId, CONFIGURATION_SPACE_NAME, CONFIGURATION_PAGE_NAME);
return xwiki.getDocument(reference, context);
} catch (XWikiException e) {
throw new WikiUserManagerException(String.format("Fail to get the configuration document for wiki [%s].", wikiId));
}
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class AddUsersStepTest method executeWhenException.
@Test
public void executeWhenException() throws Exception {
WikiCreationRequest request = new WikiCreationRequest();
request.setWikiId("wikiId");
List<String> members = new ArrayList<>();
request.setMembers(members);
Exception exception = new WikiUserManagerException("Execption in WikiUserManager.");
doThrow(exception).when(wikiUserManager).addMembers(anyCollection(), any());
// Test
WikiCreationException caughtException = null;
try {
mocker.getComponentUnderTest().execute(request);
} catch (WikiCreationException e) {
caughtException = e;
}
// Verify
assertNotNull(caughtException);
assertEquals("Failed to add members to the wiki [wikiId].", caughtException.getMessage());
assertEquals(exception, caughtException.getCause());
}
Aggregations