Search in sources :

Example 26 with Group

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);
    }
}
Also used : Role(com.liferay.portal.model.Role) UserGroupRole(com.liferay.portal.model.UserGroupRole) Group(com.liferay.portal.model.Group) UserGroup(com.liferay.portal.model.UserGroup) UnicodeProperties(com.liferay.portal.kernel.util.UnicodeProperties) ArrayList(java.util.ArrayList) Team(com.liferay.portal.model.Team) HashSet(java.util.HashSet)

Example 27 with Group

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);
}
Also used : Group(com.liferay.portal.model.Group) UserGroup(com.liferay.portal.model.UserGroup) Company(com.liferay.portal.model.Company) User(com.liferay.portal.model.User)

Example 28 with Group

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;
}
Also used : UserGroupRole(com.liferay.portal.model.UserGroupRole) Role(com.liferay.portal.model.Role) UserGroupRole(com.liferay.portal.model.UserGroupRole) BooleanQuery(com.liferay.portal.kernel.search.BooleanQuery) Group(com.liferay.portal.model.Group)

Example 29 with Group

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);
    }
}
Also used : Group(com.liferay.portal.model.Group) CollectionOptions(org.apache.shindig.social.opensocial.spi.CollectionOptions) User(com.liferay.portal.model.User) ServiceContext(com.liferay.portal.service.ServiceContext) Http(com.liferay.portal.kernel.util.Http) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Example 30 with Group

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;
}
Also used : Group(com.liferay.portal.model.Group) Layout(com.liferay.portal.model.Layout) ArrayList(java.util.ArrayList)

Aggregations

Group (com.liferay.portal.model.Group)30 User (com.liferay.portal.model.User)15 UserGroup (com.liferay.portal.model.UserGroup)13 ArrayList (java.util.ArrayList)9 UserGroupRole (com.liferay.portal.model.UserGroupRole)6 Role (com.liferay.portal.model.Role)5 Indexer (com.liferay.portal.kernel.search.Indexer)4 Company (com.liferay.portal.model.Company)4 Contact (com.liferay.portal.model.Contact)3 ServiceContext (com.liferay.portal.service.ServiceContext)3 RestfulCollection (org.apache.shindig.protocol.RestfulCollection)3 KBArticle (com.liferay.knowledgebase.model.KBArticle)2 DuplicateUserScreenNameException (com.liferay.portal.DuplicateUserScreenNameException)2 GroupFriendlyURLException (com.liferay.portal.GroupFriendlyURLException)2 NoSuchImageException (com.liferay.portal.NoSuchImageException)2 RequiredUserException (com.liferay.portal.RequiredUserException)2 ReservedUserScreenNameException (com.liferay.portal.ReservedUserScreenNameException)2 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)2 Folder (com.liferay.portal.kernel.repository.model.Folder)2 Organization (com.liferay.portal.model.Organization)2