Cascade delete invitations on deletion of web site.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13998 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2009-04-17 16:14:34 +00:00
parent 91a43578c8
commit 40321d445e
3 changed files with 64 additions and 3 deletions

View File

@@ -40,7 +40,6 @@
<import resource="classpath:alfresco/audit-services-context.xml" /> <import resource="classpath:alfresco/audit-services-context.xml" />
<import resource="classpath:alfresco/attributes-service-context.xml"/> <import resource="classpath:alfresco/attributes-service-context.xml"/>
<import resource="classpath:alfresco/deployment-service-context.xml"/> <import resource="classpath:alfresco/deployment-service-context.xml"/>
<import resource="classpath:alfresco/invitation-service-context.xml"/>
<import resource="classpath:alfresco/linkvalidation-service-context.xml"/> <import resource="classpath:alfresco/linkvalidation-service-context.xml"/>
<import resource="classpath:alfresco/remote-services-context.xml"/> <import resource="classpath:alfresco/remote-services-context.xml"/>
<import resource="classpath*:alfresco/office-addin-context.xml"/> <import resource="classpath*:alfresco/office-addin-context.xml"/>
@@ -51,6 +50,7 @@
<import resource="classpath:alfresco/site-services-context.xml"/> <import resource="classpath:alfresco/site-services-context.xml"/>
<import resource="classpath:alfresco/tagging-services-context.xml"/> <import resource="classpath:alfresco/tagging-services-context.xml"/>
<import resource="classpath:alfresco/form-services-context.xml"/> <import resource="classpath:alfresco/form-services-context.xml"/>
<import resource="classpath:alfresco/invitation-service-context.xml"/>
<import resource="classpath:alfresco/cmis-api-context.xml" /> <import resource="classpath:alfresco/cmis-api-context.xml" />
<import resource="classpath*:alfresco/patch/*-context.xml" /> <import resource="classpath*:alfresco/patch/*-context.xml" />
<import resource="classpath*:alfresco/domain/*-context.xml" /> <import resource="classpath*:alfresco/domain/*-context.xml" />

View File

@@ -3,7 +3,7 @@
<beans> <beans>
<!-- Invitation Service Configuration File --> <!-- Invitation Service Configuration File -->
<bean id="invitationService" class="org.alfresco.repo.invitation.InvitationServiceImpl"> <bean id="invitationService" class="org.alfresco.repo.invitation.InvitationServiceImpl" init-method="init">
<property name="workflowService" ref="WorkflowService"/> <property name="workflowService" ref="WorkflowService"/>
<property name="personService" ref="PersonService"/> <property name="personService" ref="PersonService"/>
<property name="permissionService" ref="PermissionService"/> <property name="permissionService" ref="PermissionService"/>
@@ -14,6 +14,9 @@
<property name="nodeService" ref="NodeService"/> <property name="nodeService" ref="NodeService"/>
<property name="userNameGenerator" ref="userNameGenerator"/> <property name="userNameGenerator" ref="userNameGenerator"/>
<property name="passwordGenerator" ref="passwordGenerator"/> <property name="passwordGenerator" ref="passwordGenerator"/>
<property name="policyComponent">
<ref bean="policyComponent" />
</property>
</bean> </bean>
<!-- Site service security bean --> <!-- Site service security bean -->

View File

@@ -62,6 +62,9 @@ import org.alfresco.util.GUID;
import org.alfresco.util.PropertyCheck; import org.alfresco.util.PropertyCheck;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.invitation.site.*; import org.alfresco.repo.invitation.site.*;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.MutableAuthenticationDao; import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
import org.alfresco.repo.security.authentication.PasswordGenerator; import org.alfresco.repo.security.authentication.PasswordGenerator;
@@ -80,7 +83,7 @@ import org.apache.commons.logging.LogFactory;
* @author mrogers * @author mrogers
* *
*/ */
public class InvitationServiceImpl implements InvitationService public class InvitationServiceImpl implements InvitationService, NodeServicePolicies.BeforeDeleteNodePolicy
{ {
private static final Log logger = LogFactory private static final Log logger = LogFactory
.getLog(InvitationServiceImpl.class); .getLog(InvitationServiceImpl.class);
@@ -99,6 +102,7 @@ public class InvitationServiceImpl implements InvitationService
// user name and password generation beans // user name and password generation beans
private UserNameGenerator usernameGenerator; private UserNameGenerator usernameGenerator;
private PasswordGenerator passwordGenerator; private PasswordGenerator passwordGenerator;
private PolicyComponent policyComponent;
// maximum number of tries to generate a invitee user name which // maximum number of tries to generate a invitee user name which
// does not already belong to an existing person // does not already belong to an existing person
@@ -106,6 +110,16 @@ public class InvitationServiceImpl implements InvitationService
private int maxUserNameGenRetries = MAX_NUM_INVITEE_USER_NAME_GEN_TRIES; private int maxUserNameGenRetries = MAX_NUM_INVITEE_USER_NAME_GEN_TRIES;
/**
* Set the policy component
*
* @param policyComponent policy component
*/
public void setPolicyComponent(PolicyComponent policyComponent)
{
this.policyComponent = policyComponent;
}
/** /**
* Checks that all necessary properties and services have been provided. * Checks that all necessary properties and services have been provided.
@@ -123,6 +137,13 @@ public class InvitationServiceImpl implements InvitationService
PropertyCheck.mandatory(this, "NodeService", nodeService); PropertyCheck.mandatory(this, "NodeService", nodeService);
PropertyCheck.mandatory(this, "UserNameGenerator", usernameGenerator); PropertyCheck.mandatory(this, "UserNameGenerator", usernameGenerator);
PropertyCheck.mandatory(this, "PasswordGenerator", passwordGenerator); PropertyCheck.mandatory(this, "PasswordGenerator", passwordGenerator);
PropertyCheck.mandatory(this, "PolicyComponent", policyComponent);
//
this.policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
SiteModel.TYPE_SITE,
new JavaBehaviour(this, "beforeDeleteNode"));
} }
/** /**
@@ -1421,4 +1442,41 @@ public class InvitationServiceImpl implements InvitationService
private int getMaxUserNameGenRetries() { private int getMaxUserNameGenRetries() {
return maxUserNameGenRetries; return maxUserNameGenRetries;
} }
/**
* NodeServicePolicies.BeforeDeleteNodePolicy
*
* Called immediatly prior to deletion of a web site.
*/
public void beforeDeleteNode(NodeRef nodeRef)
{
logger.debug("beforeDeleteNode");
final NodeRef siteRef = nodeRef;
// Run as system user
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>()
{
public Object doWork() throws Exception
{
QName type = nodeService.getType(siteRef);
if(type.equals(SiteModel.TYPE_SITE))
{
// this is a web site being deleted.
String siteName = (String)nodeService.getProperty(siteRef, ContentModel.PROP_NAME);
if(siteName != null)
{
logger.debug("Invitation service delete node fired " + type + ", " +siteName);
List<Invitation> invitations = listPendingInvitationsForResource(Invitation.ResourceType.WEB_SITE, siteName);
for(Invitation invitation : invitations)
{
logger.debug("cancel workflow " + invitation.getInviteId());
workflowService.cancelWorkflow(invitation.getInviteId());
}
}
}
return null;
}
}, AuthenticationUtil.SYSTEM_USER_NAME);
}
} }