protected void assertLinksToLayouts(String content, Layout layout, long groupId) { StringBundler sb = new StringBundler(); sb.append(StringPool.OPEN_BRACKET); sb.append(layout.getLayoutId()); sb.append(CharPool.AT); Group group = GroupLocalServiceUtil.fetchGroup(groupId); if (layout.isPrivateLayout()) { if (group == null) { sb.append("private"); } else if (group.isUser()) { sb.append("private-user"); } else { sb.append("private-group"); } } else { sb.append("public"); } sb.append(CharPool.AT); sb.append(layout.getPlid()); if (group != null) { sb.append(CharPool.AT); sb.append(String.valueOf(groupId)); } sb.append(StringPool.CLOSE_BRACKET); Assert.assertTrue(content.contains(sb.toString())); }
/** * Returns the default role for the group with the primary key. * * <p>If the group is a site, then the default role is {@link * com.liferay.portal.model.RoleConstants#SITE_MEMBER}. If the group is an organization, then the * default role is {@link com.liferay.portal.model.RoleConstants#ORGANIZATION_USER}. If the group * is a user or user group, then the default role is {@link * com.liferay.portal.model.RoleConstants#POWER_USER}. For all other group types, the default role * is {@link com.liferay.portal.model.RoleConstants#USER}. * * @param groupId the primary key of the group * @return the default role for the group with the primary key * @throws PortalException if a group with the primary key could not be found, or if a default * role could not be found for the group * @throws SystemException if a system exception occurred */ public Role getDefaultGroupRole(long groupId) throws PortalException, SystemException { Group group = groupPersistence.findByPrimaryKey(groupId); if (group.isLayout()) { Layout layout = layoutLocalService.getLayout(group.getClassPK()); group = layout.getGroup(); } if (group.isStagingGroup()) { group = group.getLiveGroup(); } Role role = null; if (group.isCompany()) { role = getRole(group.getCompanyId(), RoleConstants.USER); } else if (group.isLayoutPrototype() || group.isLayoutSetPrototype() || group.isRegularSite() || group.isSite()) { role = getRole(group.getCompanyId(), RoleConstants.SITE_MEMBER); } else if (group.isOrganization()) { role = getRole(group.getCompanyId(), RoleConstants.ORGANIZATION_USER); } else if (group.isUser() || group.isUserGroup()) { role = getRole(group.getCompanyId(), RoleConstants.POWER_USER); } else { role = getRole(group.getCompanyId(), RoleConstants.USER); } return role; }
protected int[] getRoleTypes(long companyId, Group group, String modelResource) { int[] types = RoleConstants.TYPES_REGULAR_AND_SITE; if (isPortalModelResource(modelResource)) { if (modelResource.equals(Organization.class.getName()) || modelResource.equals(User.class.getName())) { types = RoleConstants.TYPES_ORGANIZATION_AND_REGULAR; } else { types = RoleConstants.TYPES_REGULAR; } } else { if (group != null) { if (group.isLayout()) { try { group = GroupServiceUtil.getGroup(group.getParentGroupId()); } catch (Exception e) { } } if (group.isOrganization()) { types = RoleConstants.TYPES_ORGANIZATION_AND_REGULAR_AND_SITE; } else if (group.isUser()) { types = RoleConstants.TYPES_REGULAR; } } } return types; }
protected void initNewLayoutPermissions( long companyId, long groupId, long userId, Layout layout, Layout importedLayout, boolean privateLayout) throws Exception { boolean addGroupPermissions = true; Group group = importedLayout.getGroup(); if (privateLayout && group.isUser()) { addGroupPermissions = false; } boolean addGuestPermissions = false; if (!privateLayout || layout.isTypeControlPanel()) { addGuestPermissions = true; } _resourceLocalService.addResources( companyId, groupId, userId, Layout.class.getName(), importedLayout.getPlid(), false, addGroupPermissions, addGuestPermissions); }
protected String[] getStaticPortletIds(String position) throws PortalException { Layout layout = getLayout(); String selector1 = StringPool.BLANK; Group group = layout.getGroup(); if (group.isUser()) { selector1 = LayoutTypePortletConstants.STATIC_PORTLET_USER_SELECTOR; } else if (group.isOrganization()) { selector1 = LayoutTypePortletConstants.STATIC_PORTLET_ORGANIZATION_SELECTOR; } else if (group.isRegularSite()) { selector1 = LayoutTypePortletConstants.STATIC_PORTLET_REGULAR_SITE_SELECTOR; } String selector2 = layout.getFriendlyURL(); String[] portletIds = PropsUtil.getArray(position, new Filter(selector1, selector2)); for (int i = 0; i < portletIds.length; i++) { portletIds[i] = JS.getSafeName(portletIds[i]); } return portletIds; }
private void _buildParentGroupsBreadcrumb( LayoutSet layoutSet, PortletURL portletURL, ThemeDisplay themeDisplay, StringBundler sb) throws Exception { Group group = layoutSet.getGroup(); if (group.isOrganization()) { Organization organization = OrganizationLocalServiceUtil.getOrganization(group.getOrganizationId()); Organization parentOrganization = organization.getParentOrganization(); if (parentOrganization != null) { Group parentGroup = parentOrganization.getGroup(); LayoutSet parentLayoutSet = LayoutSetLocalServiceUtil.getLayoutSet( parentGroup.getGroupId(), layoutSet.isPrivateLayout()); _buildParentGroupsBreadcrumb(parentLayoutSet, portletURL, themeDisplay, sb); } } else if (group.isUser()) { User groupUser = UserLocalServiceUtil.getUser(group.getClassPK()); List<Organization> organizations = OrganizationLocalServiceUtil.getUserOrganizations(groupUser.getUserId(), true); if (!organizations.isEmpty()) { Organization organization = organizations.get(0); Group parentGroup = organization.getGroup(); LayoutSet parentLayoutSet = LayoutSetLocalServiceUtil.getLayoutSet( parentGroup.getGroupId(), layoutSet.isPrivateLayout()); _buildParentGroupsBreadcrumb(parentLayoutSet, portletURL, themeDisplay, sb); } } int layoutsPageCount = 0; if (layoutSet.isPrivateLayout()) { layoutsPageCount = group.getPrivateLayoutsPageCount(); } else { layoutsPageCount = group.getPublicLayoutsPageCount(); } if ((layoutsPageCount > 0) && !group.getName().equals(GroupConstants.GUEST)) { String layoutSetFriendlyURL = PortalUtil.getLayoutSetFriendlyURL(layoutSet, themeDisplay); sb.append("<li><span><a href=\""); sb.append(layoutSetFriendlyURL); sb.append("\">"); sb.append(HtmlUtil.escape(group.getDescriptiveName())); sb.append("</a></span></li>"); } }
protected boolean isMergeComplete(Method method, Object[] arguments, Group group) { if (MergeLayoutPrototypesThreadLocal.isMergeComplete(method, arguments) && (!group.isUser() || PropsValues.USER_GROUPS_COPY_LAYOUTS_TO_USER_PERSONAL_SITE)) { return true; } else { return false; } }
public static String getOwnerId(Layout layout) throws PortalException, SystemException { Group group = layout.getGroup(); long classPK = group.getClassPK(); String ownerId = "G-" + classPK; if (group.isUser()) { ownerId = String.valueOf(classPK); } return ownerId; }
protected CalendarResource getCalendarResource(long companyId, long groupId) throws PortalException, SystemException { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); long userId = UserLocalServiceUtil.getDefaultUserId(companyId); serviceContext.setUserId(userId); Group group = groupLocalService.getGroup(groupId); if (group.isUser()) { return CalendarResourceUtil.getUserCalendarResource(group.getCreatorUserId(), serviceContext); } return CalendarResourceUtil.getGroupCalendarResource(groupId, serviceContext); }
protected List<SocialActivity> getSocialActivities(ResourceRequest resourceRequest, int max) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); Group group = _groupLocalService.getGroup(themeDisplay.getScopeGroupId()); int start = 0; if (group.isOrganization()) { return _socialActivityLocalService.getOrganizationActivities( group.getOrganizationId(), start, max); } else if (group.isRegularSite()) { return _socialActivityLocalService.getGroupActivities(group.getGroupId(), start, max); } else if (group.isUser()) { return _socialActivityLocalService.getUserActivities(group.getClassPK(), start, max); } return Collections.emptyList(); }
@Override public SyncDLObject addFolder( long repositoryId, long parentFolderId, String name, String description, ServiceContext serviceContext) throws PortalException { try { Group group = groupLocalService.getGroup(repositoryId); SyncUtil.checkSyncEnabled(group.getGroupId()); if (!group.isUser() && (serviceContext.getGroupPermissions() == null)) { SyncUtil.setFilePermissions(group, true, serviceContext); } Folder folder = dlAppService.addFolder(repositoryId, parentFolderId, name, description, serviceContext); return toSyncDLObject(folder, SyncConstants.EVENT_ADD); } catch (PortalException pe) { if (pe instanceof DuplicateFolderNameException) { if (GetterUtil.getBoolean(serviceContext.getAttribute("overwrite"))) { Folder folder = dlAppService.getFolder(repositoryId, parentFolderId, name); folder = dlAppService.updateFolder(folder.getFolderId(), name, description, serviceContext); return toSyncDLObject(folder, SyncConstants.EVENT_UPDATE); } } throw new PortalException(SyncUtil.buildExceptionMessage(pe), pe); } }
public void updateSummary(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); if (!themeDisplay.isSignedIn()) { return; } Group group = _groupLocalService.getGroup(themeDisplay.getScopeGroupId()); User user = null; if (group.isUser()) { user = _userLocalService.getUserById(group.getClassPK()); } else { return; } if (!UserPermissionUtil.contains( themeDisplay.getPermissionChecker(), user.getUserId(), ActionKeys.UPDATE)) { return; } String jobTitle = ParamUtil.getString(actionRequest, "jobTitle"); _userLocalService.updateJobTitle(user.getUserId(), jobTitle); String aboutMe = ParamUtil.getString(actionRequest, "aboutMe"); _expandoValueLocalService.addValue( themeDisplay.getCompanyId(), User.class.getName(), "SN", "aboutMe", user.getUserId(), aboutMe); }
protected boolean isViewableGroup( PermissionChecker permissionChecker, Layout layout, String controlPanelCategory, boolean checkResourcePermission) throws PortalException, SystemException { Group group = GroupLocalServiceUtil.getGroup(layout.getGroupId()); // Inactive sites are not viewable if (!group.isActive()) { return false; } else if (group.isStagingGroup()) { Group liveGroup = group.getLiveGroup(); if (!liveGroup.isActive()) { return false; } } // User private layouts are only viewable by the user and anyone who can // update the user. The user must also be active. if (group.isUser()) { long groupUserId = group.getClassPK(); if (groupUserId == permissionChecker.getUserId()) { return true; } User groupUser = UserLocalServiceUtil.getUserById(groupUserId); if (!groupUser.isActive()) { return false; } if (layout.isPrivateLayout()) { if (GroupPermissionUtil.contains( permissionChecker, groupUser.getGroupId(), ActionKeys.MANAGE_LAYOUTS) || UserPermissionUtil.contains( permissionChecker, groupUserId, groupUser.getOrganizationIds(), ActionKeys.UPDATE)) { return true; } return false; } } // If the current group is staging, only users with editorial rights // can access it if (group.isStagingGroup()) { if (GroupPermissionUtil.contains( permissionChecker, group.getGroupId(), ActionKeys.VIEW_STAGING)) { return true; } return false; } // Control panel layouts are only viewable by authenticated users if (group.isControlPanel()) { if (!permissionChecker.isSignedIn()) { return false; } if (PortalPermissionUtil.contains(permissionChecker, ActionKeys.VIEW_CONTROL_PANEL)) { return true; } if (Validator.isNotNull(controlPanelCategory)) { return true; } return false; } // Site layouts are only viewable by users who are members of the site // or by users who can update the site if (group.isSite()) { if (GroupPermissionUtil.contains( permissionChecker, group.getGroupId(), ActionKeys.MANAGE_LAYOUTS) || GroupPermissionUtil.contains( permissionChecker, group.getGroupId(), ActionKeys.UPDATE)) { return true; } if (layout.isPrivateLayout() && !permissionChecker.isGroupMember(group.getGroupId())) { return false; } } // Organization site layouts are also viewable by users who belong to // the organization or by users who can update organization if (group.isCompany()) { return false; } else if (group.isLayoutPrototype()) { if (LayoutPrototypePermissionUtil.contains( permissionChecker, group.getClassPK(), ActionKeys.VIEW)) { return true; } return false; } else if (group.isLayoutSetPrototype()) { if (LayoutSetPrototypePermissionUtil.contains( permissionChecker, group.getClassPK(), ActionKeys.VIEW)) { return true; } return false; } else if (group.isOrganization()) { long organizationId = group.getOrganizationId(); if (OrganizationLocalServiceUtil.hasUserOrganization( permissionChecker.getUserId(), organizationId, false, false)) { return true; } else if (OrganizationPermissionUtil.contains( permissionChecker, organizationId, ActionKeys.UPDATE)) { return true; } if (!PropsValues.ORGANIZATIONS_MEMBERSHIP_STRICT) { List<Organization> userOrgs = OrganizationLocalServiceUtil.getUserOrganizations(permissionChecker.getUserId()); for (Organization organization : userOrgs) { for (Organization ancestorOrganization : organization.getAncestors()) { if (organizationId == ancestorOrganization.getOrganizationId()) { return true; } } } } } else if (group.isUserGroup()) { if (UserGroupPermissionUtil.contains( permissionChecker, group.getClassPK(), ActionKeys.UPDATE)) { return true; } } // Only check the actual Layout if all of the above failed if (containsWithoutViewableGroup( permissionChecker, layout, controlPanelCategory, ActionKeys.VIEW)) { return true; } // As a last resort, check if any top level pages are viewable by the // user List<Layout> layouts = LayoutLocalServiceUtil.getLayouts( layout.getGroupId(), layout.isPrivateLayout(), LayoutConstants.DEFAULT_PARENT_LAYOUT_ID); for (Layout curLayout : layouts) { if (!curLayout.isHidden() && containsWithoutViewableGroup( permissionChecker, curLayout, controlPanelCategory, ActionKeys.VIEW)) { return true; } } return false; }
protected void importLayout( PortletDataContext portletDataContext, User user, LayoutCache layoutCache, List<Layout> previousLayouts, List<Layout> newLayouts, Map<Long, Layout> newLayoutsMap, Set<Long> newLayoutIds, String portletsMergeMode, String themeId, String colorSchemeId, String layoutsImportMode, boolean privateLayout, boolean importPermissions, boolean importPublicLayoutPermissions, boolean importUserPermissions, boolean importThemeSettings, Element rootElement, Element layoutElement) throws Exception { long groupId = portletDataContext.getGroupId(); String layoutUuid = GetterUtil.getString(layoutElement.attributeValue("layout-uuid")); long layoutId = GetterUtil.getInteger(layoutElement.attributeValue("layout-id")); long oldLayoutId = layoutId; boolean deleteLayout = GetterUtil.getBoolean(layoutElement.attributeValue("delete")); if (deleteLayout) { Layout layout = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(layoutUuid, groupId); if (layout != null) { newLayoutsMap.put(oldLayoutId, layout); ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); LayoutLocalServiceUtil.deleteLayout(layout, false, serviceContext); } return; } String path = layoutElement.attributeValue("path"); if (!portletDataContext.isPathNotProcessed(path)) { return; } Layout layout = (Layout) portletDataContext.getZipEntryAsObject(path); Layout existingLayout = null; Layout importedLayout = null; String friendlyURL = layout.getFriendlyURL(); if (layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_ADD_AS_NEW)) { layoutId = LayoutLocalServiceUtil.getNextLayoutId(groupId, privateLayout); friendlyURL = StringPool.SLASH + layoutId; } else if (layoutsImportMode.equals( PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_NAME)) { Locale locale = LocaleUtil.getDefault(); String localizedName = layout.getName(locale); for (Layout curLayout : previousLayouts) { if (localizedName.equals(curLayout.getName(locale)) || friendlyURL.equals(curLayout.getFriendlyURL())) { existingLayout = curLayout; break; } } if (existingLayout == null) { layoutId = LayoutLocalServiceUtil.getNextLayoutId(groupId, privateLayout); } } else if (layoutsImportMode.equals( PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) { existingLayout = LayoutUtil.fetchByG_P_SPLU(groupId, privateLayout, layout.getUuid()); if (SitesUtil.isLayoutModifiedSinceLastMerge(existingLayout)) { newLayoutsMap.put(oldLayoutId, existingLayout); return; } } else { // The default behaviour of import mode is // PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_UUID existingLayout = LayoutUtil.fetchByUUID_G(layout.getUuid(), groupId); if (existingLayout == null) { existingLayout = LayoutUtil.fetchByG_P_F(groupId, privateLayout, friendlyURL); } if (existingLayout == null) { layoutId = LayoutLocalServiceUtil.getNextLayoutId(groupId, privateLayout); } } if (_log.isDebugEnabled()) { if (existingLayout == null) { _log.debug( "Layout with {groupId=" + groupId + ",privateLayout=" + privateLayout + ",layoutId=" + layoutId + "} does not exist"); } else { _log.debug( "Layout with {groupId=" + groupId + ",privateLayout=" + privateLayout + ",layoutId=" + layoutId + "} exists"); } } if (existingLayout == null) { long plid = CounterLocalServiceUtil.increment(); importedLayout = LayoutUtil.create(plid); if (layoutsImportMode.equals( PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) { importedLayout.setSourcePrototypeLayoutUuid(layout.getUuid()); layoutId = LayoutLocalServiceUtil.getNextLayoutId(groupId, privateLayout); } else { importedLayout.setUuid(layout.getUuid()); importedLayout.setCreateDate(layout.getCreateDate()); importedLayout.setModifiedDate(layout.getModifiedDate()); importedLayout.setLayoutPrototypeUuid(layout.getLayoutPrototypeUuid()); importedLayout.setLayoutPrototypeLinkEnabled(layout.isLayoutPrototypeLinkEnabled()); importedLayout.setSourcePrototypeLayoutUuid(layout.getSourcePrototypeLayoutUuid()); } importedLayout.setGroupId(groupId); importedLayout.setPrivateLayout(privateLayout); importedLayout.setLayoutId(layoutId); // Resources boolean addGroupPermissions = true; Group group = importedLayout.getGroup(); if (privateLayout && group.isUser()) { addGroupPermissions = false; } boolean addGuestPermissions = false; if (!privateLayout || layout.isTypeControlPanel()) { addGuestPermissions = true; } ResourceLocalServiceUtil.addResources( user.getCompanyId(), groupId, user.getUserId(), Layout.class.getName(), importedLayout.getPlid(), false, addGroupPermissions, addGuestPermissions); LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, privateLayout); importedLayout.setLayoutSet(layoutSet); } else { importedLayout = existingLayout; } newLayoutsMap.put(oldLayoutId, importedLayout); long parentLayoutId = layout.getParentLayoutId(); Node parentLayoutNode = rootElement.selectSingleNode("./layouts/layout[@layout-id='" + parentLayoutId + "']"); String parentLayoutUuid = GetterUtil.getString(layoutElement.attributeValue("parent-layout-uuid")); if ((parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) && (parentLayoutNode != null)) { importLayout( portletDataContext, user, layoutCache, previousLayouts, newLayouts, newLayoutsMap, newLayoutIds, portletsMergeMode, themeId, colorSchemeId, layoutsImportMode, privateLayout, importPermissions, importPublicLayoutPermissions, importUserPermissions, importThemeSettings, rootElement, (Element) parentLayoutNode); Layout parentLayout = newLayoutsMap.get(parentLayoutId); parentLayoutId = parentLayout.getLayoutId(); } else if (Validator.isNotNull(parentLayoutUuid)) { Layout parentLayout = LayoutLocalServiceUtil.getLayoutByUuidAndGroupId(parentLayoutUuid, groupId); parentLayoutId = parentLayout.getLayoutId(); } if (_log.isDebugEnabled()) { _log.debug( "Importing layout with layout id " + layoutId + " and parent layout id " + parentLayoutId); } importedLayout.setCompanyId(user.getCompanyId()); importedLayout.setParentLayoutId(parentLayoutId); importedLayout.setName(layout.getName()); importedLayout.setTitle(layout.getTitle()); importedLayout.setDescription(layout.getDescription()); importedLayout.setKeywords(layout.getKeywords()); importedLayout.setRobots(layout.getRobots()); importedLayout.setType(layout.getType()); if (layout.isTypeArticle()) { importJournalArticle(portletDataContext, layout, layoutElement); importedLayout.setTypeSettings(layout.getTypeSettings()); } else if (layout.isTypePortlet() && Validator.isNotNull(layout.getTypeSettings()) && !portletsMergeMode.equals(PortletDataHandlerKeys.PORTLETS_MERGE_MODE_REPLACE)) { mergePortlets(importedLayout, layout.getTypeSettings(), portletsMergeMode); } else if (layout.isTypeLinkToLayout()) { UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties(); long linkToLayoutId = GetterUtil.getLong( typeSettingsProperties.getProperty("linkToLayoutId", StringPool.BLANK)); if (linkToLayoutId > 0) { Node linkedLayoutNode = rootElement.selectSingleNode("./layouts/layout[@layout-id='" + linkToLayoutId + "']"); if (linkedLayoutNode != null) { importLayout( portletDataContext, user, layoutCache, previousLayouts, newLayouts, newLayoutsMap, newLayoutIds, portletsMergeMode, themeId, colorSchemeId, layoutsImportMode, privateLayout, importPermissions, importPublicLayoutPermissions, importUserPermissions, importThemeSettings, rootElement, (Element) linkedLayoutNode); Layout linkedLayout = newLayoutsMap.get(linkToLayoutId); typeSettingsProperties.setProperty( "privateLayout", String.valueOf(linkedLayout.getPrivateLayout())); typeSettingsProperties.setProperty( "linkToLayoutId", String.valueOf(linkedLayout.getLayoutId())); } else { if (_log.isWarnEnabled()) { StringBundler sb = new StringBundler(); sb.append("Unable to link layout with friendly URL "); sb.append(layout.getFriendlyURL()); sb.append(" and layout id "); sb.append(layout.getLayoutId()); sb.append(" to layout with layout id "); sb.append(linkToLayoutId); _log.warn(sb.toString()); } } } importedLayout.setTypeSettings(layout.getTypeSettings()); } else { importedLayout.setTypeSettings(layout.getTypeSettings()); } importedLayout.setHidden(layout.isHidden()); importedLayout.setFriendlyURL(friendlyURL); if (importThemeSettings) { importedLayout.setThemeId(layout.getThemeId()); importedLayout.setColorSchemeId(layout.getColorSchemeId()); } else { importedLayout.setThemeId(StringPool.BLANK); importedLayout.setColorSchemeId(StringPool.BLANK); } importedLayout.setWapThemeId(layout.getWapThemeId()); importedLayout.setWapColorSchemeId(layout.getWapColorSchemeId()); importedLayout.setCss(layout.getCss()); importedLayout.setPriority(layout.getPriority()); importedLayout.setLayoutPrototypeUuid(layout.getLayoutPrototypeUuid()); importedLayout.setLayoutPrototypeLinkEnabled(layout.isLayoutPrototypeLinkEnabled()); StagingUtil.updateLastImportSettings(layoutElement, importedLayout, portletDataContext); fixTypeSettings(importedLayout); importedLayout.setIconImage(false); if (layout.isIconImage()) { String iconImagePath = layoutElement.elementText("icon-image-path"); byte[] iconBytes = portletDataContext.getZipEntryAsByteArray(iconImagePath); if ((iconBytes != null) && (iconBytes.length > 0)) { importedLayout.setIconImage(true); if (importedLayout.getIconImageId() == 0) { long iconImageId = CounterLocalServiceUtil.increment(); importedLayout.setIconImageId(iconImageId); } ImageLocalServiceUtil.updateImage(importedLayout.getIconImageId(), iconBytes); } } else { ImageLocalServiceUtil.deleteImage(importedLayout.getIconImageId()); } ServiceContext serviceContext = portletDataContext.createServiceContext(layoutElement, importedLayout, null); importedLayout.setExpandoBridgeAttributes(serviceContext); LayoutUtil.update(importedLayout, false); portletDataContext.setPlid(importedLayout.getPlid()); portletDataContext.setOldPlid(layout.getPlid()); newLayoutIds.add(importedLayout.getLayoutId()); newLayouts.add(importedLayout); // Layout permissions if (importPermissions) { _permissionImporter.importLayoutPermissions( layoutCache, portletDataContext.getCompanyId(), groupId, user.getUserId(), importedLayout, layoutElement, rootElement, importUserPermissions); } if (importPublicLayoutPermissions) { String resourceName = Layout.class.getName(); String resourcePrimKey = String.valueOf(importedLayout.getPlid()); Role guestRole = RoleLocalServiceUtil.getRole(importedLayout.getCompanyId(), RoleConstants.GUEST); if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 5) { Resource resource = layoutCache.getResource( importedLayout.getCompanyId(), groupId, resourceName, ResourceConstants.SCOPE_INDIVIDUAL, resourcePrimKey, false); PermissionLocalServiceUtil.setRolePermissions( guestRole.getRoleId(), new String[] {ActionKeys.VIEW}, resource.getResourceId()); } else if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) { ResourcePermissionLocalServiceUtil.setResourcePermissions( importedLayout.getCompanyId(), resourceName, ResourceConstants.SCOPE_INDIVIDUAL, resourcePrimKey, guestRole.getRoleId(), new String[] {ActionKeys.VIEW}); } else { Resource resource = layoutCache.getResource( importedLayout.getCompanyId(), groupId, resourceName, ResourceConstants.SCOPE_INDIVIDUAL, resourcePrimKey, false); PermissionLocalServiceUtil.setGroupPermissions( groupId, new String[] {ActionKeys.VIEW}, resource.getResourceId()); } } _portletImporter.importPortletData( portletDataContext, PortletKeys.LAYOUT_CONFIGURATION, null, layoutElement); }
@Override public SyncDLObject addFileEntry( long repositoryId, long folderId, String sourceFileName, String mimeType, String title, String description, String changeLog, File file, String checksum, ServiceContext serviceContext) throws PortalException { try { Group group = groupLocalService.getGroup(repositoryId); SyncUtil.checkSyncEnabled(group.getGroupId()); if (!group.isUser() && (serviceContext.getGroupPermissions() == null)) { SyncUtil.setFilePermissions(group, false, serviceContext); } FileEntry fileEntry = dlAppService.addFileEntry( repositoryId, folderId, sourceFileName, mimeType, title, description, changeLog, file, serviceContext); return toSyncDLObject(fileEntry, SyncConstants.EVENT_ADD); } catch (PortalException pe) { if (pe instanceof DuplicateFileException) { if (GetterUtil.getBoolean(serviceContext.getAttribute("overwrite"))) { FileEntry fileEntry = dlAppService.getFileEntry(repositoryId, folderId, title); fileEntry = dlAppService.updateFileEntry( fileEntry.getFileEntryId(), sourceFileName, mimeType, title, description, changeLog, false, file, serviceContext); return toSyncDLObject(fileEntry, SyncConstants.EVENT_UPDATE); } } throw new PortalException(SyncUtil.buildExceptionMessage(pe), pe); } }
@Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { if (MergeLayoutPrototypesThreadLocal.isInProgress()) { return methodInvocation.proceed(); } Method method = methodInvocation.getMethod(); String methodName = method.getName(); Class<?>[] parameterTypes = method.getParameterTypes(); Object[] arguments = methodInvocation.getArguments(); boolean workflowEnabled = WorkflowThreadLocal.isEnabled(); if (methodName.equals("getLayout") && (Arrays.equals(parameterTypes, _TYPES_L) || Arrays.equals(parameterTypes, _TYPES_L_B_L))) { Layout layout = (Layout) methodInvocation.proceed(); Group group = layout.getGroup(); if (isMergeComplete(method, arguments, group)) { return layout; } if (Validator.isNull(layout.getLayoutPrototypeUuid()) && Validator.isNull(layout.getSourcePrototypeLayoutUuid())) { return layout; } LayoutSet layoutSet = layout.getLayoutSet(); try { MergeLayoutPrototypesThreadLocal.setInProgress(true); WorkflowThreadLocal.setEnabled(false); SitesUtil.mergeLayoutPrototypeLayout(group, layout); if (Validator.isNotNull(layout.getSourcePrototypeLayoutUuid())) { SitesUtil.mergeLayoutSetPrototypeLayouts(group, layoutSet); } } finally { MergeLayoutPrototypesThreadLocal.setMergeComplete(method, arguments); WorkflowThreadLocal.setEnabled(workflowEnabled); } } else if (methodName.equals("getLayouts") && (Arrays.equals(parameterTypes, _TYPES_L_B_L) || Arrays.equals(parameterTypes, _TYPES_L_B_L_B_I_I))) { long groupId = (Long) arguments[0]; Group group = GroupLocalServiceUtil.getGroup(groupId); if (isMergeComplete(method, arguments, group)) { return methodInvocation.proceed(); } boolean privateLayout = (Boolean) arguments[1]; long parentLayoutId = (Long) arguments[2]; try { LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, privateLayout); mergeLayoutSetPrototypeLayouts( method, arguments, group, layoutSet, privateLayout, workflowEnabled); List<Layout> layouts = (List<Layout>) methodInvocation.proceed(); if (PropsValues.USER_GROUPS_COPY_LAYOUTS_TO_USER_PERSONAL_SITE) { return layouts; } if (group.isUser()) { _virtualLayoutTargetGroupId.set(group.getGroupId()); if (parentLayoutId == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) { return addUserGroupLayouts(group, layoutSet, layouts, parentLayoutId); } else { return addChildUserGroupLayouts(group, layouts); } } else if (group.isUserGroup() && (parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID)) { long targetGroupId = _virtualLayoutTargetGroupId.get(); if (targetGroupId != GroupConstants.DEFAULT_LIVE_GROUP_ID) { Group targetGroup = GroupLocalServiceUtil.getGroup(targetGroupId); return addChildUserGroupLayouts(targetGroup, layouts); } } return layouts; } catch (Exception e) { _log.error(e, e); throw e; } } return methodInvocation.proceed(); }
public boolean containsWithoutViewableGroup( PermissionChecker permissionChecker, Layout layout, String controlPanelCategory, boolean checkLayoutUpdateable, String actionId) throws PortalException, SystemException { if (checkLayoutUpdateable && !actionId.equals(ActionKeys.CUSTOMIZE) && !actionId.equals(ActionKeys.VIEW) && (layout instanceof VirtualLayout)) { return false; } if (actionId.equals(ActionKeys.CUSTOMIZE) && (layout instanceof VirtualLayout)) { VirtualLayout virtualLayout = (VirtualLayout) layout; layout = virtualLayout.getWrappedModel(); } if (actionId.equals(ActionKeys.DELETE) && !SitesUtil.isLayoutDeleteable(layout)) { return false; } Group group = layout.getGroup(); if (checkLayoutUpdateable && !group.isLayoutSetPrototype() && isAttemptToModifyLockedLayout(layout, actionId)) { return false; } User user = UserLocalServiceUtil.getUserById(permissionChecker.getUserId()); if ((PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) && !user.isDefaultUser() && !group.isUser()) { // This is new way of doing an ownership check without having to // have a userId field on the model. When the instance model was // first created, we set the user's userId as the ownerId of the // individual scope ResourcePermission of the Owner Role. // Therefore, ownership can be determined by obtaining the Owner // role ResourcePermission for the current instance model and // testing it with the hasOwnerPermission call. ResourcePermission resourcePermission = ResourcePermissionLocalServiceUtil.getResourcePermission( layout.getCompanyId(), Layout.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(layout.getPlid()), permissionChecker.getOwnerRoleId()); if (permissionChecker.hasOwnerPermission( layout.getCompanyId(), Layout.class.getName(), String.valueOf(layout.getPlid()), resourcePermission.getOwnerId(), actionId)) { return true; } } if (GroupPermissionUtil.contains( permissionChecker, layout.getGroupId(), ActionKeys.MANAGE_LAYOUTS)) { return true; } else if (actionId.equals(ActionKeys.ADD_LAYOUT) && GroupPermissionUtil.contains( permissionChecker, layout.getGroupId(), ActionKeys.ADD_LAYOUT)) { return true; } if (PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE && !actionId.equals(ActionKeys.VIEW)) { // Check upward recursively to see if any pages above grant the // action long parentLayoutId = layout.getParentLayoutId(); while (parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) { Layout parentLayout = LayoutLocalServiceUtil.getLayout( layout.getGroupId(), layout.isPrivateLayout(), parentLayoutId); if (contains(permissionChecker, parentLayout, controlPanelCategory, actionId)) { return true; } parentLayoutId = parentLayout.getParentLayoutId(); } } try { if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) { if (ResourcePermissionLocalServiceUtil.getResourcePermissionsCount( layout.getCompanyId(), Layout.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(layout.getPlid())) == 0) { throw new NoSuchResourceException(); } } else { ResourceLocalServiceUtil.getResource( layout.getCompanyId(), Layout.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(layout.getPlid())); } } catch (NoSuchResourceException nsre) { boolean addGroupPermission = true; boolean addGuestPermission = true; if (layout.isPrivateLayout()) { addGuestPermission = false; } ResourceLocalServiceUtil.addResources( layout.getCompanyId(), layout.getGroupId(), 0, Layout.class.getName(), layout.getPlid(), false, addGroupPermission, addGuestPermission); } return permissionChecker.hasPermission( layout.getGroupId(), Layout.class.getName(), layout.getPlid(), actionId); }
@Override public boolean contains(PermissionChecker permissionChecker, Group group, String actionId) throws PortalException, SystemException { long groupId = group.getGroupId(); if (group.isStagingGroup()) { group = group.getLiveGroup(); } if (group.isUser()) { // An individual user would never reach this block because he would // be an administrator of his own layouts. However, a user who // manages a set of organizations may be modifying pages of a user // he manages. User user = UserLocalServiceUtil.getUserById(group.getClassPK()); if ((permissionChecker.getUserId() != user.getUserId()) && UserPermissionUtil.contains( permissionChecker, user.getUserId(), user.getOrganizationIds(), ActionKeys.UPDATE)) { return true; } } if (actionId.equals(ActionKeys.ADD_COMMUNITY) && permissionChecker.hasPermission( groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_SUBGROUPS) || PortalPermissionUtil.contains(permissionChecker, ActionKeys.ADD_COMMUNITY)) { return true; } else if (actionId.equals(ActionKeys.ADD_LAYOUT) && !group.isLayoutPrototype() && permissionChecker.hasPermission( groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_LAYOUTS)) { return true; } else if ((actionId.equals(ActionKeys.EXPORT_IMPORT_LAYOUTS) || actionId.equals(ActionKeys.EXPORT_IMPORT_PORTLET_INFO)) && permissionChecker.hasPermission( groupId, Group.class.getName(), groupId, ActionKeys.PUBLISH_STAGING)) { return true; } else if (actionId.equals(ActionKeys.VIEW) && (permissionChecker.hasPermission( groupId, Group.class.getName(), groupId, ActionKeys.ASSIGN_USER_ROLES) || permissionChecker.hasPermission( groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_LAYOUTS))) { return true; } else if (actionId.equals(ActionKeys.VIEW_STAGING) && (permissionChecker.hasPermission( groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_LAYOUTS) || permissionChecker.hasPermission( groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_STAGING) || permissionChecker.hasPermission( groupId, Group.class.getName(), groupId, ActionKeys.PUBLISH_STAGING) || permissionChecker.hasPermission( groupId, Group.class.getName(), groupId, ActionKeys.UPDATE))) { return true; } // Group id must be set so that users can modify their personal pages if (permissionChecker.hasPermission(groupId, Group.class.getName(), groupId, actionId)) { return true; } while (!group.isRoot()) { if (contains(permissionChecker, group.getParentGroupId(), ActionKeys.MANAGE_SUBGROUPS)) { return true; } group = group.getParentGroup(); } return false; }