List of usage examples for com.liferay.portal.kernel.test.util RoleTestUtil addResourcePermission
public static void addResourcePermission(String roleName, String resourceName, int scope, String primKey, String actionId) throws Exception
From source file:com.liferay.asset.search.test.AssetSearcherStagingTest.java
License:Open Source License
@Test public void testSiteRolePermissions() throws Exception { Role role = addRole(RoleConstants.TYPE_SITE); String className = "com.liferay.journal.model.JournalArticle"; RoleTestUtil.addResourcePermission(role, className, ResourceConstants.SCOPE_GROUP_TEMPLATE, "0", ActionKeys.VIEW);/*from w w w . ja v a 2 s . c o m*/ User user = addUser(); ServiceTestUtil.setUser(user); addUserGroupRole(user, role); addJournalArticle(); GroupTestUtil.enableLocalStaging(_group); SearchContext searchContext = getSearchContext(); Group stagingGroup = _group.getStagingGroup(); searchContext.setGroupIds(new long[] { stagingGroup.getGroupId() }); searchContext.setUserId(user.getUserId()); QueryConfig queryConfig = searchContext.getQueryConfig(); queryConfig.addSelectedFieldNames(Field.GROUP_ID, Field.STAGING_GROUP); AssetEntryQuery assetEntryQuery = getAssetEntryQuery(className); Hits hits = search(assetEntryQuery, searchContext); Document[] documents = hits.getDocs(); DocumentsAssert.assertCount(hits.toString(), documents, Field.COMPANY_ID, 1); Document document = documents[0]; assertField(document, Field.GROUP_ID, String.valueOf(stagingGroup.getGroupId())); assertField(document, Field.STAGING_GROUP, StringPool.TRUE); }
From source file:com.liferay.document.library.service.test.DLCheckInCheckOutTest.java
License:Open Source License
@Before public void setUp() throws Exception { _group = GroupTestUtil.addGroup();//from ww w. jav a 2 s . c o m RoleTestUtil.addResourcePermission(RoleConstants.POWER_USER, DLFolderConstants.getClassName(), ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID), ActionKeys.ADD_DOCUMENT); RoleTestUtil.addResourcePermission(RoleConstants.GUEST, DLPermission.RESOURCE_NAME, ResourceConstants.SCOPE_GROUP, String.valueOf(_group.getGroupId()), ActionKeys.VIEW); _authorUser = UserTestUtil.addUser("author", _group.getGroupId()); _overriderUser = UserTestUtil.addUser("overrider", _group.getGroupId()); _serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(), 0); _folder = createFolder("CheckInCheckOutTest"); _fileEntry = createFileEntry(_FILE_NAME); }
From source file:com.liferay.document.library.service.test.DLCheckInCheckOutTest.java
License:Open Source License
@Test(expected = FileEntryLockException.MustOwnLock.class) public void testUpdateWithPermissionOverrideCheckout() throws Exception { Role role = RoleTestUtil.addRole("Overrider", RoleConstants.TYPE_REGULAR, DLFileEntryConstants.getClassName(), ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID), ActionKeys.OVERRIDE_CHECKOUT); RoleTestUtil.addResourcePermission(role, DLFileEntryConstants.getClassName(), ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID), ActionKeys.UPDATE);/*from www. j a va 2 s . co m*/ try { UserLocalServiceUtil.setRoleUsers(role.getRoleId(), new long[] { _overriderUser.getUserId() }); FileEntry fileEntry = null; try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_authorUser)) { fileEntry = createFileEntry(StringUtil.randomString()); DLAppServiceUtil.checkOutFileEntry(fileEntry.getFileEntryId(), _serviceContext); } try (ContextUserReplace contextUserReplacer = new ContextUserReplace(_overriderUser)) { updateFileEntry(fileEntry.getFileEntryId()); } } finally { RoleLocalServiceUtil.deleteRole(role.getRoleId()); } }
From source file:com.liferay.document.library.service.test.DLFileVersionTest.java
License:Open Source License
protected void setUpResourcePermission() throws Exception { RoleTestUtil.addResourcePermission(RoleConstants.GUEST, "com.liferay.document.library", ResourceConstants.SCOPE_GROUP, String.valueOf(_group.getGroupId()), ActionKeys.VIEW); }
From source file:com.liferay.social.activity.service.test.SocialActivityServiceTest.java
License:Open Source License
@Before public void setUp() throws Exception { _group = GroupTestUtil.addGroup();//from w w w .j a v a 2 s .c o m _user = UserTestUtil.addUser(); RoleTestUtil.addResourcePermission(RoleConstants.GUEST, DLPermission.RESOURCE_NAME, ResourceConstants.SCOPE_GROUP, String.valueOf(_group.getGroupId()), ActionKeys.VIEW); }
From source file:com.liferay.trash.service.webserver.test.WebServerTrashTest.java
License:Open Source License
@Override public void setUp() throws Exception { super.setUp(); _user = UserTestUtil.addUser(null, group.getGroupId()); String portletId = PortletProviderUtil.getPortletId(TrashEntry.class.getName(), PortletProvider.Action.VIEW); _role = RoleTestUtil.addRole("Trash Admin", RoleConstants.TYPE_REGULAR, portletId, ResourceConstants.SCOPE_COMPANY, String.valueOf(TestPropsValues.getCompanyId()), ActionKeys.ACCESS_IN_CONTROL_PANEL); RoleTestUtil.addResourcePermission(RoleConstants.GUEST, DLPermission.RESOURCE_NAME, ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID), ActionKeys.VIEW);//from w w w. ja v a 2 s. c om }