Merged BRANCHES/DEV/V3.3-BUG-FIX to HEAD:

22237: Fix ALF-3986: decrement original owner usage (if content deleted by a different user)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22339 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2010-09-08 14:04:02 +00:00
parent 81a22de2d3
commit 8143ba5440
2 changed files with 187 additions and 19 deletions

View File

@@ -367,11 +367,16 @@ public class ContentUsageImpl implements ContentUsageService,
long contentSize = contentData.getSize();
// Get owner/creator
String owner = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_OWNER);
String owner = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER); // allow for case where someone else is deleting the node
if (owner == null)
{
owner = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_OWNER);
if ((owner == null) || (owner.equals(OwnableService.NO_OWNER)))
{
owner = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_CREATOR);
}
}
if (contentSize != 0 && owner != null)
{

View File

@@ -65,7 +65,6 @@ public class UserUsageTest extends TestCase
private MutableAuthenticationDao authenticationDAO;
protected NodeRef rootNodeRef;
protected NodeRef systemNodeRef;
protected NodeRef personNodeRef;
protected AuthenticationComponent authenticationComponent;
private UserTransaction testTX;
private TransactionService transactionService;
@@ -77,6 +76,9 @@ public class UserUsageTest extends TestCase
private RepoAdminService repoAdminService;
private static final String TEST_USER = "userUsageTestUser";
private static final String TEST_USER_2 = "userUsageTestUser2";
protected NodeRef personNodeRef;
protected NodeRef personNodeRef2;
private static final QName customType = QName.createQName("{my.new.model}sop"); // from exampleModel.xml
@@ -110,21 +112,8 @@ public class UserUsageTest extends TestCase
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
rootNodeRef = nodeService.getRootNode(storeRef);
// create person
if (personService.personExists(TEST_USER))
{
personService.deletePerson(TEST_USER);
}
Map<QName, Serializable> props = createPersonProperties(TEST_USER);
personNodeRef = personService.createPerson(props);
// create an authentication object e.g. the user
if (authenticationDAO.userExists(TEST_USER))
{
authenticationService.deleteAuthentication(TEST_USER);
}
authenticationService.createAuthentication(TEST_USER, TEST_USER.toCharArray());
// create test users
createTestUsers();
// deploy custom model
InputStream modelStream = getClass().getClassLoader().getResourceAsStream("tenant/exampleModel.xml");
@@ -138,11 +127,45 @@ public class UserUsageTest extends TestCase
testTX.begin();
}
private void createTestUsers()
{
// test user 1
if (personService.personExists(TEST_USER))
{
personService.deletePerson(TEST_USER);
}
Map<QName, Serializable> props = createPersonProperties(TEST_USER);
personNodeRef = personService.createPerson(props);
if (authenticationDAO.userExists(TEST_USER))
{
authenticationService.deleteAuthentication(TEST_USER);
}
authenticationService.createAuthentication(TEST_USER, TEST_USER.toCharArray());
// test user 2
if (personService.personExists(TEST_USER_2))
{
personService.deletePerson(TEST_USER_2);
}
props = createPersonProperties(TEST_USER_2);
personNodeRef2 = personService.createPerson(props);
if (authenticationDAO.userExists(TEST_USER_2))
{
authenticationService.deleteAuthentication(TEST_USER_2);
}
authenticationService.createAuthentication(TEST_USER_2, TEST_USER_2.toCharArray());
}
protected void tearDown() throws Exception
{
try
{
usageService.deleteDeltas(personNodeRef);
usageService.deleteDeltas(personNodeRef2);
testTX.commit();
}
@@ -163,6 +186,12 @@ public class UserUsageTest extends TestCase
assertNotNull(authenticationService.getCurrentUserName());
}
protected void runAsAdmin()
{
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
assertNotNull(authenticationService.getCurrentUserName());
}
private Map<QName, Serializable> createPersonProperties(String userName)
{
HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>();
@@ -746,6 +775,140 @@ public class UserUsageTest extends TestCase
assertEquals(before+44, contentUsageImpl.getUserUsage(ADMIN));
}
public void testCreateDeleteRestoreTwoUsersAcrossTx() throws Exception
{
if(!contentUsageImpl.getEnabled())
{
return;
}
runAs(TEST_USER);
// Create a (shared) folder
Map<QName, Serializable> folderProps = new HashMap<QName, Serializable>(1);
folderProps.put(ContentModel.PROP_NAME, "testFolder");
NodeRef folder = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "testFolder"),
ContentModel.TYPE_FOLDER).getChildRef();
// create some content as the first user
assertEquals(0, contentUsageImpl.getUserUsage(TEST_USER));
NodeRef content1 = addTextContent(folder, "tqbfjotld.txt", "The quick brown fox jumps over the lazy dog");
assertEquals(43, contentUsageImpl.getUserUsage(TEST_USER));
assertEquals(TEST_USER, ownableService.getOwner(content1));
NodeRef content2 = addTextContent(folder, "afdpj.txt", "Amazingly few discotheques provide jukeboxes", true);
assertEquals(87, contentUsageImpl.getUserUsage(TEST_USER));
assertEquals(TEST_USER, ownableService.getOwner(content2));
testTX.commit();
testTX = transactionService.getUserTransaction();
testTX.begin();
runAs(TEST_USER_2);
// create some more content as the second user
assertEquals(0, contentUsageImpl.getUserUsage(TEST_USER_2));
NodeRef content3 = addTextContent(folder, "aqabfweatj.txt", "All questions asked by five watch experts amazed the judge");
assertEquals(58, contentUsageImpl.getUserUsage(TEST_USER_2));
assertEquals(TEST_USER_2, ownableService.getOwner(content3));
testTX.commit();
testTX = transactionService.getUserTransaction();
testTX.begin();
runAs(TEST_USER_2);
assertEquals(87, contentUsageImpl.getUserUsage(TEST_USER));
assertEquals(58, contentUsageImpl.getUserUsage(TEST_USER_2));
// as the second user, delete some content owned by first user
delete(content2);
assertEquals(43, contentUsageImpl.getUserUsage(TEST_USER));
assertEquals(58, contentUsageImpl.getUserUsage(TEST_USER_2));
delete(content1);
assertEquals(0, contentUsageImpl.getUserUsage(TEST_USER));
assertEquals(58, contentUsageImpl.getUserUsage(TEST_USER_2));
testTX.commit();
testTX = transactionService.getUserTransaction();
testTX.begin();
runAs(TEST_USER);
assertEquals(0, contentUsageImpl.getUserUsage(TEST_USER));
assertEquals(58, contentUsageImpl.getUserUsage(TEST_USER_2));
// as the first user, delete some content owned by second user
delete(content3);
assertEquals(0, contentUsageImpl.getUserUsage(TEST_USER));
assertEquals(0, contentUsageImpl.getUserUsage(TEST_USER_2));
// note: via AlfExp non-admin user can only restore what they have deleted
testTX.commit();
testTX = transactionService.getUserTransaction();
testTX.begin();
runAs(TEST_USER_2);
assertEquals(0, contentUsageImpl.getUserUsage(TEST_USER));
assertEquals(0, contentUsageImpl.getUserUsage(TEST_USER_2));
restore(content2);
// note: restore sets owner as the user who deleted the content (not the original owner)
assertEquals(TEST_USER_2, ownableService.getOwner(content2));
assertEquals(0, contentUsageImpl.getUserUsage(TEST_USER));
assertEquals(44, contentUsageImpl.getUserUsage(TEST_USER_2));
testTX.commit();
testTX = transactionService.getUserTransaction();
testTX.begin();
runAs(TEST_USER);
restore(content3);
assertEquals(TEST_USER, ownableService.getOwner(content3));
assertEquals(58, contentUsageImpl.getUserUsage(TEST_USER));
assertEquals(44, contentUsageImpl.getUserUsage(TEST_USER_2));
testTX.commit();
testTX = transactionService.getUserTransaction();
testTX.begin();
runAsAdmin();
restore(content1);
//note: restore sets owner as the user who deleted the content (not the original owner)
assertEquals(TEST_USER_2, ownableService.getOwner(content1));
assertEquals(58, contentUsageImpl.getUserUsage(TEST_USER));
assertEquals(87, contentUsageImpl.getUserUsage(TEST_USER_2));
}
private NodeRef addTextContent(NodeRef folderRef, String name, String textData)
{
return addTextContent(folderRef, name, textData, false);