use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-repository by Alfresco.
the class SiteServiceImplTest method testContainer.
@Test
public void testContainer() {
// Create a couple of sites as user one
SiteInfo siteInfo = this.siteService.createSite(TEST_SITE_PRESET, "testContainer", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
boolean hasContainer = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component");
assertFalse(hasContainer);
NodeRef container1 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component");
assertNull(container1);
container1 = this.siteService.createContainer(siteInfo.getShortName(), "folder.component", null, null);
assertTrue(this.taggingService.isTagScope(container1));
NodeRef container2 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component");
assertNotNull(container2);
assertTrue(this.taggingService.isTagScope(container2));
assertTrue(container1.equals(container2));
boolean hasContainer2 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component");
assertTrue(hasContainer2);
boolean hasContainer3 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component2");
assertFalse(hasContainer3);
NodeRef container3 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component2");
assertNull(container3);
container3 = this.siteService.createContainer(siteInfo.getShortName(), "folder.component2", null, null);
assertNotNull(container3);
assertTrue(this.taggingService.isTagScope(container3));
assertFalse(container1.equals(container3));
boolean hasContainer4 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component2");
assertTrue(hasContainer4);
boolean hasContainer5 = this.siteService.hasContainer(siteInfo.getShortName(), "folder.component3");
assertFalse(hasContainer5);
NodeRef container5 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component3");
assertNull(container5);
container5 = this.siteService.createContainer(siteInfo.getShortName(), "folder.component3", ContentModel.TYPE_FOLDER, null);
assertNotNull(container5);
NodeRef container6 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component3");
assertNotNull(container6);
container6 = this.siteService.createContainer(siteInfo.getShortName(), "folder.component3", null, null);
assertNotNull(container6);
assertTrue(container5.equals(container6));
assertEquals(ContentModel.TYPE_FOLDER, nodeService.getType(container6));
NodeRef container7 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component3");
assertNotNull(container7);
container7 = this.siteService.createContainer(siteInfo.getShortName(), "folder.component3", ForumModel.TYPE_FORUM, null);
assertNotNull(container7);
assertTrue(container5.equals(container7));
assertEquals(ContentModel.TYPE_FOLDER, nodeService.getType(container7));
NodeRef container8 = this.siteService.getContainer(siteInfo.getShortName(), "folder.component4");
assertNull(container8);
container8 = this.siteService.createContainer(siteInfo.getShortName(), "folder.component4", ForumModel.TYPE_FORUM, null);
assertNotNull(container8);
assertEquals(ForumModel.TYPE_FORUM, nodeService.getType(container8));
try {
boolean noItDoesnt = this.siteService.hasContainer("IDONT_EXISTS", "folder.component2");
fail("Shouldn't get here");
} catch (SiteDoesNotExistException exception) {
// Expected
}
}
use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-repository by Alfresco.
the class SiteServiceImplTest method testETHREEOH_15.
/**
* This method tests that admin and system users can set site membership for a site of which they are not SiteManagers.
*/
@Test
public void testETHREEOH_15() throws Exception {
RetryingTransactionCallback<Object> work = new RetryingTransactionCallback<Object>() {
@Override
public Object execute() throws Throwable {
String mySiteTest = "mySiteTest" + UUID.randomUUID();
SiteInfo siteInfo = siteService.createSite(TEST_SITE_PRESET, mySiteTest, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
checkSiteInfo(siteInfo, TEST_SITE_PRESET, mySiteTest, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
siteService.setMembership(siteInfo.getShortName(), USER_TWO, SiteModel.SITE_MANAGER);
authenticationComponent.setCurrentUser(USER_TWO);
siteService.setMembership(siteInfo.getShortName(), USER_THREE, SiteModel.SITE_CONTRIBUTOR);
siteService.removeMembership(siteInfo.getShortName(), USER_THREE);
authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
siteService.removeMembership(siteInfo.getShortName(), USER_TWO);
authenticationComponent.setSystemUserAsCurrentUser();
siteService.setMembership(siteInfo.getShortName(), USER_THREE, SiteModel.SITE_CONTRIBUTOR);
authenticationComponent.setCurrentUser(USER_THREE);
try {
siteService.setMembership(siteInfo.getShortName(), USER_TWO, SiteModel.SITE_CONTRIBUTOR);
fail("Shouldn't be able to do this cos you don't have permissions");
} catch (Exception exception) {
}
try {
siteService.removeMembership(siteInfo.getShortName(), USER_ONE);
fail("Shouldn't be able to do this cos you don't have permissions");
} catch (Exception exception) {
}
siteService.removeMembership(siteInfo.getShortName(), USER_THREE);
authenticationComponent.setSystemUserAsCurrentUser();
siteService.deleteSite(mySiteTest);
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(work);
}
use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-repository by Alfresco.
the class SiteServiceImplTest method testNonDefaultPublicGroupPermissions.
/**
* ALF-10343 - When the default public group for sites isn't EVERYBODY,
* check that creating and altering sites results in the correct permissions
*/
@Test
public void testNonDefaultPublicGroupPermissions() throws Exception {
// Sanity check the current permissions
assertEquals(PermissionService.ALL_AUTHORITIES, sysAdminParams.getSitePublicGroup());
// Change the public site group
SysAdminParamsImpl sp = new SysAdminParamsImpl();
sp.setSitePublicGroup(groupFour);
siteServiceImpl.setSysAdminParams(sp);
// Create sites of the three types
SiteInfo s1 = this.siteService.createSite(TEST_SITE_PRESET, "SiteTest_priv", "priv", "priv", SiteVisibility.PRIVATE);
SiteInfo s2 = this.siteService.createSite(TEST_SITE_PRESET, "SiteTest_mod", "mod", "mod", SiteVisibility.MODERATED);
SiteInfo s3 = this.siteService.createSite(TEST_SITE_PRESET, "SiteTest_pub", "pub", "pub", SiteVisibility.PUBLIC);
// Check the permissions on them
// Everyone has read permissions only, not Consumer
assertTrue(getAllowedPermissionsMap(s1).get(PermissionService.ALL_AUTHORITIES).contains("ReadPermissions"));
assertTrue(getAllowedPermissionsMap(s2).get(PermissionService.ALL_AUTHORITIES).contains("ReadPermissions"));
assertTrue(getAllowedPermissionsMap(s3).get(PermissionService.ALL_AUTHORITIES).contains("ReadPermissions"));
// On the public + moderated sites, the special group will be a Consumer
assertEquals(null, getAllowedPermissionsMap(s1).get(groupFour));
assertTrue(getAllowedPermissionsMap(s2).get(groupFour).contains(SiteModel.SITE_CONSUMER));
assertTrue(getAllowedPermissionsMap(s3).get(groupFour).contains(SiteModel.SITE_CONSUMER));
// Our current user will be Manager
assertEquals(SiteModel.SITE_MANAGER, siteService.getMembersRole(s1.getShortName(), USER_ONE));
assertEquals(SiteModel.SITE_MANAGER, siteService.getMembersRole(s2.getShortName(), USER_ONE));
assertEquals(SiteModel.SITE_MANAGER, siteService.getMembersRole(s3.getShortName(), USER_ONE));
// Swap the visibilites around, private+moderated -> public, public -> private
s1.setVisibility(SiteVisibility.PUBLIC);
s2.setVisibility(SiteVisibility.PUBLIC);
s3.setVisibility(SiteVisibility.PRIVATE);
siteService.updateSite(s1);
siteService.updateSite(s2);
siteService.updateSite(s3);
// Check the permissions now
// Everyone still has read permissions everywhere, but nothing more
assertTrue(getAllowedPermissionsMap(s1).get(PermissionService.ALL_AUTHORITIES).contains("ReadPermissions"));
assertTrue(getAllowedPermissionsMap(s2).get(PermissionService.ALL_AUTHORITIES).contains("ReadPermissions"));
assertTrue(getAllowedPermissionsMap(s3).get(PermissionService.ALL_AUTHORITIES).contains("ReadPermissions"));
// The site public group has consumer permissions on mod+public
assertTrue(getAllowedPermissionsMap(s1).get(groupFour).contains(SiteModel.SITE_CONSUMER));
assertTrue(getAllowedPermissionsMap(s2).get(groupFour).contains(SiteModel.SITE_CONSUMER));
assertEquals(null, getAllowedPermissionsMap(s3).get(groupFour));
// Our user is still the manager
assertEquals(SiteModel.SITE_MANAGER, siteService.getMembersRole(s1.getShortName(), USER_ONE));
assertEquals(SiteModel.SITE_MANAGER, siteService.getMembersRole(s2.getShortName(), USER_ONE));
assertEquals(SiteModel.SITE_MANAGER, siteService.getMembersRole(s3.getShortName(), USER_ONE));
// Swap them back again
s1.setVisibility(SiteVisibility.PRIVATE);
s2.setVisibility(SiteVisibility.MODERATED);
s3.setVisibility(SiteVisibility.PUBLIC);
siteService.updateSite(s1);
siteService.updateSite(s2);
siteService.updateSite(s3);
// Check the permissions have restored
// Everyone only has read permissions
assertTrue(getAllowedPermissionsMap(s1).get(PermissionService.ALL_AUTHORITIES).contains("ReadPermissions"));
assertTrue(getAllowedPermissionsMap(s2).get(PermissionService.ALL_AUTHORITIES).contains("ReadPermissions"));
assertTrue(getAllowedPermissionsMap(s3).get(PermissionService.ALL_AUTHORITIES).contains("ReadPermissions"));
// The site public group has consumer permissions on mod+public
assertEquals(null, getAllowedPermissionsMap(s1).get(groupFour));
assertTrue(getAllowedPermissionsMap(s2).get(groupFour).contains(SiteModel.SITE_CONSUMER));
assertTrue(getAllowedPermissionsMap(s3).get(groupFour).contains(SiteModel.SITE_CONSUMER));
// Our user is still the manager
assertEquals(SiteModel.SITE_MANAGER, siteService.getMembersRole(s1.getShortName(), USER_ONE));
assertEquals(SiteModel.SITE_MANAGER, siteService.getMembersRole(s2.getShortName(), USER_ONE));
assertEquals(SiteModel.SITE_MANAGER, siteService.getMembersRole(s3.getShortName(), USER_ONE));
}
use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-repository by Alfresco.
the class SiteServiceImplTest method testCustomSiteType.
/**
* Creates a site with a custom type, and ensures that
* it behaves correctly.
*/
@SuppressWarnings("deprecation")
@Test
public void testCustomSiteType() {
final String CS_URI = "http://example.com/site";
final String CS_PFX = "cs";
// Setup our custom site type
DictionaryDAO dictionaryDAO = (DictionaryDAO) this.applicationContext.getBean("dictionaryDAO");
M2Model model = M2Model.createModel("cm:CustomSiteModel");
model.createNamespace(CS_URI, CS_PFX);
// Import the usual suspects too
model.createImport(NamespaceService.CONTENT_MODEL_1_0_URI, NamespaceService.CONTENT_MODEL_PREFIX);
model.createImport(NamespaceService.DICTIONARY_MODEL_1_0_URI, NamespaceService.DICTIONARY_MODEL_PREFIX);
model.createImport(SiteModel.SITE_MODEL_URL, SiteModel.SITE_MODEL_PREFIX);
// Custom type
M2Type customType = model.createType("cs:customSite");
customType.setTitle("customSite");
customType.setParentName(SiteModel.SITE_MODEL_PREFIX + ":" + SiteModel.TYPE_SITE.getLocalName());
M2Property customProp = customType.createProperty("cs:customSiteProp");
customProp.setTitle("customSiteProp");
customProp.setType("d:text");
dictionaryDAO.putModel(model);
// Get our custom type, to check it's in there properly
final QName customTypeQ = QName.createQName("cs", "customSite", namespaceService);
TypeDefinition td = dictionaryService.getType(customTypeQ);
assertNotNull(td);
// Create a site
SiteInfo site = siteService.createSite("custom", "custom", "Custom", "Custom", SiteVisibility.PUBLIC);
// Check the roles on it
List<String> roles = siteService.getSiteRoles();
assertEquals(7, roles.size());
assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONSUMER));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONTRIBUTOR));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_COLLABORATOR));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
roles = siteService.getSiteRoles(site.getShortName());
assertEquals(7, roles.size());
assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONSUMER));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONTRIBUTOR));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_COLLABORATOR));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
// Swap the type
nodeService.setType(site.getNodeRef(), customTypeQ);
// Check again
roles = siteService.getSiteRoles();
assertEquals(7, roles.size());
assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONSUMER));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONTRIBUTOR));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_COLLABORATOR));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
roles = siteService.getSiteRoles(site.getShortName());
assertEquals(7, roles.size());
assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONSUMER));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONTRIBUTOR));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_COLLABORATOR));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
// Alter the permissions for the custom site
PermissionService testPermissionService = spy((PermissionService) this.applicationContext.getBean("permissionServiceImpl"));
Set<String> customPerms = new HashSet<String>();
customPerms.add(SiteServiceImpl.SITE_MANAGER);
customPerms.add("CUSTOM");
when(testPermissionService.getSettablePermissions(customTypeQ)).thenReturn(customPerms);
// Check it changed for the custom site, but not normal
SiteServiceImpl siteServiceImpl = (SiteServiceImpl) this.applicationContext.getBean("siteService");
siteServiceImpl.setPermissionService(testPermissionService);
roles = siteService.getSiteRoles();
assertEquals(7, roles.size());
assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONSUMER));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONTRIBUTOR));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_COLLABORATOR));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
roles = siteService.getSiteRoles(site.getShortName());
assertEquals(2, roles.size());
assertEquals(true, roles.contains("CUSTOM"));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
// Put the permissions back
siteServiceImpl.setPermissionService(permissionService);
roles = siteService.getSiteRoles();
assertEquals(7, roles.size());
assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONSUMER));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONTRIBUTOR));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_COLLABORATOR));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
roles = siteService.getSiteRoles(site.getShortName());
assertEquals(7, roles.size());
assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONSUMER));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONTRIBUTOR));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_COLLABORATOR));
assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
}
use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-repository by Alfresco.
the class InvitationCleanupTest method pendingJoinRequestsToModeratedSitesShouldDisappearOnSiteDeletion.
/**
* See CLOUD-1824 for details on bug & ALF-11872 for details on a related, older bug.
*/
@Test
public void pendingJoinRequestsToModeratedSitesShouldDisappearOnSiteDeletion() throws Exception {
// First, UserOne creates a site - we'll name it after this test method.
final String siteShortName = InvitationCleanupTest.class.getSimpleName() + "-test-site";
TEST_SITES.createSite("sitePreset", siteShortName, "title", "description", SiteVisibility.MODERATED, TEST_USER1.getUsername());
// Now UserTwo makes a request to join the site
AuthenticationUtil.runAs(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
return TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
INVITATION_SERVICE.inviteModerated("Let me in!", TEST_USER2.getUsername(), ResourceType.WEB_SITE, siteShortName, SiteModel.SITE_CONTRIBUTOR);
return null;
}
});
}
}, TEST_USER2.getUsername());
AuthenticationUtil.runAs(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
// Sanity check: UserOne should now have a task assigned to them
assertUserHasTasks(TEST_USER1.getUsername(), 1);
return null;
}
});
NodeRef archivedNodeRef = TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<NodeRef>() {
public NodeRef execute() throws Throwable {
SiteInfo siteInfo = SITE_SERVICE.getSite(siteShortName);
// UserOne ignores the task and instead deletes the site.
SITE_SERVICE.deleteSite(siteShortName);
return NODE_ARCHIVE_SERVICE.getArchivedNode(siteInfo.getNodeRef());
}
});
// Purge deleted site from trashcan so that sitename can be reused
NODE_ARCHIVE_SERVICE.purgeArchivedNode(archivedNodeRef);
// The pending inviations are deleted asynchronously and so we must wait for that deletion to complete.
// TODO Obviously Thread.sleep is not the best way to do this.
Thread.sleep(1000);
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
// UserOne now creates a new site WITH THE SAME NAME.
TEST_SITES.createSite("sitePreset", siteShortName, "title", "description", SiteVisibility.MODERATED, TEST_USER1.getUsername());
return null;
}
});
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
// Now the task should remain unseen/deleted.
assertUserHasTasks(TEST_USER1.getUsername(), 0);
return null;
}
});
return null;
}
}, TEST_USER1.getUsername());
}
Aggregations