use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class XWikiGroupServiceImpl method removeUserOrGroupFromAllGroups.
@Override
public void removeUserOrGroupFromAllGroups(String memberWiki, String memberSpace, String memberName, XWikiContext context) throws XWikiException {
List<Object> parameterValues = new ArrayList<Object>();
StringBuilder where = new StringBuilder(", BaseObject as obj, StringProperty as prop where doc.fullName=obj.name and obj.className=?");
parameterValues.add(CLASS_XWIKIGROUPS);
where.append(" and obj.id=prop.id.id");
where.append(" and prop.name=?");
parameterValues.add(FIELD_XWIKIGROUPS_MEMBER);
where.append(" and prop.value like ?");
if (context.getWikiId() == null || context.getWikiId().equalsIgnoreCase(memberWiki)) {
if (memberSpace == null || memberSpace.equals(DEFAULT_MEMBER_SPACE)) {
parameterValues.add(HQLLIKE_ALL_SYMBOL + memberName + HQLLIKE_ALL_SYMBOL);
} else {
parameterValues.add(HQLLIKE_ALL_SYMBOL + memberSpace + SPACE_NAME_SEP + memberName + HQLLIKE_ALL_SYMBOL);
}
} else {
parameterValues.add(HQLLIKE_ALL_SYMBOL + memberWiki + WIKI_FULLNAME_SEP + memberSpace + SPACE_NAME_SEP + memberName + HQLLIKE_ALL_SYMBOL);
}
List<XWikiDocument> documentList = context.getWiki().getStore().searchDocuments(where.toString(), parameterValues, context);
for (XWikiDocument groupDocument : documentList) {
if (removeUserOrGroupFromGroup(groupDocument, memberWiki, memberSpace, memberName, context)) {
context.getWiki().saveDocument(groupDocument, context);
}
}
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class XWikiRightServiceImpl method isSuperUser.
private boolean isSuperUser(String accessLevel, String name, String resourceKey, boolean user, XWikiDocument xwikidoc, int maxRecursiveSpaceChecks, XWikiContext context) throws XWikiException {
boolean allow;
// Verify XWiki super user
try {
allow = checkRight(name, xwikidoc, "admin", user, true, true, context);
if (allow) {
logAllow(name, resourceKey, accessLevel, "admin level");
return true;
}
} catch (XWikiRightNotFoundException e) {
}
XWikiDocument documentName = new XWikiDocument();
documentName.setFullName(resourceKey);
// Verify Web super user
String space = documentName.getSpace();
ArrayList<String> spacesChecked = new ArrayList<String>();
int recursiveSpaceChecks = 0;
while ((space != null) && (recursiveSpaceChecks <= maxRecursiveSpaceChecks)) {
// Add one to the recursive space checks
recursiveSpaceChecks++;
// add to list of spaces already checked
spacesChecked.add(space);
XWikiDocument webdoc = context.getWiki().getDocument(space, "WebPreferences", context);
if (!webdoc.isNew()) {
try {
allow = checkRight(name, webdoc, "admin", user, true, true, context);
if (allow) {
logAllow(name, resourceKey, accessLevel, "web admin level");
return true;
}
} catch (XWikiRightNotFoundException e) {
}
// find the parent web to check rights on it
space = webdoc.getStringValue("XWiki.XWikiPreferences", "parent");
if ((space == null) || (space.trim().equals("")) || spacesChecked.contains(space)) {
// no parent space or space already checked (recursive loop). let's finish the
// loop
space = null;
}
} else {
space = null;
}
}
return false;
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class EditAction method render.
@Override
public String render(XWikiContext context) throws XWikiException {
try {
XWikiDocument editedDocument = prepareEditedDocument(context);
maybeLockDocument(editedDocument, context);
} catch (XWikiException e) {
if (e.getCode() == XWikiException.ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY) {
context.put("exception", e);
return "docalreadyexists";
} else {
throw e;
}
}
// Make sure object property fields are displayed in edit mode.
// See XWikiDocument#display(String, BaseObject, XWikiContext)
// TODO: Revisit the display mode after the inline action is removed. Is the display mode still needed when
// there is only one edit action?
context.put("display", "edit");
return "edit";
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class EditAction method getEditedDocument.
/**
* There are three important use cases:
* <ul>
* <li>editing or creating the original translation (for the default language)</li>
* <li>editing an existing document translation</li>
* <li>creating a new translation.</i>
* </ul>
* Most of the code deals with the really bad way the default language can be specified (empty string, 'default' or
* a real language code).
*
* @param context the XWiki context
* @return the edited document translation based on the language specified on the request
* @throws XWikiException if something goes wrong
*/
private XWikiDocument getEditedDocument(XWikiContext context) throws XWikiException {
XWikiDocument doc = context.getDoc();
boolean hasTranslation = doc != context.get("tdoc");
// We have to clone the context document because it is cached and the changes we are going to make are valid
// only for the duration of the current request.
doc = doc.clone();
context.put("doc", doc);
EditForm editForm = (EditForm) context.getForm();
doc.readDocMetaFromForm(editForm, context);
String language = context.getWiki().getLanguagePreference(context);
if (doc.isNew() && doc.getDefaultLanguage().equals("")) {
doc.setDefaultLanguage(language);
}
String languageToEdit = StringUtils.isEmpty(editForm.getLanguage()) ? language : editForm.getLanguage();
// If no specific language is set or if it is "default" then we edit the current doc.
if (languageToEdit == null || languageToEdit.equals("default")) {
languageToEdit = "";
}
// translation.
if (doc.isNew() || doc.getDefaultLanguage().equals(languageToEdit)) {
languageToEdit = "";
}
// we edit the default document translation. This prevents use from creating unneeded translations.
if (!hasTranslation && StringUtils.isEmpty(editForm.getLanguage())) {
languageToEdit = "";
}
// Initialize the translated document.
XWikiDocument tdoc;
if (languageToEdit.equals("")) {
// Edit the default document translation (default language).
tdoc = doc;
if (doc.isNew()) {
doc.setDefaultLanguage(language);
doc.setLanguage("");
}
} else if (!hasTranslation && context.getWiki().isMultiLingual(context)) {
// Edit a new translation.
tdoc = new XWikiDocument(doc.getDocumentReference());
tdoc.setLanguage(languageToEdit);
tdoc.setDefaultLocale(doc.getDefaultLocale());
// Mark the translation. It's important to know whether a document is a translation or not, especially
// for the sheet manager which needs to access the objects using the default document not one of its
// translations.
tdoc.setTitle(doc.getTitle());
tdoc.setContent(doc.getContent());
tdoc.setSyntax(doc.getSyntax());
tdoc.setAuthorReference(context.getUserReference());
tdoc.setStore(doc.getStore());
} else {
// Edit an existing translation. Clone the translated document object to be sure that the changes we are
// going to make will last only for the duration of the current request.
tdoc = ((XWikiDocument) context.get("tdoc")).clone();
}
return tdoc;
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class EditAction method prepareEditedDocument.
/**
* Determines the edited document (translation) and updates it based on the template specified on the request and
* any additional request parameters that overwrite the default values from the template.
*
* @param context the XWiki context
* @return the edited document
* @throws XWikiException if something goes wrong
*/
protected XWikiDocument prepareEditedDocument(XWikiContext context) throws XWikiException {
// Determine the edited document (translation).
XWikiDocument editedDocument = getEditedDocument(context);
EditForm editForm = (EditForm) context.getForm();
// Update the edited document based on the template specified on the request.
editedDocument.readFromTemplate(editForm, context);
// The default values from the template can be overwritten by additional request parameters.
updateDocumentTitleAndContentFromRequest(editedDocument, context);
editedDocument.readObjectsFromForm(editForm, context);
// using XWikiGuest instead (because those fields were not previously initialized).
if (editedDocument.isNew()) {
editedDocument.setCreatorReference(context.getUserReference());
editedDocument.setAuthorReference(context.getUserReference());
editedDocument.setContentAuthorReference(context.getUserReference());
}
// Expose the edited document on the XWiki context and the Velocity context.
putDocumentOnContext(editedDocument, context);
return editedDocument;
}
Aggregations