use of com.liferay.portal.model.Role in project liferay-ide by liferay.
the class UserLocalServiceImpl method getRoleUsersCount.
/**
* Returns the number of users with the status belonging to the role.
*
* @param roleId the primary key of the role
* @param status the workflow status
* @return the number of users with the status belonging to the role
* @throws PortalException if an role with the primary key could not be
* found
* @throws SystemException if a system exception occurred
*/
@Override
public int getRoleUsersCount(long roleId, int status) throws PortalException, SystemException {
Role role = rolePersistence.findByPrimaryKey(roleId);
LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();
params.put("usersRoles", new Long(roleId));
return searchCount(role.getCompanyId(), null, status, params);
}
use of com.liferay.portal.model.Role in project liferay-ide by liferay.
the class UserLocalServiceImpl method addDefaultRoles.
/**
* Adds the user to the default roles, unless the user already has these
* roles. The default roles can be specified in
* <code>portal.properties</code> with the key
* <code>admin.default.role.names</code>.
*
* @param userId the primary key of the user
* @throws PortalException if a user with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public void addDefaultRoles(long userId) throws PortalException, SystemException {
User user = userPersistence.findByPrimaryKey(userId);
Set<Long> roleIdSet = new HashSet<Long>();
String[] defaultRoleNames = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_ROLE_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_ROLE_NAMES);
for (String defaultRoleName : defaultRoleNames) {
try {
Role role = rolePersistence.findByC_N(user.getCompanyId(), defaultRoleName);
if (!userPersistence.containsRole(userId, role.getRoleId())) {
roleIdSet.add(role.getRoleId());
}
} catch (NoSuchRoleException nsre) {
}
}
long[] roleIds = ArrayUtil.toArray(roleIdSet.toArray(new Long[roleIdSet.size()]));
roleIds = UsersAdminUtil.addRequiredRoles(user, roleIds);
userPersistence.addRoles(userId, roleIds);
}
use of com.liferay.portal.model.Role in project liferay-ide by liferay.
the class UserLocalServiceImpl method unsetRoleUsers.
/**
* Removes the users from the role.
*
* @param roleId the primary key of the role
* @param userIds the primary keys of the users
* @throws PortalException if a portal exception occurred
* @throws SystemException if a system exception occurred
*/
@Override
public void unsetRoleUsers(long roleId, long[] userIds) throws PortalException, SystemException {
Role role = rolePersistence.findByPrimaryKey(roleId);
String roleName = role.getName();
if (roleName.equals(RoleConstants.USER) || (roleName.equals(RoleConstants.ADMINISTRATOR) && getRoleUsersCount(role.getRoleId()) <= 1)) {
return;
}
rolePersistence.removeUsers(roleId, userIds);
Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
indexer.reindex(userIds);
PermissionCacheUtil.clearCache();
}
use of com.liferay.portal.model.Role in project liferay-ide by liferay.
the class UserLocalServiceImpl method addDefaultRolesAndTeams.
protected void addDefaultRolesAndTeams(long groupId, long[] userIds) throws PortalException, SystemException {
List<Role> defaultSiteRoles = new ArrayList<Role>();
Group group = groupLocalService.getGroup(groupId);
UnicodeProperties typeSettingsProperties = group.getTypeSettingsProperties();
long[] defaultSiteRoleIds = StringUtil.split(typeSettingsProperties.getProperty("defaultSiteRoleIds"), 0L);
for (long defaultSiteRoleId : defaultSiteRoleIds) {
Role defaultSiteRole = rolePersistence.fetchByPrimaryKey(defaultSiteRoleId);
if (defaultSiteRole == null) {
if (_log.isWarnEnabled()) {
_log.warn("Unable to find role " + defaultSiteRoleId);
}
continue;
}
defaultSiteRoles.add(defaultSiteRole);
}
List<Team> defaultTeams = new ArrayList<Team>();
long[] defaultTeamIds = StringUtil.split(typeSettingsProperties.getProperty("defaultTeamIds"), 0L);
for (long defaultTeamId : defaultTeamIds) {
Team defaultTeam = teamPersistence.findByPrimaryKey(defaultTeamId);
if (defaultTeam == null) {
if (_log.isWarnEnabled()) {
_log.warn("Unable to find team " + defaultTeamId);
}
continue;
}
defaultTeams.add(defaultTeam);
}
for (long userId : userIds) {
Set<Long> userRoleIdsSet = new HashSet<Long>();
for (Role role : defaultSiteRoles) {
if (!userPersistence.containsRole(userId, role.getRoleId())) {
userRoleIdsSet.add(role.getRoleId());
}
}
long[] userRoleIds = ArrayUtil.toArray(userRoleIdsSet.toArray(new Long[userRoleIdsSet.size()]));
userGroupRoleLocalService.addUserGroupRoles(userId, groupId, userRoleIds);
Set<Long> userTeamIdsSet = new HashSet<Long>();
for (Team team : defaultTeams) {
if (!userPersistence.containsTeam(userId, team.getTeamId())) {
userTeamIdsSet.add(team.getTeamId());
}
}
long[] userTeamIds = ArrayUtil.toArray(userTeamIdsSet.toArray(new Long[userTeamIdsSet.size()]));
userPersistence.addTeams(userId, userTeamIds);
}
}
use of com.liferay.portal.model.Role in project liferay-ide by liferay.
the class SearchPermissionCheckerImpl method doGetPermissionQuery_6.
protected Query doGetPermissionQuery_6(long companyId, long[] groupIds, long userId, String className, Query query, SearchContext searchContext, AdvancedPermissionChecker advancedPermissionChecker, List<Group> groups, List<Role> roles, List<UserGroupRole> userGroupRoles, Map<Long, List<Role>> groupIdsToRoles) throws Exception {
BooleanQuery permissionQuery = BooleanQueryFactoryUtil.create(searchContext);
if (userId > 0) {
permissionQuery.addTerm(Field.USER_ID, userId);
}
BooleanQuery groupsQuery = BooleanQueryFactoryUtil.create(searchContext);
BooleanQuery rolesQuery = BooleanQueryFactoryUtil.create(searchContext);
for (Role role : roles) {
String roleName = role.getName();
if (roleName.equals(RoleConstants.ADMINISTRATOR)) {
return query;
}
if (ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, className, ResourceConstants.SCOPE_COMPANY, String.valueOf(companyId), role.getRoleId(), ActionKeys.VIEW)) {
return query;
}
if ((role.getType() == RoleConstants.TYPE_REGULAR) && ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, className, ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID), role.getRoleId(), ActionKeys.VIEW)) {
return query;
}
for (Group group : groups) {
if (ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, className, ResourceConstants.SCOPE_GROUP, String.valueOf(group.getGroupId()), role.getRoleId(), ActionKeys.VIEW)) {
groupsQuery.addTerm(Field.GROUP_ID, group.getGroupId());
}
if ((role.getType() != RoleConstants.TYPE_REGULAR) && ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, className, ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID), role.getRoleId(), ActionKeys.VIEW)) {
List<Role> groupRoles = groupIdsToRoles.get(group.getGroupId());
if (groupRoles.contains(role)) {
groupsQuery.addTerm(Field.GROUP_ID, group.getGroupId());
}
}
if (group.isSite() && !roleName.equals(RoleConstants.SITE_MEMBER) && (role.getType() == RoleConstants.TYPE_SITE)) {
rolesQuery.addTerm(Field.GROUP_ROLE_ID, group.getGroupId() + StringPool.DASH + role.getRoleId());
}
}
rolesQuery.addTerm(Field.ROLE_ID, role.getRoleId());
}
for (Group group : groups) {
addRequiredMemberRole(group, rolesQuery);
}
for (UserGroupRole userGroupRole : userGroupRoles) {
rolesQuery.addTerm(Field.GROUP_ROLE_ID, userGroupRole.getGroupId() + StringPool.DASH + userGroupRole.getRoleId());
}
if (groupsQuery.hasClauses()) {
permissionQuery.add(groupsQuery, BooleanClauseOccur.SHOULD);
}
if (rolesQuery.hasClauses()) {
permissionQuery.add(rolesQuery, BooleanClauseOccur.SHOULD);
}
BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
fullQuery.add(query, BooleanClauseOccur.MUST);
fullQuery.add(permissionQuery, BooleanClauseOccur.MUST);
return fullQuery;
}
Aggregations