001    /**
002     * Copyright (c) 2000-2013 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.kernel.servlet.DynamicServletRequest;
018    import com.liferay.portal.model.Group;
019    import com.liferay.portal.model.RoleConstants;
020    import com.liferay.portal.model.User;
021    import com.liferay.portal.service.RoleLocalServiceUtil;
022    import com.liferay.portal.struts.PortletAction;
023    import com.liferay.portal.util.PortalUtil;
024    import com.liferay.portal.util.PropsValues;
025    import com.liferay.portlet.RenderRequestImpl;
026    import com.liferay.portlet.sites.action.ActionUtil;
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 actionMapping, ActionForm actionForm,
046                            PortletConfig portletConfig, RenderRequest renderRequest,
047                            RenderResponse renderResponse)
048                    throws Exception {
049    
050                    if (renderRequest.getRemoteUser() == null) {
051                            return actionMapping.findForward("portlet.my_pages.view");
052                    }
053    
054                    if (!renderRequest.getWindowState().equals(WindowState.MAXIMIZED)) {
055                            return actionMapping.findForward("portlet.my_pages.view");
056                    }
057    
058                    User user = PortalUtil.getUser(renderRequest);
059    
060                    RenderRequestImpl renderRequestImpl = (RenderRequestImpl)renderRequest;
061    
062                    DynamicServletRequest dynamicRequest =
063                            (DynamicServletRequest)renderRequestImpl.getHttpServletRequest();
064    
065                    dynamicRequest.setParameter(
066                            "p_u_i_d", String.valueOf(user.getUserId()));
067    
068                    String tabs1 = "public-pages";
069    
070                    boolean hasPowerUserRole = RoleLocalServiceUtil.hasUserRole(
071                            user.getUserId(), user.getCompanyId(), RoleConstants.POWER_USER,
072                            true);
073    
074                    if (PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED &&
075                            !hasPowerUserRole) {
076    
077                            tabs1 = "private-pages";
078                    }
079    
080                    dynamicRequest.setParameter("tabs1", tabs1);
081    
082                    Group group = user.getGroup();
083    
084                    dynamicRequest.setParameter(
085                            "groupId", String.valueOf(group.getGroupId()));
086    
087                    ActionUtil.getGroup(renderRequest);
088    
089                    return actionMapping.findForward("portlet.my_pages.edit_layouts");
090            }
091    
092    }