Is there are some way to create section in user profile which can be seen only by specific group of users?
Example of a condition in wiki syntax:
{{velocity}}
#if ($xwiki.user.isUserInGroup('XWiki.XWikiAllGroup'))
Hello world!
#end
{{/velocity}}
So you’ll just need to modify the user sheet to add some conditions
The page containing the user sheet is XWiki.XWikiUserSheet
.
If i create section in USERS & GROUPS > User Profile and in SECTION PROPERTIES type
{{velocity}}
#if ($xwiki.user.isUserInGroup(‘XWiki.Admin’))
Hello world!
#end
{{/velocity}}
will only thous who is in Admin group will see
“Hello world!”?
And this section will be in every user`s profile
What page is that?
The Admin group name is XWiki.XWikiAdminGroup
.
Administration: User Profile
i mean random group name, it can be any other
Or there is a specific page "XWiki.XWikiUserSheet " and all changes for all users must be done there? (didn`t find it and thount that this is some user sheet) And i just making a stupid mistake…
OK, I give up… I cant find XWiki.XWikiUserSheet. If someone can help me, I will be very appreciate
http://xxxxxxxxx/xwiki/bin/view/XWiki/XWikiUserSheet
or Ctrl+G => XWiki.XWikiUserSheet
Don’t forget to display hidden page in your xwiki profile because XWiki.XWikiUserSheet is a hidden page.
Pascal B
Thanks a lot!!
It was so not obviously for me ))
BTW if you need to navigate to a page: https://www.xwiki.org/xwiki/bin/view/FAQ/How%20can%20I%20navigate%20to%20a%20given%20page
So if I wont to hide section “links” for all but users from admin group, i should delete it from “Displayed section” in User Profile, and add to XWiki.XWikiUserSheet something like this?
#if ($xwiki.user.isUserInGroup(‘XWiki.Admin’))
$object.display(‘links’)
#end
Yes, except that your example won’t work since it’s not referring to the Admin Group (see my previous comment about that).
Its me again.
Looks like that method didn’t work ((
I am able to hide all section in User Profile from all, accept thous who is in Admin group by editing XWikiUserProfileSheet like this
#if ($xwiki.user.isUserInGroup('XWiki.XWikiAdminGroup'))
#foreach ($sectionId in $sectionsToDisplay)
#set ($sectionObject = $sheetDocument.getObject($sectionObjectClassName, 'id', $sectionId))
#set ($sectionName = "$!sectionObject.getProperty('name').value")
Now i want to hide section “links” from all accept Admins, i tried this way
#if ($xwiki.user.isUserInGroup('XWiki.XWikiAdminGroup'))
#foreach ($sectionId in $sectionsToDisplay)
#else
#foreach (($sectionId != 'links') in $sectionsToDisplay )
#set ($sectionObject = $sheetDocument.getObject($sectionObjectClassName, 'id', $sectionId))
#set ($sectionName = "$!sectionObject.getProperty('name').value")
And its not right. Could you please show me my error? Or give some decision
You just need to add your IF inside the FOREACH and test for the sectionId value…
not quite get it but i’ll try. but first of all i getting error in #else part
Encountered “#else\r\n” at 34:xwiki:XWiki.XWikiUserSheet[line 40, column 1]
Was expecting one of:
“(” …
…
<ESCAPE_DIRECTIVE> …
<SET_DIRECTIVE> …
“##” …
“\\” …
“\” …
…
“#" …
"#” …
“]]#” …
<STRING_LITERAL> …
…
<IF_DIRECTIVE> …
<INTEGER_LITERAL> …
<FLOATING_POINT_LITERAL> …
…
<BRACKETED_WORD> …
…
…
“{” …
“}” …
<EMPTY_INDEX> …
This just means your velocity is invalid. Can’t help without seeing the script you wrote.
{{velocity}}
#set ($discard = $xwiki.ssx.use('XWiki.XWikiUserSheet'))
##
#set ($inEditMode = $xcontext.action == 'edit' || $xcontext.action == 'inline')
#set ($xwikiUsersClassName = 'XWiki.XWikiUsers')
#set ($obj = $doc.getObject($xwikiUsersClassName))
##
#if (!$obj)
= $services.localization.render('xe.admin.users.sheet') =
{{info}}$services.localization.render('xe.admin.users.applyonusers'){{/info}}
#else
## Make sure we only care about properties of the user object and don't get polluted by other objects that might be in the user's profile page.
#set ($discard = $doc.use($obj))
##
#set ($sheetDocumentReference = $services.model.createDocumentReference($xcontext.database, 'XWiki', 'AdminUserProfileSheet'))
#set ($sheetDocument = $xwiki.getDocument($sheetDocumentReference))
#set ($xwikiUsersClass = $xwiki.getClass($xwikiUsersClassName))
##
#set ($sectionsObjectClassName = 'XWiki.UserProfileSectionsClass')
#set ($sectionObjectClassName = 'XWiki.UserProfileSectionClass')
##
{{html clean='false' wiki='true'}}
#if (!$inEditMode)
<div class="vcard">
<span class="fn hidden">$xwiki.getUserName($doc.fullName, false)</span>
#end
<div class="#if($xcontext.action == 'view')half #{else}full #{end}column xform">
<div class='userInfo'>
#if($xcontext.action == 'view' && $hasEdit)
<div class='editProfileCategory'><a href="$doc.getURL('edit', 'editor=inline&category=profile')"><span class='hidden'>$services.localization.render('platform.core.profile.category.profile.edit')</span></a></div>
#end
## Please do not insert extra empty lines here (as it affects the validity of the rendered xhtml)
#set ($sectionsObject = $sheetDocument.getObject($sectionsObjectClassName))
#set ($sectionsToDisplayString = $sectionsObject.getProperty('sections').value)
#set ($sectionsToDisplay = $sectionsToDisplayString.split('\s+'))
##TESTING
#if ($xwiki.user.isUserInGroup('XWiki.XWikiAdminGroup'))
#foreach ($sectionId in $sectionsToDisplay)
#else
#foreach (($sectionId != 'links') in $sectionsToDisplay )
#set ($sectionObject = $sheetDocument.getObject($sectionObjectClassName, 'id', $sectionId))
#set ($sectionName = "$!sectionObject.getProperty('name').value")
## The section name will be evaluated. The admin can specify a static string or a call to $msg(...) to provide internationalization support.
#set ($sectionName = "#evaluate($!sectionName)")
## If there is no section name specified, use the default translations prefix for the user profile, maybe we get lucky.
#if ("$!sectionName" == '')
#set ($sectionName = $services.localization.render("platform.core.profile.section.${sectionId}"))
#end
## If that does not work either, just display the sectionID.
#if ("$!sectionName" == "platform.core.profile.section.${sectionId}")
#set ($sectionName = $sectionId)
#end
#end
#set ($sectionPropertiesString = $sectionObject.getProperty('properties').value)
#set ($sectionProperties = $sectionPropertiesString.split('\s+'))
#if ($sectionProperties && $sectionProperties.size() > 0)
<h1>$sectionName</h1>
<dl>
#foreach ($sectionProperty in $sectionProperties)
#set ($vCardData = $sectionProperty.split(':'))
#set ($vCardProperty = '')
#if ($vCardData.size() == 2)
#set ($vCardProperty = $vCardData[0])
#set ($sectionProperty = $vCardData[1])
#end
#if ("$!sectionProperty" != '' && $xwikiUsersClass.get($sectionProperty))
<dt class='label'>
<label #if($inEditMode)for="${xwikiUsersClassName}_${obj.number}_${sectionProperty}"#{end}>$doc.displayPrettyName("${sectionProperty}")</label>
</dt>
<dd #if("$!vCardProperty" != '' && !$inEditMode)class="$vCardProperty"#{end}>$doc.display($sectionProperty)</dd>
#end
#end
</dl>
#end
#end
</div>
</div>
#if (!$inEditMode)
<div class='half column'>
#set ($isMessageStreamActive = $services.messageStream.isActive())
#if ($isMessageStreamActive && !$isGuest)
<div class='userMessage profile-section'>
<h1>$services.localization.render('platform.core.profile.section.sendMessage')</h1>
{{messageSender /}}
</div>
#end
<div class='userRecentChanges'>
#if ($xcontext.user == $doc.fullName)
<h1>$services.localization.render('platform.core.profile.section.activity')</h1>
#else
<h1>$services.localization.render('platform.core.profile.section.activityof', [$xwiki.getUserName($doc.fullName, false)])</h1>
#if ($hasWatch)
$xwiki.ssx.use('XWiki.XWikiUserProfileSheet')##
<div class='activity-follow'>
#set ($xredirect = $doc.getURL($xcontext.action, $request.queryString))
#if ($services.watchlist.isWatched(${doc.prefixedFullName}, "USER"))
<span class='following'>$services.localization.render('xe.activity.messages.following')</span>
<a class='action unfollow' href="$doc.getURL('view', "xpage=watch&do=removeuser&xredirect=${escapetool.url($xredirect)}")">$services.localization.render('xe.activity.messages.unfollow')</a>
#else
<a class='action follow' href="$doc.getURL('view', "xpage=watch&do=adduser&xredirect=${escapetool.url($xredirect)}")">$services.localization.render('xe.activity.messages.follow')</a>
#end
</div>
#end
#end
{{/html}}
{{activity authors="${doc.prefixedFullName}" /}}
{{html clean='false'}}
</div>
</div>
#end
<div class='clearfloats'> </div>
#if(!$inEditMode)
## Close the vcard
</div>
#end
{{/html}}##
#end
{{/velocity}}
That’s not correct.
You just need to add your IF inside the FOREACH and test for the sectionId value…
#foreach (...)
#if (...)
#else
#end
#end