mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Tweak the Wiki REST API to better handle deleted users, and add an explicit unit test for this (spotted while testing ALF-1156)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31360 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -28,6 +28,7 @@ import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.service.cmr.activities.ActivityService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.NoSuchPersonException;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
@@ -155,17 +156,24 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript
|
||||
}
|
||||
}
|
||||
|
||||
protected Object buildPerson(String username)
|
||||
protected NodeRef personForModel(String username)
|
||||
{
|
||||
if (username == null || username.length() == 0)
|
||||
{
|
||||
// Empty string needed
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
// Will turn into a Script Node needed of the person
|
||||
NodeRef person = personService.getPerson(username);
|
||||
return person;
|
||||
try
|
||||
{
|
||||
// Will turn into a Script Node needed of the person
|
||||
NodeRef person = personService.getPerson(username);
|
||||
return person;
|
||||
}
|
||||
catch(NoSuchPersonException e)
|
||||
{
|
||||
// This is normally caused by the person having been deleted
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected Map<String, Object> renderWikiPage(WikiPageInfo page)
|
||||
@@ -184,11 +192,7 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript
|
||||
res.put("created", page.getCreatedAt());
|
||||
res.put("modified", page.getModifiedAt());
|
||||
|
||||
// FTL needs a script node of the people
|
||||
res.put("createdBy", buildPerson(page.getCreator()));
|
||||
res.put("modifiedBY", buildPerson(page.getModifier()));
|
||||
|
||||
// We want blank instead of null
|
||||
// For most things, we want blank instead of null
|
||||
for (String key : res.keySet())
|
||||
{
|
||||
if (res.get(key) == null)
|
||||
@@ -197,6 +201,11 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript
|
||||
}
|
||||
}
|
||||
|
||||
// FTL needs a script node of the people, or null if unavailable
|
||||
res.put("createdBy", personForModel(page.getCreator()));
|
||||
res.put("modifiedBy", personForModel(page.getModifier()));
|
||||
|
||||
// All done
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@@ -148,13 +148,19 @@ public class WikiRestApiTest extends BaseWebScriptTest
|
||||
siteService.deleteSite(SITE_SHORT_NAME_WIKI);
|
||||
|
||||
// delete the users
|
||||
personService.deletePerson(USER_ONE);
|
||||
if(personService.personExists(USER_ONE))
|
||||
{
|
||||
personService.deletePerson(USER_ONE);
|
||||
}
|
||||
if(this.authenticationService.authenticationExists(USER_ONE))
|
||||
{
|
||||
this.authenticationService.deleteAuthentication(USER_ONE);
|
||||
}
|
||||
|
||||
personService.deletePerson(USER_TWO);
|
||||
if(personService.personExists(USER_TWO))
|
||||
{
|
||||
personService.deletePerson(USER_TWO);
|
||||
}
|
||||
if(this.authenticationService.authenticationExists(USER_TWO))
|
||||
{
|
||||
this.authenticationService.deleteAuthentication(USER_TWO);
|
||||
@@ -782,8 +788,43 @@ public class WikiRestApiTest extends BaseWebScriptTest
|
||||
assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(1).getString("title"));
|
||||
assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(2).getString("title"));
|
||||
// assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(2).getString("title"));
|
||||
|
||||
|
||||
// Change the owner+creator of one of the pages to System, ensure that
|
||||
// this doesn't break anything in the process
|
||||
String pageTwoName = entries.getJSONObject(1).getString("name");
|
||||
WikiPageInfo pageTwo = wikiService.getWikiPage(SITE_SHORT_NAME_WIKI, pageTwoName);
|
||||
nodeService.setProperty(pageTwo.getNodeRef(), ContentModel.PROP_OWNER, AuthenticationUtil.SYSTEM_USER_NAME);
|
||||
nodeService.setProperty(pageTwo.getNodeRef(), ContentModel.PROP_CREATOR, AuthenticationUtil.SYSTEM_USER_NAME);
|
||||
nodeService.setProperty(pageTwo.getNodeRef(), ContentModel.PROP_MODIFIER, AuthenticationUtil.SYSTEM_USER_NAME);
|
||||
|
||||
// Check the listing still works (note - order will have changed)
|
||||
pages = getPages("recentlyModified", null);
|
||||
assertEquals(3, pages.getInt("totalPages"));
|
||||
|
||||
entries = pages.getJSONArray("pages");
|
||||
assertEquals(3, entries.length());
|
||||
assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(0).getString("title"));
|
||||
assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(1).getString("title"));
|
||||
assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(2).getString("title"));
|
||||
|
||||
|
||||
// Delete User Two, who owns the 3rd page, and ensure that this
|
||||
// doesn't break anything
|
||||
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
||||
personService.deletePerson(USER_TWO);
|
||||
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||
|
||||
// Check the listing still works
|
||||
pages = getPages("recentlyModified", null);
|
||||
assertEquals(3, pages.getInt("totalPages"));
|
||||
|
||||
entries = pages.getJSONArray("pages");
|
||||
assertEquals(3, entries.length());
|
||||
assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(0).getString("title"));
|
||||
assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(1).getString("title"));
|
||||
assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(2).getString("title"));
|
||||
|
||||
|
||||
// Now hide the site, and remove the user from it, won't be allowed to see it
|
||||
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
||||
|
Reference in New Issue
Block a user