use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-repository by Alfresco.
the class SiteServiceImplTest method testChangeSiteVisibility.
/**
* From MNT-14452, insure that GROUP_EVERYONE have read access to public sites' containers.
*/
@Test
public void testChangeSiteVisibility() {
String siteName = GUID.generate();
// Check Private->public
SiteInfo siteInfo = createSite(siteName, "doclib", SiteVisibility.PRIVATE);
NodeRef container = this.siteService.getContainer(siteInfo.getShortName(), "doclib");
siteInfo.setVisibility(SiteVisibility.PUBLIC);
siteService.updateSite(siteInfo);
assertTrue(getAllowedPermissionsMap(container).get(PermissionService.ALL_AUTHORITIES).contains("ReadPermissions"));
// Check public->moderated
siteInfo.setVisibility(SiteVisibility.MODERATED);
siteService.updateSite(siteInfo);
assertNull("GROUP_EVERYONE shouldn't have any permissions on a moderated site's containers", getAllowedPermissionsMap(container).get(PermissionService.ALL_AUTHORITIES));
// Check moderated->public
siteInfo.setVisibility(SiteVisibility.PUBLIC);
siteService.updateSite(siteInfo);
assertTrue(getAllowedPermissionsMap(container).get(PermissionService.ALL_AUTHORITIES).contains("ReadPermissions"));
// Check public->private
siteInfo.setVisibility(SiteVisibility.PRIVATE);
siteService.updateSite(siteInfo);
assertNull("GROUP_EVERYONE shouldn't have any permissions on a moderated site's containers", getAllowedPermissionsMap(container).get(PermissionService.ALL_AUTHORITIES));
}
use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-repository by Alfresco.
the class SiteServiceImplTest method testSiteVisibility.
/**
* Tests the visibility of a site
*
* See https://issues.alfresco.com/jira/browse/JAWS-291
*/
@Test
public void testSiteVisibility() {
RetryingTransactionCallback<Object> work = new RetryingTransactionCallback<Object>() {
@Override
public Object execute() throws Throwable {
// Create a public site
SiteInfo siteInfo = createTestSiteWithContent("testSiteVisibilityPublicSite", "testComp", SiteVisibility.PUBLIC);
// - is the value on the site nodeRef correct?
assertEquals(SiteVisibility.PUBLIC.toString(), nodeService.getProperty(siteInfo.getNodeRef(), SiteModel.PROP_SITE_VISIBILITY));
// - is the site info correct?
checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityPublicSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
siteInfo = siteService.getSite("testSiteVisibilityPublicSite");
checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityPublicSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
// - are the permissions correct for non-members?
testVisibilityPermissions("Testing visibility of public site", USER_TWO, siteInfo, true, true);
// Create a moderated site
siteInfo = createTestSiteWithContent("testSiteVisibilityModeratedSite", "testComp", SiteVisibility.MODERATED);
// - is the value on the site nodeRef correct?
assertEquals(SiteVisibility.MODERATED.toString(), nodeService.getProperty(siteInfo.getNodeRef(), SiteModel.PROP_SITE_VISIBILITY));
// - is the site info correct?
checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityModeratedSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.MODERATED);
siteInfo = siteService.getSite("testSiteVisibilityModeratedSite");
checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityModeratedSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.MODERATED);
// - are the permissions correct for non-members?
testVisibilityPermissions("Testing visibility of moderated site", USER_TWO, siteInfo, true, false);
// Create a private site
siteInfo = createTestSiteWithContent("testSiteVisibilityPrivateSite", "testComp", SiteVisibility.PRIVATE);
// - is the value on the site nodeRef correct?
assertEquals(SiteVisibility.PRIVATE.toString(), nodeService.getProperty(siteInfo.getNodeRef(), SiteModel.PROP_SITE_VISIBILITY));
// - is the site info correct?
checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityPrivateSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE);
siteInfo = siteService.getSite("testSiteVisibilityPrivateSite");
checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityPrivateSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE);
// - are the permissions correct for non-members?
testVisibilityPermissions("Testing visibility of private site", USER_TWO, siteInfo, false, false);
SiteInfo changeSite = createTestSiteWithContent("testSiteVisibilityChangeSite", "testComp", SiteVisibility.PUBLIC);
// Switch from public -> moderated
changeSite.setVisibility(SiteVisibility.MODERATED);
siteService.updateSite(changeSite);
// - check the updated sites visibility
siteInfo = siteService.getSite("testSiteVisibilityChangeSite");
checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityChangeSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.MODERATED);
testVisibilityPermissions("Testing visibility of moderated site", USER_TWO, siteInfo, true, false);
// Switch from moderated -> private
changeSite.setVisibility(SiteVisibility.PRIVATE);
siteService.updateSite(changeSite);
// - check the updated sites visibility
siteInfo = siteService.getSite("testSiteVisibilityChangeSite");
checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityChangeSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PRIVATE);
testVisibilityPermissions("Testing visibility of moderated site", USER_TWO, siteInfo, false, false);
// Switch from private -> public
changeSite.setVisibility(SiteVisibility.PUBLIC);
siteService.updateSite(changeSite);
// - check the updated sites visibility
siteInfo = siteService.getSite("testSiteVisibilityChangeSite");
checkSiteInfo(siteInfo, TEST_SITE_PRESET, "testSiteVisibilityChangeSite", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
testVisibilityPermissions("Testing visibility of moderated site", USER_TWO, siteInfo, true, true);
authenticationComponent.setSystemUserAsCurrentUser();
siteService.deleteSite("testSiteVisibilityPublicSite");
siteService.deleteSite("testSiteVisibilityModeratedSite");
siteService.deleteSite("testSiteVisibilityPrivateSite");
siteService.deleteSite("testSiteVisibilityChangeSite");
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(work);
}
use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-repository by Alfresco.
the class SiteServiceImplTest method testCreateSite.
/**
* This test method ensures that public sites can be created and that their site info is correct.
* It also tests that a duplicate site cannot be created.
*/
@Test
public void testCreateSite() throws Exception {
// Create a public site
String mySiteTest = "mySiteTest" + UUID.randomUUID();
SiteInfo siteInfo = this.siteService.createSite(TEST_SITE_PRESET, mySiteTest, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
checkSiteInfo(siteInfo, TEST_SITE_PRESET, mySiteTest, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
String name = "!£$%^&*()_+=-[]{}";
// Calls deprecated method (still creates a public Site)
siteInfo = this.siteService.createSite(TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, true);
checkSiteInfo(siteInfo, TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
siteInfo = this.siteService.getSite(name);
checkSiteInfo(siteInfo, TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
name = "éÃóúÃ�ÉÃ�ÓÚ";
siteInfo = this.siteService.createSite(TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
checkSiteInfo(siteInfo, TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
siteInfo = this.siteService.getSite(name);
checkSiteInfo(siteInfo, TEST_SITE_PRESET, name, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
NodeRef siteNodeRef = siteInfo.getNodeRef();
assertEquals(siteInfo.getShortName(), this.siteService.getSiteShortName(siteNodeRef));
// Localize the title and description
Locale locale = Locale.getDefault();
try {
I18NUtil.setLocale(Locale.FRENCH);
nodeService.setProperty(siteNodeRef, ContentModel.PROP_TITLE, "Localized-title");
nodeService.setProperty(siteNodeRef, ContentModel.PROP_DESCRIPTION, "Localized-description");
siteInfo = this.siteService.getSite(name);
checkSiteInfo(siteInfo, TEST_SITE_PRESET, name, "Localized-title", "Localized-description", SiteVisibility.PUBLIC);
} finally {
I18NUtil.setLocale(locale);
}
// Test for duplicate site error
try {
this.siteService.createSite(TEST_SITE_PRESET, mySiteTest, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
fail("Shouldn't allow duplicate site short names.");
} catch (AlfrescoRuntimeException exception) {
// Expected
}
try {
// Create a site with an invalid site type
this.siteService.createSite(TEST_SITE_PRESET, "InvalidSiteType", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC, ServiceRegistry.CMIS_SERVICE);
fail("Shouldn't allow invalid site type.");
} catch (SiteServiceException ssexception) {
// Expected
}
}
use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-repository by Alfresco.
the class SiteServiceImplTest method testConfigurableSitePublicGroup.
/**
* This method tests https://issues.alfresco.com/jira/browse/ALF-3785 which allows 'public' sites
* to be only visible to members of a configured group, by default EVERYONE.
*
* <br><br/>author Neil McErlean
* @since 3.4
*/
@SuppressWarnings("deprecation")
@Test
public void testConfigurableSitePublicGroup() throws Exception {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
// We'll be configuring a JMX managed bean (in this test method only).
ChildApplicationContextFactory sysAdminSubsystem = (ChildApplicationContextFactory) applicationContext.getBean("sysAdmin");
final String sitePublicGroupPropName = "site.public.group";
final String originalSitePublicGroup = "GROUP_EVERYONE";
try {
// Firstly we'll ensure that the site.public.group has the correct (pristine) value.
String groupName = sysAdminSubsystem.getProperty(sitePublicGroupPropName);
assertEquals(sitePublicGroupPropName + " was not the pristine value", originalSitePublicGroup, groupName);
// Create a 'normal', unconfigured site.
SiteInfo unconfiguredSite = siteService.createSite(TEST_SITE_PRESET, "unconfigured", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
assertTrue(containsConsumerPermission(originalSitePublicGroup, unconfiguredSite));
// Now set the managed bean's visibility group to something other than GROUP_EVERYONE.
// This is the group that will have visibility of subsequently created sites.
//
// We'll intentionally set it to a group that DOES NOT EXIST YET.
String newGroupName = this.getClass().getSimpleName() + System.currentTimeMillis();
String prefixedNewGroupName = PermissionService.GROUP_PREFIX + newGroupName;
sysAdminSubsystem.stop();
sysAdminSubsystem.setProperty(sitePublicGroupPropName, prefixedNewGroupName);
sysAdminSubsystem.start();
// Now create a site as before. It should fail as we're using a group that doesn't exist.
boolean expectedExceptionThrown = false;
try {
siteService.createSite(TEST_SITE_PRESET, "thisShouldFail", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
} catch (SiteServiceException expected) {
expectedExceptionThrown = true;
}
if (!expectedExceptionThrown) {
fail("Expected exception on createSite with non-existent group was not thrown.");
}
// Now we'll create the group used above.
authorityService.createAuthority(AuthorityType.GROUP, newGroupName);
// And create the site as before. This time it should succeed.
SiteInfo configuredSite = siteService.createSite(TEST_SITE_PRESET, "configured", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
// And check the permissions on the site.
assertTrue("The configured site should not have " + originalSitePublicGroup + " as SiteContributor", !containsConsumerPermission(originalSitePublicGroup, configuredSite));
assertTrue("The configured site should have (newGroupName) as SiteContributor", containsConsumerPermission(prefixedNewGroupName, configuredSite));
} finally {
// Reset the JMX bean to its out-of-the-box values.
sysAdminSubsystem.stop();
sysAdminSubsystem.setProperty(sitePublicGroupPropName, originalSitePublicGroup);
sysAdminSubsystem.start();
}
}
use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-repository by Alfresco.
the class SiteServiceImplTest method testJSAPI.
// == Test the JavaScript API ==
@Test
public void testJSAPI() throws Exception {
// Create a site with a custom property
SiteInfo siteInfo = this.siteService.createSite(TEST_SITE_PRESET, "mySiteWithCustomProperty", TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
NodeRef siteNodeRef = siteInfo.getNodeRef();
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(1);
properties.put(QName.createQName(SiteModel.SITE_CUSTOM_PROPERTY_URL, "additionalInformation"), "information");
this.nodeService.addAspect(siteNodeRef, QName.createQName(SiteModel.SITE_MODEL_URL, "customSiteProperties"), properties);
// Create a model to pass to the unit test scripts
Map<String, Object> model = new HashMap<String, Object>();
model.put("customSiteName", "mySiteWithCustomProperty");
model.put("preexistingSiteCount", siteService.listSites(null, null).size());
// Execute the unit test script
ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/site/script/test_siteService.js");
this.scriptService.executeScript(location, model);
}
Aggregations