Example usage for com.liferay.portal.kernel.model ResourceConstants SCOPE_GROUP_TEMPLATE

List of usage examples for com.liferay.portal.kernel.model ResourceConstants SCOPE_GROUP_TEMPLATE

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model ResourceConstants SCOPE_GROUP_TEMPLATE.

Prototype

int SCOPE_GROUP_TEMPLATE

To view the source code for com.liferay.portal.kernel.model ResourceConstants SCOPE_GROUP_TEMPLATE.

Click Source Link

Usage

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  . j  a v a  2s . c om

    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  w  ww.j  ava  2 s  .com*/

    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
public void testCancelCheckoutWithPermissionOverrideCheckout() 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);

    try {/*from  w  ww .  j a  v  a 2 s  . c o  m*/
        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)) {

            DLAppServiceUtil.cancelCheckOut(fileEntry.getFileEntryId());

            fileEntry = DLAppServiceUtil.getFileEntry(fileEntry.getFileEntryId());

            Assert.assertFalse(fileEntry.isCheckedOut());
        }
    } finally {
        RoleLocalServiceUtil.deleteRole(role.getRoleId());
    }
}

From source file:com.liferay.document.library.service.test.DLCheckInCheckOutTest.java

License:Open Source License

@Test(expected = FileEntryLockException.MustOwnLock.class)
public void testCheckInWithPermissionOverrideCheckout() 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);

    try {/* ww w  .  java 2s.  com*/
        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)) {

            DLAppServiceUtil.checkInFileEntry(fileEntry.getFileEntryId(), false, StringPool.NULL,
                    _serviceContext);
        }
    } finally {
        RoleLocalServiceUtil.deleteRole(role.getRoleId());
    }
}

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 w  ww  . ja v a  2  s  .  c o  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.roles.admin.demo.data.creator.internal.SiteRoleDemoDataCreatorImpl.java

License:Open Source License

@Override
public Role create(long companyId, String roleName, String permissionsXML) throws PortalException {

    Role role = createRole(companyId, roleName, RoleConstants.TYPE_SITE);

    if (Validator.isNotNull(permissionsXML)) {
        addPermissions(role, permissionsXML, ResourceConstants.SCOPE_GROUP_TEMPLATE,
                String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID));
    }/*from  ww  w  .j  a  va 2 s  .co  m*/

    return role;
}

From source file:com.liferay.roles.admin.internal.exportimport.data.handler.ImportExportPermissionConversionFilter.java

License:Open Source License

@Override
public boolean accept(Role role, ResourcePermission resourcePermission) {
    int scope = resourcePermission.getScope();

    if ((scope == ResourceConstants.SCOPE_COMPANY) || (scope == ResourceConstants.SCOPE_GROUP_TEMPLATE)) {

        return true;
    } else if (resourcePermission.getScope() == ResourceConstants.SCOPE_GROUP) {

        Group group = GroupLocalServiceUtil.fetchGroup(Long.valueOf(resourcePermission.getPrimKey()));

        if (group.isCompany() || group.isUserPersonalSite()) {
            return true;
        }//from w w  w .  j  a  va2 s  . c  o  m
    }

    return false;
}

From source file:com.liferay.roles.admin.internal.exportimport.data.handler.RoleStagedModelDataHandler.java

License:Open Source License

protected void deleteRolePermissions(PortletDataContext portletDataContext, Role importedRole) {

    List<ResourcePermission> resourcePermissions = _resourcePermissionLocalService.getRoleResourcePermissions(
            importedRole.getRoleId(),/*  w w w. ja  v  a2s .c o  m*/
            new int[] { ResourceConstants.SCOPE_COMPANY, ResourceConstants.SCOPE_GROUP_TEMPLATE },
            QueryUtil.ALL_POS, QueryUtil.ALL_POS);

    for (ResourcePermission resourcePermission : resourcePermissions) {
        _resourcePermissionLocalService.deleteResourcePermission(resourcePermission);
    }

    List<ResourcePermission> groupResourcePermissions = _resourcePermissionLocalService
            .getRoleResourcePermissions(importedRole.getRoleId(), new int[] { ResourceConstants.SCOPE_GROUP },
                    QueryUtil.ALL_POS, QueryUtil.ALL_POS);

    for (ResourcePermission groupResourcePermission : groupResourcePermissions) {

        long groupId = GetterUtil.getLong(groupResourcePermission.getPrimKey());

        if ((groupId == portletDataContext.getCompanyGroupId())
                || (groupId == portletDataContext.getUserPersonalSiteGroupId())) {

            _resourcePermissionLocalService.deleteResourcePermission(groupResourcePermission);
        }
    }
}

From source file:com.liferay.roles.admin.internal.exportimport.data.handler.RoleStagedModelDataHandler.java

License:Open Source License

protected void importResourcePermissions(PortletDataContext portletDataContext, Role importedRole,
        Permission permission) throws PortalException {

    int scope = permission.getScope();

    if (scope == ResourceConstants.SCOPE_COMPANY) {
        _resourcePermissionService.addResourcePermission(portletDataContext.getCompanyGroupId(),
                portletDataContext.getCompanyId(), permission.getName(), scope,
                String.valueOf(portletDataContext.getCompanyId()), importedRole.getRoleId(),
                permission.getActionId());
    } else if (scope == ResourceConstants.SCOPE_GROUP) {
        long groupId = portletDataContext.getCompanyGroupId();

        long primaryKey = groupId;

        long sourceGroupId = GetterUtil.getLong(permission.getPrimKey());

        if (sourceGroupId == portletDataContext.getSourceUserPersonalSiteGroupId()) {

            PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

            User user = permissionChecker.getUser();

            groupId = user.getGroupId();

            primaryKey = portletDataContext.getUserPersonalSiteGroupId();
        }/*from  ww  w .  ja  v  a 2 s  .  co m*/

        _resourcePermissionService.addResourcePermission(groupId, portletDataContext.getCompanyId(),
                permission.getName(), ResourceConstants.SCOPE_GROUP, String.valueOf(primaryKey),
                importedRole.getRoleId(), permission.getActionId());
    } else if (scope == ResourceConstants.SCOPE_GROUP_TEMPLATE) {
        _resourcePermissionService.addResourcePermission(GroupConstants.DEFAULT_PARENT_GROUP_ID,
                portletDataContext.getCompanyId(), permission.getName(), ResourceConstants.SCOPE_GROUP_TEMPLATE,
                String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID), importedRole.getRoleId(),
                permission.getActionId());
    } else {
        if (_log.isDebugEnabled()) {
            _log.debug("Individually scoped permissions are not imported");
        }
    }
}

From source file:com.liferay.roles.admin.web.internal.portlet.RolesAdminPortlet.java

License:Open Source License

public Role editRole(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    long roleId = ParamUtil.getLong(actionRequest, "roleId");

    String name = ParamUtil.getString(actionRequest, "name");
    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title");
    Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest, "description");
    int type = ParamUtil.getInteger(actionRequest, "type", RoleConstants.TYPE_REGULAR);
    String subtype = ParamUtil.getString(actionRequest, "subtype");
    ServiceContext serviceContext = ServiceContextFactory.getInstance(Role.class.getName(), actionRequest);

    if (roleId <= 0) {

        // Add role

        Role role = _roleService.addRole(null, 0, name, titleMap, descriptionMap, type, subtype,
                serviceContext);//ww  w  . j  a  va 2  s .c o  m

        String redirect = ParamUtil.getString(actionRequest, "redirect");

        redirect = _http.setParameter(redirect, actionResponse.getNamespace() + "roleId", role.getRoleId());

        actionRequest.setAttribute(WebKeys.REDIRECT, redirect);

        SessionMessages.add(actionRequest, "roleCreated");

        actionResponse.sendRedirect(redirect);

        return role;
    } else {

        // Update role

        if (name.equals(RoleConstants.SITE_ADMINISTRATOR)) {
            Role role = _roleLocalService.getRole(roleId);
            ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
            boolean manageSubgroups = ParamUtil.getBoolean(actionRequest, "manageSubgroups");

            updateAction(role, themeDisplay.getScopeGroupId(), Group.class.getName(),
                    ActionKeys.MANAGE_SUBGROUPS, manageSubgroups, ResourceConstants.SCOPE_GROUP_TEMPLATE,
                    new String[0]);
        }

        return _roleService.updateRole(roleId, name, titleMap, descriptionMap, subtype, serviceContext);
    }
}