use of com.liferay.portal.model.Group 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.Group in project liferay-ide by liferay.
the class UserLocalServiceImpl method updateAsset.
/**
* Updates the user's asset with the new asset categories and tag names,
* removing and adding asset categories and tag names as necessary.
*
* @param userId the primary key of the user
* @param user ID the primary key of the user
* @param assetCategoryIds the primary key's of the new asset categories
* @param assetTagNames the new asset tag names
* @throws PortalException if a user with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public void updateAsset(long userId, User user, long[] assetCategoryIds, String[] assetTagNames) throws PortalException, SystemException {
User owner = userPersistence.findByPrimaryKey(userId);
Company company = companyPersistence.findByPrimaryKey(owner.getCompanyId());
Group companyGroup = company.getGroup();
assetEntryLocalService.updateEntry(userId, companyGroup.getGroupId(), user.getCreateDate(), user.getModifiedDate(), User.class.getName(), user.getUserId(), user.getUuid(), 0, assetCategoryIds, assetTagNames, false, null, null, null, null, user.getFullName(), null, null, null, null, 0, 0, null, false);
}
use of com.liferay.portal.model.Group 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;
}
use of com.liferay.portal.model.Group in project liferay-ide by liferay.
the class LiferayMediaItemService method doUpdateMediaItem.
protected void doUpdateMediaItem(UserId userId, String appId, String albumId, String mediaItemId, MediaItem mediaItem, SecurityToken securityToken) throws Exception {
long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));
User user = UserLocalServiceUtil.getUserById(userIdLong);
if (!ShindigUtil.isValidUser(user)) {
return;
}
Group group = user.getGroup();
long groupIdLong = group.getGroupId();
Http.Options options = new Http.Options();
options.setLocation(mediaItem.getUrl());
byte[] byteArray = HttpUtil.URLtoByteArray(options);
String fileName = getFileName(mediaItem, options);
String contentType = MimeTypesUtil.getContentType(fileName);
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
serviceContext.setAttribute("sourceFileName", fileName);
serviceContext.setExpandoBridgeAttributes(SerializerUtil.toExpandoAttributes(mediaItem, _MEDIA_ITEM_FIELDS, user.getCompanyId(), DLFileEntry.class.getName()));
serviceContext.setScopeGroupId(groupIdLong);
if (mediaItemId == null) {
long albumIdLong = GetterUtil.getLong(albumId);
DLAppServiceUtil.addFileEntry(groupIdLong, albumIdLong, fileName, contentType, mediaItem.getTitle(), mediaItem.getDescription(), StringPool.BLANK, byteArray, serviceContext);
} else {
long mediaItemIdLong = GetterUtil.getLong(mediaItemId);
FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(mediaItemIdLong);
serviceContext.setCreateDate(fileEntry.getCreateDate());
serviceContext.setModifiedDate(fileEntry.getModifiedDate());
DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), fileName, contentType, mediaItem.getTitle(), mediaItem.getDescription(), StringPool.BLANK, false, byteArray, serviceContext);
}
}
use of com.liferay.portal.model.Group in project liferay-ide by liferay.
the class FindKBArticleAction method getCandidateLayouts.
protected List<Layout> getCandidateLayouts(long plid, boolean privateLayout, KBArticle kbArticle) throws Exception {
List<Layout> candidateLayouts = new ArrayList<Layout>();
Group group = GroupLocalServiceUtil.getGroup(kbArticle.getGroupId());
if (group.isLayout()) {
Layout layout = LayoutLocalServiceUtil.getLayout(group.getClassPK());
candidateLayouts.add(layout);
group = layout.getGroup();
}
List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(group.getGroupId(), privateLayout, LayoutConstants.TYPE_PORTLET);
candidateLayouts.addAll(layouts);
Layout layout = LayoutLocalServiceUtil.getLayout(plid);
if ((layout.getGroupId() == kbArticle.getGroupId()) && layout.isTypePortlet()) {
candidateLayouts.remove(layout);
candidateLayouts.add(0, layout);
}
return candidateLayouts;
}
Aggregations