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
Hide line numbers
1: {{velocity}} 2: #set ($workspaceName = $request.workspaceName) 3: #set ($workspaceId = $request.workspaceId) 4: #set ($confirm = $request.confirm) 5: ## 6: #if ("$!workspaceId" == '' || "$!workspaceName" == '') 7: {{error}}[workspaceId] and [workspaceName] parameters are not specified.{{/error}} 8: #else 9: ## FIXME: add plugin dependency checks. 10: ## 11: #set ($WorkspaceManager = $services.workspace) 12: ## 13: #set ($workspace = $WorkspaceManager.getWorkspace($workspaceId)) 14: ## 15: #if ("$!workspace" == '') 16: #if ("$!{WorkspaceManager.lastException}" != '') 17: {{error}}Exception: $!{WorkspaceManager.lastException.message}{{/error}} 18: #else 19: {{error}}$msg.get('workspacemanager.error.workspacedoesnotexist', ["$workspaceId"]){{/error}} 20: #end 21: #else 22: #set ($workspaceGroupDocument = $workspace.groupDocument) 23: ## 24: ## 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. 25: ## 26: #set ($workspaceGroupDocumentRestricted = $workspaceGroupDocument.document) 27: #set ($groupsClassReference = $services.model.createDocumentReference($workspaceId, 'XWiki', 'XWikiGroups')) 28: #set ($currentUser = "${xcontext.mainWikiName}:${xcontext.user}") 29: #set ($workspaceUrl = $workspace.wikiDescriptor.homePageUrl) 30: ## 31: #set ($existingMemberObject = $workspaceGroupDocumentRestricted.getXObject($groupsClassReference, 'member', $currentUser)) 32: #if ("$!existingMemberObject" == '') 33: {{error}}The user [[$currentUser]] is not a member of the workspace [[$workspaceName>>$workspaceUrl]].{{/error}} 34: #elseif ($workspace.wikiDescriptor.owner == $currentUser) 35: {{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}} 36: #else 37: #if ("$!confirm" != 1) 38: #set ($browseDocumentReference = $services.model.createDocumentReference($xcontext.mainWikiName, 'WorkspaceManager', 'WebHome')) 39: #set ($backUrl = $xwiki.getURL($browseDocumentReference)) 40: #set ($confirmUrl = $doc.getURL('view', "$!request.queryString&confirm=1")) 41: {{box}} 42: Are you sure you want to leave workspace [[$workspaceName>>$workspaceUrl]]? 43: ((({{html}} 44: <span class="buttonwrapper"><a class="button" href="$confirmUrl">Yes</a> <a class="button" href="$backUrl">No</a></span> 45: {{/html}}))) 46: {{/box}} 47: #else 48: #set ($temp = $workspaceGroupDocumentRestricted.removeXObject($existingMemberObject)) 49: #set ($temp = $xwiki.getXWiki().saveDocument($workspaceGroupDocumentRestricted, "User $currentUser left workspace.", true, $xcontext.context)) 50: {{success}}The user [[$currentUser]] successfully left workspace [[$workspaceName>>$workspaceUrl]].{{/success}} 51: #end 52: #end 53: #end 54: #end 55: {{/velocity}}