mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)
69765: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud) 69685: Merged V4.1-BUG-FIX (4.1.9) to V4.2-BUG-FIX (4.2.3) 68638: Merged DEV to V4.1-BUG-FIX (4.1.9) 68070 : MNT-11289 : Sites deleted in 2013 cannot be restored in 2014 - Recreate groups when a site is restored on condition that the groups are missing. Make current user site manager if there is no site managers. Fix related test git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@70448 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -50,6 +50,8 @@ import org.alfresco.repo.admin.SysAdminParams;
|
|||||||
import org.alfresco.repo.cache.SimpleCache;
|
import org.alfresco.repo.cache.SimpleCache;
|
||||||
import org.alfresco.repo.node.NodeArchiveServicePolicies;
|
import org.alfresco.repo.node.NodeArchiveServicePolicies;
|
||||||
import org.alfresco.repo.node.NodeArchiveServicePolicies.BeforePurgeNodePolicy;
|
import org.alfresco.repo.node.NodeArchiveServicePolicies.BeforePurgeNodePolicy;
|
||||||
|
import org.alfresco.repo.node.NodeServicePolicies;
|
||||||
|
import org.alfresco.repo.node.NodeServicePolicies.OnRestoreNodePolicy;
|
||||||
import org.alfresco.repo.node.getchildren.FilterProp;
|
import org.alfresco.repo.node.getchildren.FilterProp;
|
||||||
import org.alfresco.repo.node.getchildren.FilterPropString;
|
import org.alfresco.repo.node.getchildren.FilterPropString;
|
||||||
import org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString;
|
import org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString;
|
||||||
@@ -118,7 +120,7 @@ import org.springframework.extensions.surf.util.ParameterCheck;
|
|||||||
*
|
*
|
||||||
* @author Roy Wetherall
|
* @author Roy Wetherall
|
||||||
*/
|
*/
|
||||||
public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServiceInternal, SiteModel, NodeArchiveServicePolicies.BeforePurgeNodePolicy
|
public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServiceInternal, SiteModel, NodeArchiveServicePolicies.BeforePurgeNodePolicy, NodeServicePolicies.OnRestoreNodePolicy
|
||||||
{
|
{
|
||||||
/** Logger */
|
/** Logger */
|
||||||
protected static Log logger = LogFactory.getLog(SiteServiceImpl.class);
|
protected static Log logger = LogFactory.getLog(SiteServiceImpl.class);
|
||||||
@@ -402,6 +404,10 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
|
|||||||
BeforePurgeNodePolicy.QNAME,
|
BeforePurgeNodePolicy.QNAME,
|
||||||
SiteModel.TYPE_SITE,
|
SiteModel.TYPE_SITE,
|
||||||
new JavaBehaviour(this, "beforePurgeNode"));
|
new JavaBehaviour(this, "beforePurgeNode"));
|
||||||
|
this.policyComponent.bindClassBehaviour(
|
||||||
|
OnRestoreNodePolicy.QNAME,
|
||||||
|
SiteModel.TYPE_SITE,
|
||||||
|
new JavaBehaviour(this, "onRestoreNode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -563,6 +569,12 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
|
|||||||
*/
|
*/
|
||||||
private void setupSitePermissions(
|
private void setupSitePermissions(
|
||||||
final NodeRef siteNodeRef, final String shortName, final SiteVisibility visibility, final Map<String, Set<String>> memberships)
|
final NodeRef siteNodeRef, final String shortName, final SiteVisibility visibility, final Map<String, Set<String>> memberships)
|
||||||
|
{
|
||||||
|
setupSitePermissions(siteNodeRef, shortName, visibility, memberships, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupSitePermissions(
|
||||||
|
final NodeRef siteNodeRef, final String shortName, final SiteVisibility visibility, final Map<String, Set<String>> memberships, final boolean ignoreExistingGroups)
|
||||||
{
|
{
|
||||||
// Get the current user
|
// Get the current user
|
||||||
final String currentUser = authenticationContext.getCurrentUserName();
|
final String currentUser = authenticationContext.getCurrentUserName();
|
||||||
@@ -593,14 +605,26 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
|
|||||||
|
|
||||||
// Create the site's groups
|
// Create the site's groups
|
||||||
String siteGroupShortName = getSiteGroup(shortName, false);
|
String siteGroupShortName = getSiteGroup(shortName, false);
|
||||||
String siteGroup = authorityService.createAuthority(AuthorityType.GROUP, siteGroupShortName,
|
/* MNT-11289 fix - group is probably already exists. we should check it for existence */
|
||||||
|
String siteGroup = authorityService.getName(AuthorityType.GROUP, siteGroupShortName);
|
||||||
|
if (!ignoreExistingGroups || !authorityService.authorityExists(siteGroup))
|
||||||
|
{
|
||||||
|
siteGroup = authorityService.createAuthority(AuthorityType.GROUP, siteGroupShortName,
|
||||||
siteGroupShortName, shareZones);
|
siteGroupShortName, shareZones);
|
||||||
|
}
|
||||||
QName siteType = directNodeService.getType(siteNodeRef);
|
QName siteType = directNodeService.getType(siteNodeRef);
|
||||||
Set<String> permissions = permissionService.getSettablePermissions(siteType);
|
Set<String> permissions = permissionService.getSettablePermissions(siteType);
|
||||||
for (String permission : permissions)
|
for (String permission : permissions)
|
||||||
{
|
{
|
||||||
// Create a group for the permission
|
// Create a group for the permission
|
||||||
String permissionGroupShortName = getSiteRoleGroup(shortName, permission, false);
|
String permissionGroupShortName = getSiteRoleGroup(shortName, permission, false);
|
||||||
|
/* MNT-11289 fix - group is probably already exists. we should check it for existence */
|
||||||
|
String authorityName = authorityService.getName(AuthorityType.GROUP, permissionGroupShortName);
|
||||||
|
if (ignoreExistingGroups && authorityService.authorityExists(authorityName))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
String permissionGroup = authorityService.createAuthority(AuthorityType.GROUP,
|
String permissionGroup = authorityService.createAuthority(AuthorityType.GROUP,
|
||||||
permissionGroupShortName, permissionGroupShortName, shareZones);
|
permissionGroupShortName, permissionGroupShortName, shareZones);
|
||||||
authorityService.addAuthority(siteGroup, permissionGroup);
|
authorityService.addAuthority(siteGroup, permissionGroup);
|
||||||
@@ -646,9 +670,12 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
|
|||||||
permissionService.setPermission(siteNodeRef,
|
permissionService.setPermission(siteNodeRef,
|
||||||
PermissionService.ALL_AUTHORITIES,
|
PermissionService.ALL_AUTHORITIES,
|
||||||
PermissionService.READ_PERMISSIONS, true);
|
PermissionService.READ_PERMISSIONS, true);
|
||||||
if (memberships == null)
|
|
||||||
|
// add the default site manager authority
|
||||||
|
Set<String> currentManagers =
|
||||||
|
authorityService.getContainedAuthorities(AuthorityType.USER, getSiteRoleGroup(shortName, SiteModel.SITE_MANAGER, true), false);
|
||||||
|
if (currentManagers.isEmpty())
|
||||||
{
|
{
|
||||||
// add the default site manager authority
|
|
||||||
authorityService.addAuthority(getSiteRoleGroup(shortName,
|
authorityService.addAuthority(getSiteRoleGroup(shortName,
|
||||||
SiteModel.SITE_MANAGER, true), currentUser);
|
SiteModel.SITE_MANAGER, true), currentUser);
|
||||||
}
|
}
|
||||||
@@ -1820,6 +1847,22 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
|
|||||||
return getPagingResults(pagingRequest, results);
|
return getPagingResults(pagingRequest, results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.alfresco.repo.node.NodeServicePolicies.OnRestoreNodePolicy#onRestoreNode(org.alfresco.service.cmr.repository.ChildAssociationRef)
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void onRestoreNode(ChildAssociationRef childAssocRef)
|
||||||
|
{
|
||||||
|
// regenerate the groups for the site when it is restored from the Archive store
|
||||||
|
NodeRef siteRef = childAssocRef.getChildRef();
|
||||||
|
setupSitePermissions(
|
||||||
|
siteRef,
|
||||||
|
(String)directNodeService.getProperty(siteRef, ContentModel.PROP_NAME),
|
||||||
|
getSiteVisibility(siteRef),
|
||||||
|
(Map<String, Set<String>>)directNodeService.getProperty(siteRef, QName.createQName(null, "memberships")), true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.alfresco.service.cmr.site.SiteService#listMembers(java.lang.String, java.lang.String, java.lang.String, int)
|
* @see org.alfresco.service.cmr.site.SiteService#listMembers(java.lang.String, java.lang.String, java.lang.String, int)
|
||||||
*/
|
*/
|
||||||
|
@@ -194,6 +194,138 @@ public class SiteServiceImplMoreTest
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* This test ensures that site deleted before MNT-10109 fix (i.e. deleted with their associated authorities) could be restored
|
||||||
|
* with site-groups recreation
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Test public void deleteSiteDeleteAuthoritiesAndRestoreEnsuringSiteGroupsWasRecreated() throws Exception
|
||||||
|
{
|
||||||
|
final String siteShortName = "testsite-" + System.currentTimeMillis();
|
||||||
|
final SiteServiceImpl siteServiceImpl = (SiteServiceImpl)SITE_SERVICE;
|
||||||
|
log.debug("Creating test site called: " + siteShortName);
|
||||||
|
|
||||||
|
// Create site
|
||||||
|
final TestSiteAndMemberInfo testSiteAndMemberInfo =
|
||||||
|
perMethodTestSites.createTestSiteWithUserPerRole(siteShortName, "sitePreset", SiteVisibility.PUBLIC, AuthenticationUtil.getAdminUserName());
|
||||||
|
|
||||||
|
// Delete permissions and site
|
||||||
|
final Map<String, String> membersBefore = TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Map<String, String>>()
|
||||||
|
{
|
||||||
|
public Map<String, String> execute() throws Throwable
|
||||||
|
{
|
||||||
|
NodeRef siteNodeRef = testSiteAndMemberInfo.siteInfo.getNodeRef();
|
||||||
|
|
||||||
|
Map<String, String> membersBefore = SITE_SERVICE.listMembers(siteShortName, null, null, 0, true);
|
||||||
|
log.debug(membersBefore.size() + " members...");
|
||||||
|
for (Map.Entry<String, String> entry : membersBefore.entrySet()) { log.debug(entry); }
|
||||||
|
|
||||||
|
Map<String, Set<String>> groupsMemberships = new HashMap<String, Set<String>>();
|
||||||
|
|
||||||
|
log.debug("About to delete site-related groups.");
|
||||||
|
// delete authorities
|
||||||
|
Set<String> permissions = PERMISSION_SERVICE.getSettablePermissions(SiteModel.TYPE_SITE);
|
||||||
|
for (String permission : permissions)
|
||||||
|
{
|
||||||
|
String prefixSiteRoleGroup = siteServiceImpl.getSiteRoleGroup(siteShortName, permission, true);
|
||||||
|
|
||||||
|
Set<String> groupUsers = AUTHORITY_SERVICE.getContainedAuthorities(null, prefixSiteRoleGroup, true);
|
||||||
|
groupsMemberships.put(prefixSiteRoleGroup, groupUsers);
|
||||||
|
|
||||||
|
AUTHORITY_SERVICE.deleteAuthority(prefixSiteRoleGroup);
|
||||||
|
}
|
||||||
|
//emulate onDelete site behavior before MNT-10109 fix
|
||||||
|
NODE_SERVICE.setProperty(siteNodeRef, QName.createQName(null, "memberships"), (Serializable)groupsMemberships);
|
||||||
|
log.debug("Site-related groups deleted.");
|
||||||
|
|
||||||
|
log.debug("About to delete site.");
|
||||||
|
SITE_SERVICE.deleteSite(siteShortName);
|
||||||
|
log.debug("Site deleted.");
|
||||||
|
|
||||||
|
return membersBefore;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// restore the site
|
||||||
|
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
|
||||||
|
{
|
||||||
|
public Void execute() throws Throwable
|
||||||
|
{
|
||||||
|
assertThatArchivedNodeExists(testSiteAndMemberInfo.siteInfo.getNodeRef(), "Site node not found in archive.");
|
||||||
|
|
||||||
|
// ensure there are no authorities
|
||||||
|
Set<String> permissions = PERMISSION_SERVICE.getSettablePermissions(SiteModel.TYPE_SITE);
|
||||||
|
for (String permission : permissions)
|
||||||
|
{
|
||||||
|
String permissionGroupShortName = siteServiceImpl.getSiteRoleGroup(siteShortName, permission, false);
|
||||||
|
String authorityName = AUTHORITY_SERVICE.getName(AuthorityType.GROUP, permissionGroupShortName);
|
||||||
|
|
||||||
|
assertTrue("Authotiry should not exist : " + authorityName, !AUTHORITY_SERVICE.authorityExists(authorityName));
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("About to restore site node from archive");
|
||||||
|
|
||||||
|
final NodeRef archivedSiteNode = NODE_ARCHIVE_SERVICE.getArchivedNode(testSiteAndMemberInfo.siteInfo.getNodeRef());
|
||||||
|
RestoreNodeReport report = NODE_ARCHIVE_SERVICE.restoreArchivedNode(archivedSiteNode);
|
||||||
|
// ...which should work
|
||||||
|
assertEquals("Failed to restore site from archive", RestoreStatus.SUCCESS, report.getStatus());
|
||||||
|
|
||||||
|
log.debug("Successfully restored site from arhive.");
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Map<String, String>>()
|
||||||
|
{
|
||||||
|
public Map<String, String> execute() throws Throwable
|
||||||
|
{
|
||||||
|
// The site itself should have been restored, of course...
|
||||||
|
assertTrue("The site noderef was not restored as expected", NODE_SERVICE.exists(testSiteAndMemberInfo.siteInfo.getNodeRef()));
|
||||||
|
|
||||||
|
Map<String, String> members = SITE_SERVICE.listMembers(siteShortName, null, null, 0, true);
|
||||||
|
assertEquals("Not all member have been restored", membersBefore.size(), members.size());
|
||||||
|
log.debug(members.size() + " members...");
|
||||||
|
for (Map.Entry<String, String> entry : SITE_SERVICE.listMembers(siteShortName, null, null, 0, true).entrySet()) { log.debug(entry); }
|
||||||
|
|
||||||
|
// Group authority nodes should be restored or recreated
|
||||||
|
for (String role : SITE_SERVICE.getSiteRoles())
|
||||||
|
{
|
||||||
|
final String siteGroup = SITE_SERVICE.getSiteRoleGroup(siteShortName, role);
|
||||||
|
assertTrue("Site group for role " + role + " did not exist after site restoration",
|
||||||
|
AUTHORITY_SERVICE.authorityExists(siteGroup));
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> currentManagers =
|
||||||
|
AUTHORITY_SERVICE.getContainedAuthorities(AuthorityType.USER, siteServiceImpl.getSiteRoleGroup(siteShortName, SiteModel.SITE_MANAGER, true), false);
|
||||||
|
// ensure that there is at least one site manager
|
||||||
|
log.debug("Current Managers " + currentManagers);
|
||||||
|
assertTrue("There should be at least one site manager", !currentManagers.isEmpty());
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove site completely
|
||||||
|
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
|
||||||
|
{
|
||||||
|
public Void execute() throws Throwable
|
||||||
|
{
|
||||||
|
log.debug("About to delete site completely.");
|
||||||
|
SITE_SERVICE.deleteSite(siteShortName);
|
||||||
|
log.debug("About to purge site from trashcan.");
|
||||||
|
|
||||||
|
// get archive node reference
|
||||||
|
String storePath = "archive://SpacesStore";
|
||||||
|
StoreRef storeRef = new StoreRef(storePath);
|
||||||
|
NodeRef archivedNodeRef = new NodeRef(storeRef, testSiteAndMemberInfo.siteInfo.getNodeRef().getId());
|
||||||
|
NODE_ARCHIVE_SERVICE.purgeArchivedNode(archivedNodeRef);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test ensures that when sites are deleted (moved to the trashcan) and then restored, that the 4 role-based groups are
|
* This test ensures that when sites are deleted (moved to the trashcan) and then restored, that the 4 role-based groups are
|
||||||
|
Reference in New Issue
Block a user