Example usage for com.liferay.portal.kernel.model RoleConstants ADMINISTRATOR

List of usage examples for com.liferay.portal.kernel.model RoleConstants ADMINISTRATOR

Introduction

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

Prototype

String ADMINISTRATOR

To view the source code for com.liferay.portal.kernel.model RoleConstants ADMINISTRATOR.

Click Source Link

Usage

From source file:com.liferay.calendar.internal.upgrade.v1_0_5.UpgradeCalendarResource.java

License:Open Source License

protected long getCompanyAdminUserId(Company company) throws PortalException {

    Role role = RoleLocalServiceUtil.getRole(company.getCompanyId(), RoleConstants.ADMINISTRATOR);

    long[] userIds = UserLocalServiceUtil.getRoleUserIds(role.getRoleId());

    return userIds[0];
}

From source file:com.liferay.calendar.upgrade.v1_0_5.test.UpgradeCalendarResourceTest.java

License:Open Source License

protected void assertUserIsAdministrator(long userId) throws PortalException {

    User user = UserLocalServiceUtil.getUser(userId);

    Assert.assertFalse(user.isDefaultUser());

    Role administratorRole = RoleLocalServiceUtil.getRole(_group.getCompanyId(), RoleConstants.ADMINISTRATOR);

    Assert.assertTrue(RoleLocalServiceUtil.hasUserRole(user.getUserId(), administratorRole.getRoleId()));
}

From source file:com.liferay.flags.internal.messaging.FlagsRequestMessageListener.java

License:Open Source License

protected Set<User> getRecipients(long companyId, long groupId) throws PortalException {

    Set<User> recipients = new LinkedHashSet<>();

    List<String> roleNames = new ArrayList<>();

    Group group = _groupLocalService.getGroup(groupId);

    if (group.isSite()) {
        roleNames.add(RoleConstants.SITE_ADMINISTRATOR);
        roleNames.add(RoleConstants.SITE_OWNER);
    }//from w w  w  . ja v  a2 s  .c o  m

    if (group.isCompany()) {
        roleNames.add(RoleConstants.ADMINISTRATOR);
    } else if (group.isOrganization()) {
        roleNames.add(RoleConstants.ORGANIZATION_ADMINISTRATOR);
        roleNames.add(RoleConstants.ORGANIZATION_OWNER);
    }

    for (String roleName : roleNames) {
        Role role = _roleLocalService.getRole(companyId, roleName);

        List<UserGroupRole> userGroupRoles = _userGroupRoleLocalService.getUserGroupRolesByGroupAndRole(groupId,
                role.getRoleId());

        for (UserGroupRole userGroupRole : userGroupRoles) {
            recipients.add(userGroupRole.getUser());
        }
    }

    if (recipients.isEmpty()) {
        Role role = _roleLocalService.getRole(companyId, RoleConstants.ADMINISTRATOR);

        recipients.addAll(_userLocalService.getRoleUsers(role.getRoleId()));
    }

    return recipients;
}

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

License:Open Source License

public void deletePermission(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long roleId = ParamUtil.getLong(actionRequest, "roleId");
    String name = ParamUtil.getString(actionRequest, "name");
    int scope = ParamUtil.getInteger(actionRequest, "scope");
    String primKey = ParamUtil.getString(actionRequest, "primKey");
    String actionId = ParamUtil.getString(actionRequest, "actionId");

    Role role = _roleLocalService.getRole(roleId);

    String roleName = role.getName();

    if (roleName.equals(RoleConstants.ADMINISTRATOR)
            || roleName.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR)
            || roleName.equals(RoleConstants.ORGANIZATION_OWNER) || roleName.equals(RoleConstants.OWNER)
            || roleName.equals(RoleConstants.SITE_ADMINISTRATOR) || roleName.equals(RoleConstants.SITE_OWNER)) {

        throw new RolePermissionsException(roleName);
    }/*w  ww .  j  a  v  a 2s  .  c o m*/

    _resourcePermissionService.removeResourcePermission(themeDisplay.getScopeGroupId(),
            themeDisplay.getCompanyId(), name, scope, primKey, roleId, actionId);

    // Send redirect

    SessionMessages.add(actionRequest, "permissionDeleted");

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

    if (Validator.isNotNull(redirect)) {
        actionResponse.sendRedirect(redirect);
    }
}

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

License:Open Source License

public void updateActions(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

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

    Role role = _roleLocalService.getRole(roleId);

    String roleName = role.getName();

    if (roleName.equals(RoleConstants.ADMINISTRATOR)
            || roleName.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR)
            || roleName.equals(RoleConstants.ORGANIZATION_OWNER) || roleName.equals(RoleConstants.OWNER)
            || roleName.equals(RoleConstants.SITE_ADMINISTRATOR) || roleName.equals(RoleConstants.SITE_OWNER)) {

        throw new RolePermissionsException(roleName);
    }/*from   w w  w.j  a  v  a2s.  c o  m*/

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");
    String[] relatedPortletResources = StringUtil
            .split(ParamUtil.getString(actionRequest, "relatedPortletResources"));
    String[] modelResources = StringUtil.split(ParamUtil.getString(actionRequest, "modelResources"));

    Map<String, List<String>> resourceActionsMap = new HashMap<>();

    if (Validator.isNotNull(portletResource)) {
        resourceActionsMap.put(portletResource, ResourceActionsUtil.getResourceActions(portletResource, null));
    }

    for (String relatedPortletResource : relatedPortletResources) {
        resourceActionsMap.put(relatedPortletResource,
                ResourceActionsUtil.getResourceActions(relatedPortletResource, null));
    }

    for (String modelResource : modelResources) {
        resourceActionsMap.put(modelResource, ResourceActionsUtil.getResourceActions(null, modelResource));
    }

    int rootResourceScope = ResourceConstants.SCOPE_COMPANY;
    String[] rootResourceGroupIds = null;

    String[] selectedTargets = StringUtil.split(ParamUtil.getString(actionRequest, "selectedTargets"));
    String[] unselectedTargets = StringUtil.split(ParamUtil.getString(actionRequest, "unselectedTargets"));

    for (Map.Entry<String, List<String>> entry : resourceActionsMap.entrySet()) {

        String selResource = entry.getKey();
        List<String> actions = entry.getValue();

        actions = ListUtil.sort(actions, new ActionComparator(themeDisplay.getLocale()));

        for (String actionId : actions) {
            String target = selResource + actionId;

            boolean selected = ArrayUtil.contains(selectedTargets, target);

            if (!selected && !ArrayUtil.contains(unselectedTargets, target)) {

                continue;
            }

            String[] groupIds = StringUtil.split(ParamUtil.getString(actionRequest, "groupIds" + target));

            groupIds = ArrayUtil.distinct(groupIds);

            int scope = ResourceConstants.SCOPE_COMPANY;

            if ((role.getType() == RoleConstants.TYPE_ORGANIZATION)
                    || (role.getType() == RoleConstants.TYPE_PROVIDER)
                    || (role.getType() == RoleConstants.TYPE_SITE)) {

                scope = ResourceConstants.SCOPE_GROUP_TEMPLATE;
            } else {
                if (groupIds.length > 0) {
                    scope = ResourceConstants.SCOPE_GROUP;
                }
            }

            updateAction(role, themeDisplay.getScopeGroupId(), selResource, actionId, selected, scope,
                    groupIds);

            if (selected && actionId.equals(ActionKeys.ACCESS_IN_CONTROL_PANEL)) {

                updateViewControlPanelPermission(role, themeDisplay.getScopeGroupId(), selResource, scope,
                        groupIds);

                rootResourceScope = scope;
                rootResourceGroupIds = groupIds;
            }
        }
    }

    // LPS-38031

    if (rootResourceGroupIds != null) {
        updateViewRootResourcePermission(role, themeDisplay.getScopeGroupId(), portletResource,
                rootResourceScope, rootResourceGroupIds);
    }

    // Send redirect

    SessionMessages.add(actionRequest, "permissionsUpdated");

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

    if (Validator.isNotNull(redirect)) {
        actionResponse.sendRedirect(redirect);
    }
}

From source file:com.liferay.users.admin.demo.data.creator.internal.CompanyAdminUserDemoDataCreatorImpl.java

License:Open Source License

@Override
public User create(long companyId, String emailAddress) throws PortalException {

    User user = createUser(companyId, emailAddress);

    Role role = _roleLocalService.getRole(companyId, RoleConstants.ADMINISTRATOR);

    userLocalService.addRoleUser(role.getRoleId(), user);

    return userLocalService.getUser(user.getUserId());
}