Merge WCM-SERVICES to HEAD

Changes 11272-11536

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@11562 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2008-10-27 17:02:00 +00:00
parent e56a24a351
commit 7b47b75eb1
23 changed files with 484 additions and 2222 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
* Copyright (C) 2005-2008 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,26 +24,18 @@
*/
package org.alfresco.web.bean.wcm;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.faces.context.FacesContext;
import org.alfresco.model.WCMAppModel;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.wcm.util.WCMUtil;
import org.alfresco.wcm.webproject.WebProjectService;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.wizard.BaseInviteUsersWizard;
import org.alfresco.web.ui.common.Utils;
@@ -68,19 +60,21 @@ public class InviteWebsiteUsersWizard extends BaseInviteUsersWizard
/** assume we are launching the wizard standalone */
private boolean standalone = true;
/** AVM Browse Bean reference */
protected AVMBrowseBean avmBrowseBean;
transient private WebProjectService wpService;
/** Data for virtualization server notification */
private List<SandboxInfo> sandboxInfoList;
/**
* @param avmBrowseBean The AVMBrowseBean to set.
*/
public void setAvmBrowseBean(AVMBrowseBean avmBrowseBean)
public void setWebProjectService(WebProjectService wpService)
{
this.avmBrowseBean = avmBrowseBean;
this.wpService = wpService;
}
protected WebProjectService getWebProjectService()
{
if (wpService == null)
{
wpService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getWebProjectService();
}
return wpService;
}
/**
@@ -114,205 +108,17 @@ public class InviteWebsiteUsersWizard extends BaseInviteUsersWizard
{
super.finishImpl(context, outcome);
// break the permissions inheritance on the node so that only assigned users can access it
NodeRef nodeRef = this.getNode().getNodeRef();
this.getPermissionService().setInheritParentPermissions(nodeRef, false);
// create a sandbox for each user appropriately with permissions based on role
// build a list of managers who will have full permissions on ALL staging areas
List<String> managers = new ArrayList<String>(4);
Set<String> existingUsers = new HashSet(8);
if (isStandalone() == false)
{
// no website created yet - so we need to build the list of managers from the
// invited users and the power user who is executing the create web project wizard
boolean foundCurrentUser = false;
String currentUser = Application.getCurrentUser(context).getUserName();
for (UserGroupRole userRole : this.userGroupRoles)
{
for (String userAuth : findNestedUserAuthorities(userRole.getAuthority()))
{
if (currentUser.equals(userAuth))
{
foundCurrentUser = true;
}
if (AVMUtil.ROLE_CONTENT_MANAGER.equals(userRole.getRole()))
{
managers.add(userAuth);
}
}
}
if (foundCurrentUser == false)
{
this.userGroupRoles.add(new UserGroupRole(currentUser, AVMUtil.ROLE_CONTENT_MANAGER, null));
managers.add(currentUser);
// assign permissions explicitly for the current user
this.getPermissionService().setPermission(
nodeRef,
currentUser,
AVMUtil.ROLE_CONTENT_MANAGER,
true);
}
}
else
{
// website already exists - we are only adding to the existing sandboxes
// so retrieve the list of managers from the existing users and the selected invitees
for (UserGroupRole userRole : this.userGroupRoles)
{
for (String userAuth : findNestedUserAuthorities(userRole.getAuthority()))
{
if (AVMUtil.ROLE_CONTENT_MANAGER.equals(userRole.getRole()))
{
managers.add(userAuth);
}
}
}
List<ChildAssociationRef> userInfoRefs = this.getNodeService().getChildAssocs(
getNode().getNodeRef(), WCMAppModel.ASSOC_WEBUSER, RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef ref : userInfoRefs)
{
NodeRef userInfoRef = ref.getChildRef();
String username = (String)getNodeService().getProperty(userInfoRef, WCMAppModel.PROP_WEBUSERNAME);
String userrole = (String)getNodeService().getProperty(userInfoRef, WCMAppModel.PROP_WEBUSERROLE);
if (AVMUtil.ROLE_CONTENT_MANAGER.equals(userrole) &&
managers.contains(username) == false)
{
managers.add(username);
}
// add each existing user to the exclude this - we cannot add them more than once!
existingUsers.add(username);
}
}
// build the sandboxes now we have the manager list and complete user list
// and create an association to a node to represent each invited user
this.sandboxInfoList = new LinkedList<SandboxInfo>();
boolean managersUpdateRequired = false;
Map<String, String> selectedInvitees = new HashMap<String, String>(this.userGroupRoles.size());
for (UserGroupRole userRole : this.userGroupRoles)
{
for (String userAuth : findNestedUserAuthorities(userRole.getAuthority()))
{
// create the sandbox if the invited user does not already have one
if (existingUsers.contains(userAuth) == false)
{
SandboxInfo info = SandboxFactory.createUserSandbox(
getAvmStore(), managers, userAuth, userRole.getRole());
SandboxFactory.addStagingAreaUser(getAvmStore(), userAuth, userRole.getRole());
this.sandboxInfoList.add(info);
// create an app:webuser instance for each authority and assoc to the website node
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f);
props.put(WCMAppModel.PROP_WEBUSERNAME, userAuth);
props.put(WCMAppModel.PROP_WEBUSERROLE, userRole.getRole());
this.getNodeService().createNode(getNode().getNodeRef(),
WCMAppModel.ASSOC_WEBUSER,
WCMAppModel.ASSOC_WEBUSER,
WCMAppModel.TYPE_WEBUSER,
props);
// if this new user is a manager, we'll need to update the manager permissions applied
// to each existing user sandbox - to ensure that new managers have access to them
managersUpdateRequired |= (AVMUtil.ROLE_CONTENT_MANAGER.equals(userRole.getRole()));
}
}
}
if (isStandalone() == true && managersUpdateRequired == true)
{
// walk existing sandboxes and reapply manager permissions to include any new manager users
List<ChildAssociationRef> userInfoRefs = this.getNodeService().getChildAssocs(
getNode().getNodeRef(), WCMAppModel.ASSOC_WEBUSER, RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef ref : userInfoRefs)
{
NodeRef userInfoRef = ref.getChildRef();
String username = (String)getNodeService().getProperty(userInfoRef, WCMAppModel.PROP_WEBUSERNAME);
if (existingUsers.contains(username))
{
// only need to modify the sandboxes we haven't just created
SandboxFactory.updateSandboxManagers(getAvmStore(), managers, username);
}
}
SandboxFactory.updateStagingAreaManagers(getAvmStore(), getNode().getNodeRef(), managers);
selectedInvitees.put(userRole.getAuthority(), userRole.getRole());
}
getWebProjectService().inviteWebUsersGroups(this.getNode().getNodeRef(), selectedInvitees);
return outcome;
}
/**
* Handle notification to the virtualization server
* (this needs to occur after the sandbox is created in the main txn).
*/
@Override
protected String doPostCommitProcessing(FacesContext context, String outcome)
{
// reload virtualisation server for webapp in this web project
if (isStandalone())
{
for (SandboxInfo sandboxInfo : this.sandboxInfoList)
{
String newlyInvitedStoreName = AVMUtil.buildStagingStoreName(
sandboxInfo.getMainStoreName());
String path = AVMUtil.buildStoreWebappPath(
newlyInvitedStoreName, this.avmBrowseBean.getWebapp());
AVMUtil.updateVServerWebapp(path, true);
}
}
return outcome;
}
/**
* Find all nested user authorities contained with an authority
*
* @param authority The authority to search, USER authorities are returned immediately, GROUP authorites
* are recursively scanned for contained USER authorities.
*
* @return a Set of USER authorities
*/
private Set<String> findNestedUserAuthorities(String authority)
{
Set<String> users;
AuthorityType authType = AuthorityType.getAuthorityType(authority);
if (authType.equals(AuthorityType.USER))
{
users = new HashSet<String>(1, 1.0f);
if (this.getPersonService().personExists(authority) == true)
{
users.add(authority);
}
}
else if (authType.equals(AuthorityType.GROUP))
{
// walk each member of the group
users = this.getAuthorityService().getContainedAuthorities(AuthorityType.USER, authority, false);
for (String userAuth : users)
{
if (this.getPersonService().personExists(userAuth) == false)
{
users.remove(authType);
}
}
}
else
{
users = Collections.<String>emptySet();
}
return users;
}
/**
* @return summary text for the wizard
*/
@@ -336,7 +142,7 @@ public class InviteWebsiteUsersWizard extends BaseInviteUsersWizard
if (isStandalone() == false && foundCurrentUser == false)
{
buf.append(buildLabelForUserAuthorityRole(
currentUser, AVMUtil.ROLE_CONTENT_MANAGER));
currentUser, WCMUtil.ROLE_CONTENT_MANAGER));
}
return buildSummary(