-
-
Notifications
You must be signed in to change notification settings - Fork 562
XWIKI-22656: Add a UI for setting required rights on a document #4158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
caa90c8
68ff5b8
74b8343
f148b7d
1d2b73e
266aefd
6a6ca11
f74ef58
34f6cfa
f9ac64d
b1a1c85
93442d0
13a2175
6859771
6898691
b3adcbd
305a764
0a84852
dbf4dea
4d41f39
b5f13dc
b0aed69
a8e8d75
b7bd889
bde9ff6
3abe08a
391b450
1ffc809
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
(function () { | ||
'use strict'; | ||
const $ = jQuery; | ||
|
||
// Reload the content of the CKEditor instances when the document rights are changed to reflect the new rights | ||
// in the executed macros. | ||
$(document).on('xwiki:document:requiredRightsUpdated.ckeditor', function (event, data) { | ||
$.each(CKEDITOR.instances, function(key, editor) { | ||
if (matchesRequiredRightsChangeEvent(editor, event, data)) { | ||
maybeReload(editor); | ||
} | ||
}); | ||
}); | ||
|
||
const matchesRequiredRightsChangeEvent = function (editor, event, data) { | ||
// Check if the syntax change event targets the edited document (the source document). | ||
return editor.config.sourceDocument.documentReference.equals(data.documentReference) && | ||
// Check if the syntax plugin is enabled for this editor instance. | ||
editor.plugins['xwiki-rights']; | ||
}; | ||
|
||
const maybeReload = function (editor) { | ||
// Only reload in WYSIWYG mode. In source mode, rights aren't influencing anything. | ||
// TODO: it would be nice if we could mark something in source mode to ensure that on the next switch to | ||
// wysiwyg mode, the content would be reloaded regardless if it has been modified or not. | ||
if (editor.mode === 'wysiwyg') { | ||
editor.execCommand('xwiki-refresh'); | ||
} | ||
}; | ||
|
||
// An empty plugin that can be used to enable / disable the reloading on required rights changes on a particular | ||
// CKEditor instance. | ||
CKEDITOR.plugins.add('xwiki-rights', { | ||
requires: 'xwiki-macro,xwiki-source' | ||
}); | ||
})(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
import org.xwiki.model.internal.document.SafeDocumentAuthors; | ||
import org.xwiki.model.reference.DocumentReference; | ||
import org.xwiki.model.reference.DocumentReferenceResolver; | ||
import org.xwiki.model.reference.EntityReference; | ||
import org.xwiki.model.reference.EntityReferenceSerializer; | ||
import org.xwiki.model.reference.ObjectReference; | ||
import org.xwiki.model.reference.PageReference; | ||
|
@@ -1169,6 +1170,24 @@ public Object newObject(String classname) throws XWikiException | |
return getObject(classname, nb); | ||
} | ||
|
||
/** | ||
* Creates a new XObject from the given class reference. | ||
* | ||
* @param classReference the reference to the class of the XObject to be created | ||
* @return the object created | ||
* @throws XWikiException if an error occurs while creating the XObject | ||
* @since 17.4.0RC1 | ||
*/ | ||
@Unstable | ||
public Object newObject(EntityReference classReference) throws XWikiException | ||
{ | ||
int index = getDoc().createXObject(classReference, getXWikiContext()); | ||
|
||
updateAuthor(); | ||
|
||
return getObject(classReference, index); | ||
} | ||
|
||
/** | ||
* @return true of the document has been loaded from cache | ||
*/ | ||
|
@@ -1229,6 +1248,21 @@ public Vector<Object> getObjects(String className) | |
return getXObjects(objects); | ||
} | ||
|
||
/** | ||
* Retrieves and returns all objects corresponding to the class reference corresponding to the resolution of the | ||
* given entity reference, or an empty list if there are none. | ||
* | ||
* @param classReference the reference that is resolved to an XClass for retrieving the corresponding xobjects | ||
* @return a list of xobjects corresponding to the given XClass or an empty list. | ||
* @since 17.4.0RC1 | ||
*/ | ||
@Unstable | ||
public List<Object> getObjects(EntityReference classReference) | ||
{ | ||
List<BaseObject> objects = this.getDoc().getXObjects(classReference); | ||
return getXObjects(objects); | ||
} | ||
|
||
/** | ||
* Get the first object that contains the given fieldname | ||
* | ||
|
@@ -1387,6 +1421,29 @@ public Object getObject(String classname, int nb) | |
} | ||
} | ||
|
||
/** | ||
* Gets the object matching the given class reference and given object number. | ||
* | ||
* @param classReference the reference of the class of the object | ||
* @param nb the number of the object | ||
* @return the XWiki Object | ||
* @since 17.4.0RC1 | ||
*/ | ||
@Unstable | ||
public Object getObject(EntityReference classReference, int nb) | ||
{ | ||
try { | ||
BaseObject obj = this.getDoc().getXObject(classReference, nb); | ||
if (obj == null) { | ||
return null; | ||
} else { | ||
return newObjectApi(obj, getXWikiContext()); | ||
} | ||
} catch (Exception e) { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no log or anything? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copied this behavior from the other methods that take a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well if no called method declare it I'm not sure how it could be a breaking change? I think I would clean up the code to remove the catch, and maybe add a log error to the original method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could catch non-declared exceptions, that would afaik stop the Velocity script when not catched anymore. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it would be much cleaner to remove the catch. Unfortunately, it indeed might not look that much like a new method from Velocity code point of view, so better keep the same behavior. An alternative would be to name all those new methods getXObject(s), which is closer to XWikiDocument naming. But it's also probably less obvious, and I like the idea that your version will improve performances a bit of any Velocity code which happen to call those methods with EntityReference already. |
||
} | ||
} | ||
|
||
/** | ||
* @param objectReference the object reference | ||
* @return the XWiki object from this document that matches the specified object reference | ||
|
@@ -1882,7 +1939,7 @@ public Attachment getAttachment(String filename) | |
|
||
/** | ||
* @param filename the name of the attachment | ||
* @return the attachment with the given filename or null if the attachment does not exist | ||
* @return the attachment with the given filename or null if the attachment doesn’t exist | ||
* @since 17.2.0RC1 | ||
*/ | ||
public Attachment removeAttachment(String filename) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.xwiki.platform.security.requiredrights.internal; | ||
|
||
import org.xwiki.security.authorization.requiredrights.DocumentRequiredRight; | ||
|
||
/** | ||
* A suggestion for an operation that removes or adds rights to a document. | ||
* | ||
* @param increasesRights if more rights are granted due to this change | ||
* @param rightToRemove the right to replace | ||
* @param rightToAdd the right to add | ||
* @param requiresManualReview if the analysis is certain that the right is needed/not needed or the user needs to | ||
* @param hasPermission if the current user has the permission to perform the proposed change manually review the | ||
* analysis result to determine if the right is actually needed/not needed | ||
* | ||
* @version $Id$ | ||
* @since 17.4.0RC1 | ||
*/ | ||
public record RequiredRightChangeSuggestion(boolean increasesRights, DocumentRequiredRight rightToRemove, | ||
michitux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
DocumentRequiredRight rightToAdd, boolean requiresManualReview, | ||
boolean hasPermission) | ||
{ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would specify in the javadoc that the list might contain null...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually cannot contain
null
elements as they are filtered out bygetXObjects(objects)
. It's the same as for the method taking aString
. If we want to change this, I think we should give the new method a new name in order to avoid that is accidentally called (some scripts might already pass an entity reference that is currently implicitly converted to string).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no it's good then, I missed the filter and I was being extra cautious...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess in the future we should deprecate the API you replaced that are taking a String instead of a reference. But maybe not now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, as usually with this kind of API, there is a lot of work before we can but the
@Dreprecated
annotation (if we don't want to explode the log). Now what we do sometimes is put at least the javadoc@deprecated
(which does not have any log impact).