General Actions:
Log-in
Register
Wiki:
Main wiki
▼
:
Document Index
»
Space:
WorkspaceManager
▼
:
Document Index
»
Page:
LeaveWorkspaceCode
Search
en
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Main wiki
»
Browse Workspaces
»
Leave Workspace
Wiki source code of
Leave Workspace
Last modified by
Administrator
on 2012/03/21 17:40
Content
·
Comments
(0)
·
Annotations
(0)
·
Attachments
(0)
·
History
·
Information
Show line numbers
{{velocity}} #set ($workspaceName = $request.workspaceName) #set ($workspaceId = $request.workspaceId) #set ($confirm = $request.confirm) ## #if ("$!workspaceId" == '' || "$!workspaceName" == '') {{error}}[workspaceId] and [workspaceName] parameters are not specified.{{/error}} #else ## FIXME: add plugin dependency checks. ## #set ($WorkspaceManager = $services.workspace) ## #set ($workspace = $WorkspaceManager.getWorkspace($workspaceId)) ## #if ("$!workspace" == '') #if ("$!{WorkspaceManager.lastException}" != '') {{error}}Exception: $!{WorkspaceManager.lastException.message}{{/error}} #else {{error}}$msg.get('workspacemanager.error.workspacedoesnotexist', ["$workspaceId"]){{/error}} #end #else #set ($workspaceGroupDocument = $workspace.groupDocument) ## ## Use the low level API since this page has PR and we need to make the current user modify a document of a wiki he does not yet have access to. ## #set ($workspaceGroupDocumentRestricted = $workspaceGroupDocument.document) #set ($groupsClassReference = $services.model.createDocumentReference($workspaceId, 'XWiki', 'XWikiGroups')) #set ($currentUser = "${xcontext.mainWikiName}:${xcontext.user}") #set ($workspaceUrl = $workspace.wikiDescriptor.homePageUrl) ## #set ($existingMemberObject = $workspaceGroupDocumentRestricted.getXObject($groupsClassReference, 'member', $currentUser)) #if ("$!existingMemberObject" == '') {{error}}The user [[$currentUser]] is not a member of the workspace [[$workspaceName>>$workspaceUrl]].{{/error}} #elseif ($workspace.wikiDescriptor.owner == $currentUser) {{error}}The user [[$currentUser]] is the owner of the workspace [[$workspaceName>>$workspaceUrl]]. The owner of a workspace may not leave it unless the workspace is deleted or the owner is changed.{{/error}} #else #if ("$!confirm" != 1) #set ($browseDocumentReference = $services.model.createDocumentReference($xcontext.mainWikiName, 'WorkspaceManager', 'WebHome')) #set ($backUrl = $xwiki.getURL($browseDocumentReference)) #set ($confirmUrl = $doc.getURL('view', "$!request.queryString&confirm=1")) {{box}} Are you sure you want to leave workspace [[$workspaceName>>$workspaceUrl]]? ((({{html}} <span class="buttonwrapper"><a class="button" href="$confirmUrl">Yes</a> <a class="button" href="$backUrl">No</a></span> {{/html}}))) {{/box}} #else #set ($temp = $workspaceGroupDocumentRestricted.removeXObject($existingMemberObject)) #set ($temp = $xwiki.getXWiki().saveDocument($workspaceGroupDocumentRestricted, "User $currentUser left workspace.", true, $xcontext.context)) {{success}}The user [[$currentUser]] successfully left workspace [[$workspaceName>>$workspaceUrl]].{{/success}} #end #end #end #end {{/velocity}}