use of com.liferay.portal.model.Group in project liferay-ide by liferay.
the class UserLocalServiceImpl method addDefaultGroups.
/**
* Adds the user to the default groups, unless the user is already in these
* groups. The default groups can be specified in
* <code>portal.properties</code> with the key
* <code>admin.default.group.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 addDefaultGroups(long userId) throws PortalException, SystemException {
User user = userPersistence.findByPrimaryKey(userId);
Set<Long> groupIdsSet = new HashSet<Long>();
String[] defaultGroupNames = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_GROUP_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_GROUP_NAMES);
for (String defaultGroupName : defaultGroupNames) {
Company company = companyPersistence.findByPrimaryKey(user.getCompanyId());
Account account = company.getAccount();
if (StringUtil.equalsIgnoreCase(defaultGroupName, account.getName())) {
defaultGroupName = GroupConstants.GUEST;
}
Group group = groupPersistence.fetchByC_N(user.getCompanyId(), defaultGroupName);
if ((group != null) && !userPersistence.containsGroup(userId, group.getGroupId())) {
groupIdsSet.add(group.getGroupId());
}
}
String[] defaultOrganizationGroupNames = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_ORGANIZATION_GROUP_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_ORGANIZATION_GROUP_NAMES);
for (String defaultOrganizationGroupName : defaultOrganizationGroupNames) {
defaultOrganizationGroupName += GroupLocalServiceImpl.ORGANIZATION_NAME_SUFFIX;
Group group = groupPersistence.fetchByC_N(user.getCompanyId(), defaultOrganizationGroupName);
if ((group != null) && !userPersistence.containsGroup(userId, group.getGroupId())) {
groupIdsSet.add(group.getGroupId());
}
}
long[] groupIds = ArrayUtil.toArray(groupIdsSet.toArray(new Long[groupIdsSet.size()]));
groupLocalService.addUserGroups(userId, groupIds);
}
use of com.liferay.portal.model.Group in project liferay-ide by liferay.
the class SearchPermissionCheckerImpl method doGetPermissionQuery.
protected Query doGetPermissionQuery(long companyId, long[] groupIds, long userId, String className, Query query, SearchContext searchContext) throws Exception {
Indexer indexer = IndexerRegistryUtil.getIndexer(className);
if (!indexer.isPermissionAware()) {
return query;
}
PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();
AdvancedPermissionChecker advancedPermissionChecker = null;
if ((permissionChecker != null) && (permissionChecker instanceof AdvancedPermissionChecker)) {
advancedPermissionChecker = (AdvancedPermissionChecker) permissionChecker;
}
if (advancedPermissionChecker == null) {
return query;
}
PermissionCheckerBag permissionCheckerBag = getPermissionCheckerBag(advancedPermissionChecker, userId);
if (permissionCheckerBag == null) {
return query;
}
List<Group> groups = new UniqueList<Group>();
List<Role> roles = new UniqueList<Role>();
List<UserGroupRole> userGroupRoles = new UniqueList<UserGroupRole>();
Map<Long, List<Role>> groupIdsToRoles = new HashMap<Long, List<Role>>();
roles.addAll(permissionCheckerBag.getRoles());
if (ArrayUtil.isEmpty(groupIds)) {
groups.addAll(GroupLocalServiceUtil.getUserGroups(userId, true));
groups.addAll(permissionCheckerBag.getGroups());
userGroupRoles = UserGroupRoleLocalServiceUtil.getUserGroupRoles(userId);
} else {
groups.addAll(permissionCheckerBag.getGroups());
for (long groupId : groupIds) {
if (GroupLocalServiceUtil.hasUserGroup(userId, groupId)) {
Group group = GroupLocalServiceUtil.getGroup(groupId);
groups.add(group);
}
userGroupRoles.addAll(UserGroupRoleLocalServiceUtil.getUserGroupRoles(userId, groupId));
userGroupRoles.addAll(UserGroupRoleLocalServiceUtil.getUserGroupRolesByUserUserGroupAndGroup(userId, groupId));
}
}
if (advancedPermissionChecker.isSignedIn()) {
roles.add(RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST));
}
for (Group group : groups) {
PermissionCheckerBag userBag = advancedPermissionChecker.getUserBag(userId, group.getGroupId());
List<Role> groupRoles = userBag.getRoles();
groupIdsToRoles.put(group.getGroupId(), groupRoles);
roles.addAll(groupRoles);
}
return doGetPermissionQuery_6(companyId, groupIds, userId, className, query, searchContext, advancedPermissionChecker, groups, roles, userGroupRoles, groupIdsToRoles);
}
use of com.liferay.portal.model.Group in project liferay-ide by liferay.
the class SearchPermissionCheckerImpl method doAddPermissionFields_6.
protected void doAddPermissionFields_6(long companyId, long groupId, String className, String classPK, Document doc) throws Exception {
Group group = null;
if (groupId > 0) {
group = GroupLocalServiceUtil.getGroup(groupId);
}
List<Role> roles = ListUtil.copy(ResourceActionsUtil.getRoles(companyId, group, className, null));
if (groupId > 0) {
List<Role> teamRoles = RoleLocalServiceUtil.getTeamRoles(groupId);
roles.addAll(teamRoles);
}
long[] roleIdsArray = new long[roles.size()];
for (int i = 0; i < roleIdsArray.length; i++) {
Role role = roles.get(i);
roleIdsArray[i] = role.getRoleId();
}
boolean[] hasResourcePermissions = null;
if (ResourceBlockLocalServiceUtil.isSupported(className)) {
ResourceBlockIdsBag resourceBlockIdsBag = ResourceBlockLocalServiceUtil.getResourceBlockIdsBag(companyId, groupId, className, roleIdsArray);
long actionId = ResourceBlockLocalServiceUtil.getActionId(className, ActionKeys.VIEW);
List<Long> resourceBlockIds = resourceBlockIdsBag.getResourceBlockIds(actionId);
hasResourcePermissions = new boolean[roleIdsArray.length];
for (long resourceBlockId : resourceBlockIds) {
for (int i = 0; i < roleIdsArray.length; i++) {
int count = ResourceBlockPermissionLocalServiceUtil.getResourceBlockPermissionsCount(resourceBlockId, roleIdsArray[i]);
hasResourcePermissions[i] = (count > 0);
}
}
} else {
hasResourcePermissions = ResourcePermissionLocalServiceUtil.hasResourcePermissions(companyId, className, ResourceConstants.SCOPE_INDIVIDUAL, classPK, roleIdsArray, ActionKeys.VIEW);
}
List<Long> roleIds = new ArrayList<Long>();
List<String> groupRoleIds = new ArrayList<String>();
for (int i = 0; i < hasResourcePermissions.length; i++) {
if (!hasResourcePermissions[i]) {
continue;
}
Role role = roles.get(i);
if ((role.getType() == RoleConstants.TYPE_ORGANIZATION) || (role.getType() == RoleConstants.TYPE_SITE)) {
groupRoleIds.add(groupId + StringPool.DASH + role.getRoleId());
} else {
roleIds.add(role.getRoleId());
}
}
doc.addKeyword(Field.ROLE_ID, roleIds.toArray(new Long[roleIds.size()]));
doc.addKeyword(Field.GROUP_ROLE_ID, groupRoleIds.toArray(new String[groupRoleIds.size()]));
}
use of com.liferay.portal.model.Group in project liferay-ide by liferay.
the class NewPortlet method doView.
@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
long groupId = themeDisplay.getLayout().getGroupId();
try {
Group group = GroupLocalServiceUtil.getGroup(groupId);
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of com.liferay.portal.model.Group in project liferay-ide by liferay.
the class UserLocalServiceImpl method updateGroups.
protected void updateGroups(long userId, long[] newGroupIds, ServiceContext serviceContext, boolean indexingEnabled) throws PortalException, SystemException {
if (newGroupIds == null) {
return;
}
List<Group> oldGroups = userPersistence.getGroups(userId);
Set<Long> oldGroupIds = new HashSet<Long>(oldGroups.size());
for (Group oldGroup : oldGroups) {
long oldGroupId = oldGroup.getGroupId();
oldGroupIds.add(oldGroupId);
if (!ArrayUtil.contains(newGroupIds, oldGroupId)) {
unsetGroupUsers(oldGroupId, new long[] { userId }, serviceContext);
}
}
for (long newGroupId : newGroupIds) {
if (!oldGroupIds.contains(newGroupId)) {
addGroupUsers(newGroupId, new long[] { userId });
}
}
if (indexingEnabled) {
Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
indexer.reindex(new long[] { userId });
}
PermissionCacheUtil.clearCache();
}
Aggregations