use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class WikiUserFromXEMMigrationTest method setUp.
@Before
public void setUp() throws Exception {
wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
wikiUserConfigurationHelper = mocker.getInstance(WikiUserConfigurationHelper.class);
execution = mock(Execution.class);
mocker.registerComponent(Execution.class, execution);
xcontext = mock(XWikiContext.class);
xwiki = mock(XWiki.class);
ExecutionContext executionContext = mock(ExecutionContext.class);
when(execution.getContext()).thenReturn(executionContext);
when(executionContext.getProperty("xwikicontext")).thenReturn(xcontext);
when(xcontext.getWiki()).thenReturn(xwiki);
when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWiki");
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class WikiUserManagerScriptService method canSeeCandidacy.
private boolean canSeeCandidacy(MemberCandidacy candidacy) {
XWikiContext context = xcontextProvider.get();
// Test if the user is concerned by the candidacy...
DocumentReference candidacyUser = documentReferenceResolver.resolve(candidacy.getUserId());
if (context.getUserReference().equals(candidacyUser)) {
// Hide the admin private comment
candidacy.setAdminPrivateComment(null);
return true;
}
// Otherwise the user must be an admin.
return authorizationManager.hasAccess(Right.ADMIN, context.getUserReference(), new WikiReference(candidacy.getWikiId()));
}
use of com.xpn.xwiki.XWikiContext 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;
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class WikiUserManagerScriptService method join.
/**
* Join a wiki.
*
* @param userId userId to add to the wiki
* @param wikiId id of the wiki
* @return true if it succeed
*/
public boolean join(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.join() with an other userId.", context.getUserReference())));
return false;
}
try {
wikiUserManager.join(userId, wikiId);
} catch (WikiUserManagerException e) {
setLastError(e);
return false;
}
return true;
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class DefaultDocumentRestorerFromAttachedXAR method restoreDocumentFromAttachedXAR.
@Override
public void restoreDocumentFromAttachedXAR(DocumentReference docReference, String attachmentName, List<DocumentReference> documentsToRestore) throws XWikiException {
XWikiContext xcontext = xcontextProvider.get();
XWiki xwiki = xcontext.getWiki();
File tempZipFile = null;
try {
tempZipFile = getTemporaryZipFile(docReference, attachmentName);
if (tempZipFile == null) {
return;
}
ZipFile zipFile = new ZipFile(tempZipFile);
// We look for each document to restore if there is a corresponding zipEntry.
Iterator<DocumentReference> itDocumentsToRestore = documentsToRestore.iterator();
while (itDocumentsToRestore.hasNext()) {
DocumentReference docRef = itDocumentsToRestore.next();
// Compute what should be the filename of the document to restore
String fileNameToRestore = String.format("%s/%s.xml", docRef.getLastSpaceReference().getName(), docRef.getName());
// Get the corresponding zip Entry
ZipArchiveEntry zipEntry = zipFile.getEntry(fileNameToRestore);
if (zipEntry != null) {
// Restore the document
XWikiDocument docToRestore = xwiki.getDocument(docRef, xcontext);
docToRestore.fromXML(zipFile.getInputStream(zipEntry));
xwiki.saveDocument(docToRestore, xcontext);
// We have restored this document
itDocumentsToRestore.remove();
}
}
zipFile.close();
} catch (IOException e) {
logger.error("Error during the decompression of [{}].", attachmentName, e);
} finally {
// Delete the temporary zip file
if (tempZipFile != null) {
tempZipFile.delete();
}
}
}
Aggregations