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
XWIKI-17533: Allow to set custom rights in administration #1644
Changes from 2 commits
ddc9d9f
bb3dcc4
54ce02c
515c452
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,301 @@ | ||
<?xml version="1.1" encoding="UTF-8"?> | ||
|
||
<!-- | ||
* 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. | ||
--> | ||
|
||
<xwikidoc version="1.4" reference="XWiki.AdminCustomRightsSheet" locale=""> | ||
<web>XWiki</web> | ||
<name>AdminCustomRightsSheet</name> | ||
<language/> | ||
<defaultLanguage/> | ||
<translation>0</translation> | ||
<creator>xwiki:XWiki.Admin</creator> | ||
<parent>Main.WebHome</parent> | ||
<author>xwiki:XWiki.Admin</author> | ||
<contentAuthor>xwiki:XWiki.Admin</contentAuthor> | ||
<version>1.1</version> | ||
<title>AdminCustomRightsSheet</title> | ||
<comment/> | ||
<minorEdit>false</minorEdit> | ||
<syntaxId>xwiki/2.1</syntaxId> | ||
<hidden>true</hidden> | ||
<content>{{velocity}} | ||
### Sheet used to generically display the XWikiPreferences object fields in the administration sheets. | ||
{{html}} | ||
<form method="post" action="$xwiki.getURL($currentDoc, 'saveandcontinue')" class="xform"> | ||
############################################################################################ | ||
## RIGHTS | ||
############################################################################################ | ||
<fieldset> | ||
#template('rightsUI.vm') | ||
</fieldset> | ||
</form> | ||
{{/html}} | ||
{{/velocity}}</content> | ||
<object> | ||
<name>XWiki.AdminCustomRightsSheet</name> | ||
<number>0</number> | ||
<className>XWiki.ConfigurableClass</className> | ||
<guid>bad3af00-4a01-48b8-94ca-2111b758d219</guid> | ||
<class> | ||
<name>XWiki.ConfigurableClass</name> | ||
<customClass/> | ||
<customMapping/> | ||
<defaultViewSheet/> | ||
<defaultEditSheet/> | ||
<defaultWeb/> | ||
<nameField/> | ||
<validationScript/> | ||
<categoryIcon> | ||
<customDisplay/> | ||
<disabled>0</disabled> | ||
<hint/> | ||
<name>categoryIcon</name> | ||
<number>11</number> | ||
<picker>0</picker> | ||
<prettyName>categoryIcon</prettyName> | ||
<size>30</size> | ||
<unmodifiable>0</unmodifiable> | ||
<validationMessage/> | ||
<validationRegExp/> | ||
<classType>com.xpn.xwiki.objects.classes.StringClass</classType> | ||
</categoryIcon> | ||
<codeToExecute> | ||
<contenttype>VelocityWiki</contenttype> | ||
<customDisplay/> | ||
<disabled>0</disabled> | ||
<editor>---</editor> | ||
<hint/> | ||
<name>codeToExecute</name> | ||
<number>7</number> | ||
<picker>0</picker> | ||
<prettyName>codeToExecute</prettyName> | ||
<rows>5</rows> | ||
<size>40</size> | ||
<unmodifiable>0</unmodifiable> | ||
<validationMessage/> | ||
<validationRegExp/> | ||
<classType>com.xpn.xwiki.objects.classes.TextAreaClass</classType> | ||
</codeToExecute> | ||
<configurationClass> | ||
<cache>0</cache> | ||
<classname/> | ||
<customDisplay/> | ||
<defaultValue/> | ||
<disabled>0</disabled> | ||
<displayType>input</displayType> | ||
<freeText/> | ||
<hint/> | ||
<idField/> | ||
<largeStorage>0</largeStorage> | ||
<multiSelect>0</multiSelect> | ||
<name>configurationClass</name> | ||
<number>3</number> | ||
<picker>1</picker> | ||
<prettyName>configurationClass</prettyName> | ||
<relationalStorage>0</relationalStorage> | ||
<separator> </separator> | ||
<separators/> | ||
<size>30</size> | ||
<sort>none</sort> | ||
<sql/> | ||
<unmodifiable>0</unmodifiable> | ||
<validationMessage/> | ||
<validationRegExp/> | ||
<valueField/> | ||
<classType>com.xpn.xwiki.objects.classes.PageClass</classType> | ||
</configurationClass> | ||
<configureGlobally> | ||
<customDisplay/> | ||
<defaultValue/> | ||
<disabled>0</disabled> | ||
<displayFormType>checkbox</displayFormType> | ||
<displayType/> | ||
<hint/> | ||
<name>configureGlobally</name> | ||
<number>4</number> | ||
<prettyName>configureGlobally</prettyName> | ||
<unmodifiable>0</unmodifiable> | ||
<validationMessage/> | ||
<validationRegExp/> | ||
<classType>com.xpn.xwiki.objects.classes.BooleanClass</classType> | ||
</configureGlobally> | ||
<displayBeforeCategory> | ||
<customDisplay/> | ||
<disabled>0</disabled> | ||
<hint/> | ||
<name>displayBeforeCategory</name> | ||
<number>10</number> | ||
<picker>0</picker> | ||
<prettyName>displayBeforeCategory</prettyName> | ||
<size>30</size> | ||
<unmodifiable>0</unmodifiable> | ||
<validationMessage/> | ||
<validationRegExp/> | ||
<classType>com.xpn.xwiki.objects.classes.StringClass</classType> | ||
</displayBeforeCategory> | ||
<displayInCategory> | ||
<customDisplay/> | ||
<disabled>0</disabled> | ||
<hint/> | ||
<name>displayInCategory</name> | ||
<number>9</number> | ||
<picker>0</picker> | ||
<prettyName>displayInCategory</prettyName> | ||
<size>30</size> | ||
<unmodifiable>0</unmodifiable> | ||
<validationMessage/> | ||
<validationRegExp/> | ||
<classType>com.xpn.xwiki.objects.classes.StringClass</classType> | ||
</displayInCategory> | ||
<displayInSection> | ||
<customDisplay/> | ||
<disabled>0</disabled> | ||
<hint/> | ||
<name>displayInSection</name> | ||
<number>1</number> | ||
<picker>0</picker> | ||
<prettyName>displayInSection</prettyName> | ||
<size>30</size> | ||
<unmodifiable>0</unmodifiable> | ||
<validationMessage/> | ||
<validationRegExp/> | ||
<classType>com.xpn.xwiki.objects.classes.StringClass</classType> | ||
</displayInSection> | ||
<heading> | ||
<customDisplay/> | ||
<disabled>0</disabled> | ||
<hint/> | ||
<name>heading</name> | ||
<number>2</number> | ||
<picker>0</picker> | ||
<prettyName>heading</prettyName> | ||
<size>30</size> | ||
<unmodifiable>0</unmodifiable> | ||
<validationMessage/> | ||
<validationRegExp/> | ||
<classType>com.xpn.xwiki.objects.classes.StringClass</classType> | ||
</heading> | ||
<iconAttachment> | ||
<customDisplay/> | ||
<disabled>0</disabled> | ||
<hint/> | ||
<name>iconAttachment</name> | ||
<number>8</number> | ||
<picker>0</picker> | ||
<prettyName>iconAttachment</prettyName> | ||
<size>30</size> | ||
<unmodifiable>0</unmodifiable> | ||
<validationMessage/> | ||
<validationRegExp/> | ||
<classType>com.xpn.xwiki.objects.classes.StringClass</classType> | ||
</iconAttachment> | ||
<linkPrefix> | ||
<customDisplay/> | ||
<disabled>0</disabled> | ||
<hint/> | ||
<name>linkPrefix</name> | ||
<number>5</number> | ||
<picker>0</picker> | ||
<prettyName>linkPrefix</prettyName> | ||
<size>30</size> | ||
<unmodifiable>0</unmodifiable> | ||
<validationMessage/> | ||
<validationRegExp/> | ||
<classType>com.xpn.xwiki.objects.classes.StringClass</classType> | ||
</linkPrefix> | ||
<propertiesToShow> | ||
<cache>0</cache> | ||
<customDisplay/> | ||
<defaultValue/> | ||
<disabled>0</disabled> | ||
<displayType>input</displayType> | ||
<freeText/> | ||
<hint/> | ||
<largeStorage>0</largeStorage> | ||
<multiSelect>1</multiSelect> | ||
<name>propertiesToShow</name> | ||
<number>6</number> | ||
<picker>0</picker> | ||
<prettyName>propertiesToShow</prettyName> | ||
<relationalStorage>1</relationalStorage> | ||
<separator> </separator> | ||
<separators> ,|</separators> | ||
<size>20</size> | ||
<sort>none</sort> | ||
<unmodifiable>0</unmodifiable> | ||
<validationMessage/> | ||
<validationRegExp/> | ||
<values/> | ||
<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType> | ||
</propertiesToShow> | ||
<sectionOrder> | ||
<customDisplay/> | ||
<disabled>0</disabled> | ||
<hint/> | ||
<name>sectionOrder</name> | ||
<number>12</number> | ||
<numberType>integer</numberType> | ||
<prettyName>sectionOrder</prettyName> | ||
<size>30</size> | ||
<unmodifiable>0</unmodifiable> | ||
<validationMessage/> | ||
<validationRegExp/> | ||
<classType>com.xpn.xwiki.objects.classes.NumberClass</classType> | ||
</sectionOrder> | ||
</class> | ||
<property> | ||
<categoryIcon/> | ||
</property> | ||
<property> | ||
<codeToExecute>{{include reference="XWiki.AdminCustomRightsSheet" /}}</codeToExecute> | ||
</property> | ||
<property> | ||
<configurationClass/> | ||
</property> | ||
<property> | ||
<configureGlobally>1</configureGlobally> | ||
</property> | ||
<property> | ||
<displayBeforeCategory/> | ||
</property> | ||
<property> | ||
<displayInCategory>usersgroups</displayInCategory> | ||
</property> | ||
<property> | ||
<displayInSection>usersgroups.customrights</displayInSection> | ||
</property> | ||
<property> | ||
<heading/> | ||
</property> | ||
<property> | ||
<iconAttachment/> | ||
</property> | ||
<property> | ||
<linkPrefix/> | ||
</property> | ||
<property> | ||
<propertiesToShow/> | ||
</property> | ||
<property> | ||
<sectionOrder>375</sectionOrder> | ||
</property> | ||
</object> | ||
</xwikidoc> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,13 +40,25 @@ $xwiki.ssfx.use('js/xwiki/usersandgroups/usersandgroups.css', true) | |
$xwiki.jsfx.use('js/xwiki/table/livetable.js', true) | ||
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. What do you think of adding a PageTest for this template? 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. same answer |
||
$xwiki.ssfx.use('js/xwiki/table/livetable.css', true) | ||
## for admin, register, programming and createwiki, allow preceedes over deny | ||
#if("$!request.section"=='wikis.rights') | ||
#set ($standardRights = ['view', 'comment', 'edit', 'script', 'delete', 'admin', 'register', 'programming', 'login', | ||
'createwiki']) | ||
#set ($sectionWikiRights = "wikis.rights") | ||
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. very minor, could be in single quotes 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. is there any advantage to use single quote vs double quote? I generally use double quote because of the Java habit 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. IIRC single quote content is not interpreted whereas double quotes content is, making the single quote alternative slightly faster on static content such as this one. 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. ok so indeed might worth it to change that, thanks 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. yes it's our best practice to use single quotes to the max (for the reason mentioned by Manuel) |
||
#set ($sectionExtensionRights = "usersgroups.customrights") | ||
#if("$!request.section"==$sectionWikiRights) | ||
#set ($rightsLevels = {'createwiki': 0}) | ||
#set ($allowWins = [0]) | ||
## This should be changed in the future to include dynamically registered rights. | ||
#elseif ($services.security.authorization.isRightRegistered('like')) | ||
#set ($rightsLevels = {'view': 0, 'like': 1, 'comment': 2, 'edit': 3, 'script': 4, 'delete': 5, 'admin': 6, 'register': 7, 'programming': 8}) | ||
#set ($allowWins = [5, 6, 7]) | ||
#elseif ("$!request.section"==$sectionExtensionRights) | ||
#set ($allRights = $services.security.authorization.allRightsNames) | ||
#set ($rightsLevels = {}) | ||
#set ($allowWins = []) | ||
#set ($index = 0) | ||
#foreach ($right in $allRights) | ||
#if (!$standardRights.contains($right)) | ||
#set ($discard = $rightsLevels.put($right, $index)) | ||
#set ($discard = $allowWins.add($index)) | ||
#set ($index = $index + 1) | ||
#end | ||
#end | ||
#else | ||
#set ($rightsLevels = {'view': 0, 'comment': 1, 'edit': 2, 'script': 3, 'delete': 4, 'admin': 5, 'register': 6, 'programming': 7}) | ||
#set ($allowWins = [5, 6, 7]) | ||
|
@@ -56,7 +68,7 @@ $xwiki.ssfx.use('js/xwiki/table/livetable.css', true) | |
#set ($discard = $levelsRights.put($rightsLevels.get($r), $r)) | ||
#end | ||
#set ($maxlevel = $rightsLevels.get('delete')) ## Default: view, comment, edit, script, delete | ||
#if("$!request.section"=='wikis.rights') | ||
#if("$!request.section"==$sectionWikiRights) | ||
#set ($maxlevel = $rightsLevels.get('createwiki')) | ||
#set ($clsname = 'XWiki.XWikiGlobalRights') | ||
#else | ||
|
@@ -82,7 +94,9 @@ $xwiki.ssfx.use('js/xwiki/table/livetable.css', true) | |
#set ($clsname = 'XWiki.XWikiRights') | ||
#end | ||
#end | ||
|
||
#if ("$!request.section"==$sectionExtensionRights) | ||
#set ($maxlevel = $index - 1) | ||
#end | ||
## Get rights allowed for the current user | ||
#set ($currentAllowed = {}) | ||
#foreach ($i in [0..$maxlevel]) | ||
|
@@ -235,7 +249,8 @@ $xwiki.ssfx.use('js/xwiki/table/livetable.css', true) | |
</table> | ||
## Global settings: mandatory authentication for view/edit, captcha | ||
#set ($guest_comment_captcha_prop = $targetDocument.getObject('XWiki.XWikiPreferences').getxWikiClass().get('guest_comment_requires_captcha')) | ||
#if (("$!request.editor" == 'globaladmin' || "$!editor" == 'globaladmin' || $guest_comment_captcha_prop) && $request.section != 'wikis.rights') | ||
#if (("$!request.editor" == 'globaladmin' || "$!editor" == 'globaladmin' || $guest_comment_captcha_prop) | ||
&& $request.section != $sectionWikiRights && $request.section != $sectionExtensionRights) | ||
<dl class="rights-settings"> | ||
#if ("$!request.editor" == 'globaladmin' || "$!editor" == 'globaladmin') | ||
#set ($auth_view = $targetDocument.getObject('XWiki.XWikiPreferences').getProperty('authenticate_view').getValue()) | ||
|
@@ -342,7 +357,7 @@ $xwiki.ssfx.use('js/xwiki/table/livetable.css', true) | |
$('unregistered').removeClassName('hidden'); | ||
} | ||
}); | ||
#if("$!editor" == 'globaladmin' && $request.section != 'wikis.rights') | ||
#if("$!editor" == 'globaladmin' && $request.section != $sectionWikiRights && $request.section != $sectionExtensionRights) | ||
Event.observe($('authenticate_view'), 'click', setBooleanPropertyFromLiveCheckbox($('authenticate_view'), '$xwiki.getURL('XWiki.XWikiPreferences', 'save', "form_token=$!{services.csrf.getToken()}")', 'XWiki.XWikiPreferences', 0)); | ||
Event.observe($('authenticate_edit'), 'click', setBooleanPropertyFromLiveCheckbox($('authenticate_edit'), '$xwiki.getURL('XWiki.XWikiPreferences', 'save', "form_token=$!{services.csrf.getToken()}")', 'XWiki.XWikiPreferences', 0)); | ||
#end | ||
|
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.
What do you think of adding a PageTest for this document?
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.
quite frankly I'm not sure it worthes it
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.
Why would you not? Templates are very easy to break on change, so adding some test (even if it's only testing what you changed) seems valuable to me.
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.
@surli said differently, where do you validate that the HTML is correct and that it works? do you have a functional test? it's definitely needed to test somewhere this code.
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.
No I don't have test for now for this. I'll try to provide it for 13.5, I'll merge it like that for now so that I can ensure it's possible to have it for 13.5RC1. Note that I tested it manually and also this code is a copy/paste of what's in AdminWikisRightsSheet.