use of org.xwiki.wiki.user.WikiUserConfiguration in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method setUserScope.
@Override
public void setUserScope(String wikiId, UserScope scope) throws WikiUserManagerException {
WikiUserConfiguration configuration = wikiUserConfigurationHelper.getConfiguration(wikiId);
configuration.setUserScope(scope);
wikiUserConfigurationHelper.saveConfiguration(configuration, wikiId);
}
use of org.xwiki.wiki.user.WikiUserConfiguration in project xwiki-platform by xwiki.
the class WikiUserFromXEMMigration method upgradeWorkspaceConfiguration.
/**
* Convert the old WorkspaceManager.WorkspaceClass objects to the new configuration format.
*
* @param oldObject old workspace object
* @param wikiId id of the wiki to upgrade
* @param oldWikiDescriptor document that holds the old object
* @throws DataMigrationException if problems occur
* @throws XWikiException if problems occur
*/
private void upgradeWorkspaceConfiguration(BaseObject oldObject, String wikiId, XWikiDocument oldWikiDescriptor) throws DataMigrationException, XWikiException {
// Context, XWiki
XWikiContext context = getXWikiContext();
XWiki xwiki = context.getWiki();
// Create the new configuration
WikiUserConfiguration configuration = new WikiUserConfiguration();
// No local users
configuration.setUserScope(UserScope.GLOBAL_ONLY);
// Set the membershipType value
if (oldObject != null) {
// Get the membershipType value
String membershipTypeValue = oldObject.getStringValue("membershipType");
MembershipType membershipType;
try {
membershipType = MembershipType.valueOf(membershipTypeValue.toUpperCase());
} catch (Exception e) {
// Default value
membershipType = MembershipType.INVITE;
}
configuration.setMembershipType(membershipType);
} else {
// If there is no workspace object, we put a default value.
configuration.setMembershipType(MembershipType.INVITE);
}
// Save the new configuration
saveConfiguration(configuration, wikiId);
}
use of org.xwiki.wiki.user.WikiUserConfiguration in project xwiki-platform by xwiki.
the class WikiUserFromXEMMigrationTest method upgradeRegularSubWiki.
@Test
public void upgradeRegularSubWiki() throws Exception {
// Mocks
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("subwiki");
XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class);
when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerSubwiki")), any(XWikiContext.class))).thenReturn(oldDescriptorDocument);
when(oldDescriptorDocument.getXObject(eq(new DocumentReference("mainWiki", "WorkspaceManager", "WorkspaceClass")))).thenReturn(null);
// Run
mocker.getComponentUnderTest().hibernateMigrate();
// Verify
WikiUserConfiguration expectedConfiguration = new WikiUserConfiguration();
expectedConfiguration.setUserScope(UserScope.LOCAL_AND_GLOBAL);
expectedConfiguration.setMembershipType(MembershipType.INVITE);
verify(wikiUserConfigurationHelper).saveConfiguration(eq(expectedConfiguration), eq("subwiki"));
}
use of org.xwiki.wiki.user.WikiUserConfiguration in project xwiki-platform by xwiki.
the class WikiUserFromXEMMigrationTest method upgradeOldWorkspaceTemplate.
@Test
public void upgradeOldWorkspaceTemplate() throws Exception {
// Mocks about the descriptor
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("workspacetemplate");
XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class);
when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerWorkspacetemplate")), any(XWikiContext.class))).thenReturn(oldDescriptorDocument);
// Mock about the workspace special page
when(xwiki.exists(eq(new DocumentReference("workspacetemplate", "XWiki", "ManageWorkspace")), any(XWikiContext.class))).thenReturn(true);
// Mocks about candidacies
DocumentReference memberGroupRef = new DocumentReference("workspacetemplate", XWiki.SYSTEM_SPACE, "XWikiAllGroup");
XWikiDocument memberGroupDoc = mock(XWikiDocument.class);
when(xwiki.getDocument(eq(memberGroupRef), any(XWikiContext.class))).thenReturn(memberGroupDoc);
// Run
mocker.getComponentUnderTest().hibernateMigrate();
// Verify the user configuration is accurate
WikiUserConfiguration expectedConfiguration = new WikiUserConfiguration();
expectedConfiguration.setUserScope(UserScope.GLOBAL_ONLY);
expectedConfiguration.setMembershipType(MembershipType.INVITE);
verify(wikiUserConfigurationHelper).saveConfiguration(eq(expectedConfiguration), eq("workspacetemplate"));
}
use of org.xwiki.wiki.user.WikiUserConfiguration 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;
}
Aggregations