001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.mypages.action;
016    
017    import com.liferay.portal.model.Group;
018    import com.liferay.portal.model.RoleConstants;
019    import com.liferay.portal.model.User;
020    import com.liferay.portal.service.RoleLocalServiceUtil;
021    import com.liferay.portal.struts.PortletAction;
022    import com.liferay.portal.util.PortalUtil;
023    import com.liferay.portal.util.PropsValues;
024    import com.liferay.portlet.RenderRequestImpl;
025    import com.liferay.portlet.sites.action.ActionUtil;
026    import com.liferay.util.servlet.DynamicServletRequest;
027    
028    import javax.portlet.PortletConfig;
029    import javax.portlet.RenderRequest;
030    import javax.portlet.RenderResponse;
031    import javax.portlet.WindowState;
032    
033    import org.apache.struts.action.ActionForm;
034    import org.apache.struts.action.ActionForward;
035    import org.apache.struts.action.ActionMapping;
036    
037    /**
038     * @author Jorge Ferrer
039     * @author Amos Fong
040     */
041    public class ViewAction extends PortletAction {
042    
043            @Override
044            public ActionForward render(
045                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
046                            RenderRequest renderRequest, RenderResponse renderResponse)
047                    throws Exception {
048    
049                    if (renderRequest.getRemoteUser() == null) {
050                            return mapping.findForward("portlet.my_pages.view");
051                    }
052    
053                    if (!renderRequest.getWindowState().equals(WindowState.MAXIMIZED)) {
054                            return mapping.findForward("portlet.my_pages.view");
055                    }
056    
057                    User user = PortalUtil.getUser(renderRequest);
058    
059                    RenderRequestImpl renderRequestImpl = (RenderRequestImpl)renderRequest;
060    
061                    DynamicServletRequest dynamicRequest =
062                            (DynamicServletRequest)renderRequestImpl.getHttpServletRequest();
063    
064                    dynamicRequest.setParameter(
065                            "p_u_i_d", String.valueOf(user.getUserId()));
066    
067                    String tabs1 = "public-pages";
068    
069                    boolean hasPowerUserRole = RoleLocalServiceUtil.hasUserRole(
070                            user.getUserId(), user.getCompanyId(), RoleConstants.POWER_USER,
071                            true);
072    
073                    if (PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED &&
074                            !hasPowerUserRole) {
075    
076                            tabs1 = "private-pages";
077                    }
078    
079                    dynamicRequest.setParameter("tabs1", tabs1);
080    
081                    Group group = user.getGroup();
082    
083                    dynamicRequest.setParameter(
084                            "groupId", String.valueOf(group.getGroupId()));
085    
086                    ActionUtil.getGroup(renderRequest);
087    
088                    return mapping.findForward("portlet.my_pages.edit_layouts");
089            }
090    
091    }