mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
REPO-1022: MNT-16271 SiteGroups of existing sites are deleted if site of the same name exists in the Trashcan.
- It is not possible to create a site if a same-named site has not been deleted and purged - Before this change came in, there were cases where sites had been created while same-named sites existed in the trashcan - Purging those sites was detrimental to the live sites - Added the workaround and associated test as suggested by Andrea on MNT-16271 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@133079 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.site;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -1229,7 +1229,7 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
|
||||
}, AuthenticationUtil.getAdminUserName());
|
||||
|
||||
// Create a test site
|
||||
String siteShortName = "testUpdateSite";
|
||||
String siteShortName = "testDeleteSite-" + GUID.generate();
|
||||
this.siteService.createSite(TEST_SITE_PRESET, siteShortName, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
|
||||
SiteInfo siteInfo = this.siteService.getSite(siteShortName);
|
||||
assertNotNull(siteInfo);
|
||||
@@ -1258,6 +1258,122 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
|
||||
assertTrue(authorityService.authorityExists(testGroup));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testPurgeSiteSimple()
|
||||
{
|
||||
SiteService smallSiteService = (SiteService)this.applicationContext.getBean("siteService");
|
||||
// Create a test group
|
||||
final String testGroupName = "siteServiceImplTestGroup_" + GUID.generate();
|
||||
String testGroup = AuthenticationUtil.runAs(
|
||||
new AuthenticationUtil.RunAsWork<String>()
|
||||
{
|
||||
public String doWork() throws Exception
|
||||
{
|
||||
return authorityService.createAuthority(AuthorityType.GROUP, testGroupName);
|
||||
}
|
||||
}, AuthenticationUtil.getAdminUserName());
|
||||
|
||||
// Create a test site
|
||||
String siteShortName = "testPurgeSite-" + GUID.generate();
|
||||
this.siteService.createSite(TEST_SITE_PRESET, siteShortName, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
|
||||
SiteInfo siteInfo = this.siteService.getSite(siteShortName);
|
||||
assertNotNull(siteInfo);
|
||||
|
||||
// Add the test group as a member of the site
|
||||
this.siteService.setMembership(siteShortName, testGroup, SiteModel.SITE_CONTRIBUTOR);
|
||||
|
||||
// Delete the site
|
||||
this.siteService.deleteSite(siteShortName);
|
||||
assertNull(this.siteService.getSite(siteShortName));
|
||||
NodeRef archivedNodeRef = nodeArchiveService.getArchivedNode(siteInfo.getNodeRef());
|
||||
assertTrue("Deleted sites can be recovered from the Trash.", nodeService.exists(archivedNodeRef));
|
||||
|
||||
// Commit these site structures
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
// We now do two transactions that will be thrown away to handle the purge use cases
|
||||
|
||||
// Now purge the site.
|
||||
RetryingTransactionCallback<Void> purgeWork = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
// We already check that the authorities remain alive.
|
||||
nodeArchiveService.purgeArchivedNode(archivedNodeRef); // service call starts a new txn
|
||||
|
||||
// Site-related groups should be wiped
|
||||
assertFalse(authorityService.authorityExists(((SiteServiceImpl)smallSiteService).getSiteGroup(siteShortName, true)));
|
||||
assertFalse(authorityService.authorityExists(((SiteServiceImpl) smallSiteService).getSiteGroup(siteShortName)));
|
||||
Set<String> permissions = permissionService.getSettablePermissions(SiteModel.TYPE_SITE);
|
||||
for (String permission : permissions)
|
||||
{
|
||||
String siteRoleGroup = ((SiteServiceImpl)smallSiteService).getSiteRoleGroup(siteShortName, permission, true);
|
||||
assertFalse(authorityService.authorityExists(siteRoleGroup));
|
||||
}
|
||||
|
||||
// Ensure that the added "normal" groups have not been deleted
|
||||
assertTrue(authorityService.authorityExists(testGroup));
|
||||
|
||||
throw new RuntimeException("Expected $$");
|
||||
}
|
||||
};
|
||||
try
|
||||
{
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(purgeWork);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (!e.getMessage().contains("$$"))
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new site and ensure that the purge does NOT wipe out the authorities ... but still works otherwise (MNT-16271)
|
||||
RetryingTransactionCallback<Void> purgeWithExistingWork = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
siteService.createSite(TEST_SITE_PRESET, siteShortName, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
|
||||
|
||||
// We already check that the authorities remain alive.
|
||||
nodeArchiveService.purgeArchivedNode(archivedNodeRef); // service call starts a new txn
|
||||
|
||||
// Site-related groups should still exist
|
||||
assertTrue(authorityService.authorityExists(((SiteServiceImpl)smallSiteService).getSiteGroup(siteShortName, true)));
|
||||
assertTrue(authorityService.authorityExists(((SiteServiceImpl) smallSiteService).getSiteGroup(siteShortName)));
|
||||
Set<String> permissions = permissionService.getSettablePermissions(SiteModel.TYPE_SITE);
|
||||
for (String permission : permissions)
|
||||
{
|
||||
String siteRoleGroup = ((SiteServiceImpl)smallSiteService).getSiteRoleGroup(siteShortName, permission, true);
|
||||
assertTrue(authorityService.authorityExists(siteRoleGroup));
|
||||
}
|
||||
|
||||
// Ensure that the added "normal" groups have not been deleted
|
||||
assertTrue(authorityService.authorityExists(testGroup));
|
||||
|
||||
throw new RuntimeException("Expected $$");
|
||||
}
|
||||
};
|
||||
try
|
||||
{
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(purgeWithExistingWork);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (!e.getMessage().contains("$$"))
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// Start a new transaction to keep Spring's sequencing happy
|
||||
startNewTransaction();
|
||||
}
|
||||
|
||||
public void testIsPublic()
|
||||
{
|
||||
RetryingTransactionCallback<Object> work = new RetryingTransactionCallback<Object>()
|
||||
|
Reference in New Issue
Block a user