Search in sources :

Example 21 with WikiUserManagerException

use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.

the class SaveWikiMetaDataStep method execute.

@Override
public void execute(WikiCreationRequest request) throws WikiCreationException {
    try {
        String wikiId = request.getWikiId();
        // Meta data about the wiki
        WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
        descriptor.setDescription(request.getDescription());
        descriptor.setPrettyName(request.getPrettyName());
        descriptor.setOwnerId(request.getOwnerId());
        wikiDescriptorManager.saveDescriptor(descriptor);
        // Meta data about the templates
        wikiTemplateManager.setTemplate(wikiId, request.isTemplate());
        // Meta data about the users
        wikiUserManager.setUserScope(wikiId, request.getUserScope());
        wikiUserManager.setMembershipType(wikiId, request.getMembershipType());
    } catch (WikiManagerException | WikiTemplateManagerException | WikiUserManagerException e) {
        throw new WikiCreationException(String.format("Failed to set metadata to the wiki [%s].", request.getWikiId()), e);
    }
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException)

Example 22 with WikiUserManagerException

use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.

the class DefaultWikiUserManager method saveGroupDocument.

private void saveGroupDocument(XWikiDocument document, String message) throws WikiUserManagerException {
    // Get the XWiki objects
    XWikiContext xcontext = xcontextProvider.get();
    XWiki xwiki = xcontext.getWiki();
    // The document should be hidden
    document.setHidden(true);
    // The document must have a creator
    if (document.getCreatorReference() == null) {
        document.setCreatorReference(xcontext.getUserReference());
    }
    // The document must have an author
    if (document.getAuthorReference() == null) {
        document.setAuthorReference(xcontext.getUserReference());
    }
    // Save the document
    try {
        xwiki.saveDocument(document, message, xcontext);
    } catch (XWikiException e) {
        throw new WikiUserManagerException("Fail to save the member group", e);
    }
}
Also used : WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) XWikiException(com.xpn.xwiki.XWikiException)

Example 23 with WikiUserManagerException

use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.

the class DefaultWikiUserManager method askToJoin.

@Override
public MemberCandidacy askToJoin(String userId, String wikiId, String message) throws WikiUserManagerException {
    MemberCandidacy candidacy = new MemberCandidacy(wikiId, userId, MemberCandidacy.CandidateType.REQUEST);
    candidacy.setUserComment(message);
    // Get the group document
    XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
    // Add a candidacy object
    XWikiContext xcontext = xcontextProvider.get();
    try {
        int objectNumber = groupDoc.createXObject(WikiCandidateMemberClassInitializer.REFERENCE, xcontext);
        candidacy.setId(objectNumber);
        BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, objectNumber);
        object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_USER, candidacy.getUserId());
        object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT, candidacy.getUserComment());
        object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, candidacy.getStatus().name().toLowerCase());
        object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CREATION, candidacy.getDateOfCreation());
        object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_TYPE, candidacy.getType().name().toLowerCase());
    } catch (XWikiException e) {
        throw new WikiUserManagerException("Failed to create a new join request.", e);
    }
    // Save the document
    saveGroupDocument(groupDoc, String.format("[%s] asks to join the wiki.", userId));
    return candidacy;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 24 with WikiUserManagerException

use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.

the class WikiUserManagerScriptService method getCandidacy.

/**
 * Get the specified candidacy.
 *
 * @param wikiId Id of the wiki concerned by the candidacy
 * @param candidacyId id of the candidacy
 * @return the candidacy or null if problems occur
 */
public MemberCandidacy getCandidacy(String wikiId, int candidacyId) {
    // Get the candidacy
    MemberCandidacy candidacy = null;
    try {
        candidacy = wikiUserManager.getCandidacy(wikiId, candidacyId);
        // Check the rights
        if (!canSeeCandidacy(candidacy)) {
            setLastError(new WikiUserManagerScriptServiceException("You are not allowed to see this candidacy."));
            candidacy = null;
        }
    } catch (WikiUserManagerException e) {
        setLastError(e);
    }
    return candidacy;
}
Also used : MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException)

Example 25 with WikiUserManagerException

use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.

the class WikiUserManagerScriptServiceTest method getMembershipTypeWithError.

@Test
public void getMembershipTypeWithError() throws Exception {
    // Mocks
    Exception expectedException = new WikiUserManagerException("Error in getMembershipType");
    when(wikiUserManager.getMembershipType("test")).thenThrow(expectedException);
    // Test
    MembershipType result = mocker.getComponentUnderTest().getMembershipType("test");
    // Asserts
    assertNull(result);
    assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
}
Also used : WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) MembershipType(org.xwiki.wiki.user.MembershipType) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) Test(org.junit.Test)

Aggregations

WikiUserManagerException (org.xwiki.wiki.user.WikiUserManagerException)27 Test (org.junit.Test)14 XWikiContext (com.xpn.xwiki.XWikiContext)9 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)9 XWikiException (com.xpn.xwiki.XWikiException)8 BaseObject (com.xpn.xwiki.objects.BaseObject)6 DocumentReference (org.xwiki.model.reference.DocumentReference)6 MemberCandidacy (org.xwiki.wiki.user.MemberCandidacy)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 XWiki (com.xpn.xwiki.XWiki)4 MembershipType (org.xwiki.wiki.user.MembershipType)3 UserScope (org.xwiki.wiki.user.UserScope)3 ArrayList (java.util.ArrayList)2 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)2 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)2 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)2 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)1 WikiCreationRequest (org.xwiki.platform.wiki.creationjob.WikiCreationRequest)1 WikiTemplateManagerException (org.xwiki.wiki.template.WikiTemplateManagerException)1 WikiUserConfiguration (org.xwiki.wiki.user.WikiUserConfiguration)1