Skip to content
Snippets Groups Projects
Unverified Commit b4347d50 authored by Clément Aubin's avatar Clément Aubin
Browse files

XWIKI-14907: Cannot switch Advanced user mode for other user than Admin

* Update CurrentUserPropertyResourceImpl to set a new value to a
StaticList even if no value is currently defined
* Register the shortcuts only for a logged-in user
parent b9fdae5e
No related branches found
No related tags found
No related merge requests found
......@@ -75,6 +75,7 @@
## ADD KEYBOARD SHORTCUTS
###########################################
<script type="text/javascript">
#if($!xcontext.user != 'XWiki.XWikiGuest')
//<![CDATA[
/**
* Perform a PUT on the given REST API. If the request is successful, reload the page.
......@@ -87,23 +88,28 @@
*/
var developerShortcutsRestCall = function(restUrl, errorMessage) {
const req = new XMLHttpRequest();
var notification = new XWiki.widgets.Notification(
"$escapetool.javascript($services.localization.render('core.shortcuts.developer.user.ajax.inprogress'))",
'inprogress');
req.onreadystatechange = function(event) {
if (this.readyState === XMLHttpRequest.DONE) {
if (this.status >= 200 && this.status < 300) {
// Reload the page to apply the user modifications
new XWiki.widgets.Notification("$escapetool.javascript($services.localization.render('core.shortcuts.developer.user.ajax.success'))", 'success');
notification.replace(new XWiki.widgets.Notification(
"$escapetool.javascript($services.localization.render(
'core.shortcuts.developer.user.ajax.success'))", 'done'));
location.reload()
} else if (this.status == 500) {
notification.replace(new XWiki.widgets.Notification(this.data, 'error'));
} else {
new XWiki.widgets.Notification(errorMessage, 'error');
notification.replace(new XWiki.widgets.Notification(errorMessage, 'error'));
}
}
};
req.open('PUT', restUrl, true);
req.send(null);
new XWiki.widgets.Notification("$escapetool.javascript($services.localization.render('core.shortcuts.developer.user.ajax.inprogress'))", 'inprogress');
};
// Append developer shortcuts for toggeling userType and hiddenDocuments in the current user profile
......@@ -117,4 +123,5 @@
"$escapetool.javascript($services.localization.render('core.shortcuts.developer.user.displayHiddenDocs.error'))");
}, {'type': shortcut.type.SEQUENCE, 'disable_in_input': true });
//]]>
#end
</script>
\ No newline at end of file
......@@ -28,7 +28,7 @@
import org.xwiki.stability.Unstable;
/**
* Update a boolean or static kilst property of the current user to its next value (for a Boolean this means set it
* Update a boolean or static list property of the current user to its next value (for a Boolean this means set it
* to true if it was false and vice versa).
*
* @version $Id$
......
......@@ -81,7 +81,7 @@ public Response setNextPropertyValue(String propertyName) throws XWikiRestExcept
// For Guest users, raise an error
if (xcontext.getUserReference() == null) {
throw new XWikiRestException(
String.format("Cannot change property [%s] since the current is guest", propertyName));
String.format("Cannot change property [%s] since the current user is guest", propertyName));
}
XWikiDocument userDocument = xcontext.getWiki().getDocument(xcontext.getUserReference(), xcontext);
......@@ -137,12 +137,21 @@ private java.lang.Object computeNewStaticListValue(StaticListClass listClass, Ba
if (!listClass.isMultiSelect()) {
List<String> items = listClass.getList(xcontext);
int pos = items.indexOf(object.getStringValue(propertyName));
if (pos != -1) {
if (pos == items.size() - 1) {
newValue = items.get(0);
} else {
newValue = items.get(pos + 1);
}
} else {
// If no item is already selected in the static list, we assume that the default item used is the
// first in the list.
if (items.size() <= 2) {
newValue = items.get(items.size() - 1);
} else {
newValue = items.get(1);
}
}
}
return newValue;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment