use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method getMembersGroupDocument.
private XWikiDocument getMembersGroupDocument(String wikiId) throws WikiUserManagerException {
// Reference to the document
DocumentReference memberGroupReference = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "XWikiAllGroup");
// Get the document
try {
XWikiContext xcontext = xcontextProvider.get();
XWiki xwiki = xcontext.getWiki();
return xwiki.getDocument(memberGroupReference, xcontext);
} catch (XWikiException e) {
throw new WikiUserManagerException(String.format("Fail to load the member group document [%s].", memberGroupReference.toString()), e);
}
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method addMemberObject.
private void addMemberObject(XWikiDocument groupDoc, String userId) throws WikiUserManagerException {
try {
XWikiContext xcontext = xcontextProvider.get();
int objectNumber = groupDoc.createXObject(GROUPCLASS_REFERENCE, xcontext);
BaseObject object = groupDoc.getXObject(GROUPCLASS_REFERENCE, objectNumber);
object.set(GROUP_CLASS_MEMBER_FIELD, userId, xcontext);
} catch (XWikiException e) {
throw new WikiUserManagerException("Fail to add a member to the group", e);
}
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method getMembers.
@Override
public Collection<String> getMembers(String wikiId) throws WikiUserManagerException {
List<String> members = new ArrayList<>();
try {
// Get the descriptor
WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
// Add the wiki owner
members.add(descriptor.getOwnerId());
} catch (WikiManagerException e) {
throw new WikiUserManagerException(String.format("Failed to get the descriptor for [%s]", wikiId), e);
}
// Get the other members from the wiki AllGroup
XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
List<BaseObject> memberObjects = groupDoc.getXObjects(GROUPCLASS_REFERENCE);
if (memberObjects != null) {
for (BaseObject object : memberObjects) {
if (object == null) {
continue;
}
String member = object.getStringValue(GROUP_CLASS_MEMBER_FIELD);
if (!member.isEmpty() && !members.contains(member)) {
members.add(member);
}
}
}
return members;
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method invite.
@Override
public MemberCandidacy invite(String userId, String wikiId, String message) throws WikiUserManagerException {
XWikiContext xcontext = xcontextProvider.get();
// Create the candidacy
MemberCandidacy candidacy = new MemberCandidacy(wikiId, userId, MemberCandidacy.CandidateType.INVITATION);
candidacy.setUserComment(message);
candidacy.setAdminId(documentReferenceSerializer.serialize(xcontext.getUserReference()));
// Get the group document
XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
// Add a candidacy object
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.setStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN, candidacy.getAdminId());
object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT, message);
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 invitation object.", e);
}
// Save the document
saveGroupDocument(groupDoc, String.format("[%s] is invited to join the wiki.", userId));
return candidacy;
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class WikiUserManagerScriptService method leave.
/**
* Leave a wiki.
*
* @param userId userId to remove from the wiki
* @param wikiId id of the wiki
* @return true if it succeed
*/
public boolean leave(String userId, String wikiId) {
// Check if the current user is userId
XWikiContext context = xcontextProvider.get();
DocumentReference candidacyUser = documentReferenceResolver.resolve(userId);
if (!context.getUserReference().equals(candidacyUser)) {
setLastError(new WikiUserManagerException(String.format("User [%s] cannot call $services.wiki.user.leave()" + " with an other userId.", context.getUserReference())));
return false;
}
// Leave the wiki
try {
wikiUserManager.leave(userId, wikiId);
} catch (WikiUserManagerException e) {
setLastError(e);
return false;
}
return true;
}
Aggregations