-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 13192 edit mode cleanup #13193
Conversation
@@ -258,9 +258,14 @@ | |||
public static final String ADMIN_MODE_COOKIE = "ADMIN_MODE_COOKIE"; | |||
|
|||
// SESSION ATTRIBUTES | |||
/* | |||
public static final String EDIT_MODE_SESSION = "com.dotmarketing.EDIT_MODE_SESSION"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -41,8 +42,7 @@ public void init(Object obj) { | |||
|
|||
if (session != null) { | |||
timemachine = session.getAttribute("tm_date") != null; | |||
ADMIN_MODE = !timemachine && session != null | |||
&& (session.getAttribute(com.dotmarketing.util.WebKeys.ADMIN_MODE_SESSION) != null); | |||
boolean ADMIN_MODE = PageMode.get(request) .isAdmin; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
public static PageMode get(HttpSession ses) { | ||
|
||
PageMode mode = (ses != null && ses.getAttribute(com.dotmarketing.util.WebKeys.PAGE_MODE_SESSION) != null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
|
||
|
||
|
||
Optional<ShortyId> shortOpt = APILocator.getShortyAPI().getShorty(id); | ||
User user = WebAPILocator.getUserWebAPI().getLoggedInFrontendUser(request); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
PageMode mode = (EDIT_MODE) | ||
? PageMode.EDIT | ||
: (PREVIEW_MODE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? PageMode.EDIT | ||
: (PREVIEW_MODE) | ||
? PageMode.PREVIEW | ||
: (ADMIN_MODE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -117,21 +113,15 @@ public Response searchRaw(@Context HttpServletRequest request) { | |||
|
|||
HttpSession session = request.getSession(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import java.util.List; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpSession; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
PageMode mode = PageMode.get(req); | ||
EDIT_OR_PREVIEW_MODE=!mode.showLive; | ||
if(session!=null){ | ||
tmDate = (String) session.getAttribute("tm_date"); | ||
boolean tm=tmDate!=null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final Class classToUse) throws ParseException, IllegalAccessException, | ||
InvocationTargetException, InstantiationException, NoSuchMethodException, NoSuchFieldException { | ||
public static <T> List<T> convertDotConnectMapToPOJO(List<Map<String, Object>> results, final Class classToUse) | ||
throws IllegalAccessException, InstantiationException, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InvocationTargetException, InstantiationException, NoSuchMethodException, NoSuchFieldException { | ||
public static <T> List<T> convertDotConnectMapToPOJO(List<Map<String, Object>> results, final Class classToUse) | ||
throws IllegalAccessException, InstantiationException, | ||
NoSuchMethodException, NoSuchFieldException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hostVariablesTemplate.merge(context, out); | ||
template.merge(context, out); | ||
|
||
} catch (ParseErrorException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -30,8 +30,6 @@ public String getName() { | |||
return "fixBreaks"; | |||
} | |||
|
|||
|
|||
|
|||
final public boolean render(InternalContextAdapter context, Writer writer, Node node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -30,8 +30,6 @@ public String getName() { | |||
return "fixBreaks"; | |||
} | |||
|
|||
|
|||
|
|||
final public boolean render(InternalContextAdapter context, Writer writer, Node node) | |||
throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the declaration of thrown exception 'org.apache.velocity.exception.ResourceNotFoundException' which is a runtime exception.
Remove the declaration of thrown exception 'org.apache.velocity.exception.ParseErrorException' which is a runtime exception.
Remove the declaration of thrown exception 'org.apache.velocity.exception.MethodInvocationException' which is a runtime exception.
|
||
try { | ||
backendUser = com.liferay.portal.util.PortalUtil.getUser(request); | ||
// Skin skin = backendUser.getSkin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @throws DotDataException | ||
* @throws DotSecurityException | ||
*/ | ||
public static IHTMLPage getPage(Identifier id, HttpServletRequest request, boolean live, Context context) throws DotDataException, DotSecurityException{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context.put("dotPageMode", mode); | ||
Date moddate = htmlPage.getModDate(); | ||
|
||
moddate = new Date(moddate.getTime()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
//get the context from the request if possible | ||
ChainedContext context; | ||
if ( request.getAttribute( com.dotcms.rendering.velocity.Constants.VELOCITY_CONTEXT ) != null && request.getAttribute( com.dotcms.rendering.velocity.Constants.VELOCITY_CONTEXT ) instanceof ChainedContext ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @throws DotSecurityException | ||
* @throws DotDataException | ||
*/ | ||
public static String getPageCacheKey(HttpServletRequest request, HttpServletResponse response) throws DotDataException, DotSecurityException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return (ChainedContext) request.getAttribute( "velocityContext" ); | ||
} else { | ||
RequestWrapper rw = new RequestWrapper( request ); | ||
if ( request.getAttribute( "User-Agent" ) != null && request.getAttribute( "User-Agent" ).equals( Constants.USER_AGENT_DOTCMS_BROWSER ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ " and deleted=" + com.dotmarketing.db.DbConnectionFactory.getDBFalse() + "and language_id = " | ||
+ (String) request.getSession().getAttribute(com.dotmarketing.util.WebKeys.HTMLPAGE_LANGUAGE) + ")", "UTF-8"); | ||
context.put("view", view); | ||
} catch (Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class VelocityUtil { | ||
|
||
private static VelocityEngine ve = null; | ||
private static boolean DEFAULT_PAGE_TO_DEFAULT_LANGUAGE = LanguageWebAPI.canDefaultPageToDefaultLanguage(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static VelocityEngine ve = null; | ||
private static boolean DEFAULT_PAGE_TO_DEFAULT_LANGUAGE = LanguageWebAPI.canDefaultPageToDefaultLanguage(); | ||
|
||
private synchronized static void init(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static boolean DEFAULT_PAGE_TO_DEFAULT_LANGUAGE = LanguageWebAPI.canDefaultPageToDefaultLanguage(); | ||
|
||
private synchronized static void init(){ | ||
if(ve != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
// nocache passed either as a session var, as a request var or as a | ||
// request attribute | ||
if ("no".equals(request.getParameter("dotcache")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ve.init(SystemProperties.getProperties()); | ||
|
||
Logger.debug(VelocityUtil.class, SystemProperties.getProperties().toString()); | ||
}catch (Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* if we have a toolbox manager, get a toolbox from it See | ||
* /WEB-INF/toolbox.xml | ||
*/ | ||
context.setToolbox(getToolboxManager().getToolboxContext(context)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// put the list of languages on the page | ||
context.put("languages", getLanguages()); | ||
HttpSession session = request.getSession(false); | ||
if(!UtilMethods.isSet(request.getAttribute(WebKeys.HTMLPAGE_LANGUAGE)) && session!=null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HttpSession session = request.getSession(false); | ||
if(!UtilMethods.isSet(request.getAttribute(WebKeys.HTMLPAGE_LANGUAGE)) && session!=null) | ||
context.put("language", (String) session.getAttribute(com.dotmarketing.util.WebKeys.HTMLPAGE_LANGUAGE)); | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backendUser = com.liferay.portal.util.PortalUtil.getUser(request); | ||
// Skin skin = backendUser.getSkin(); | ||
// context.put("USER_SKIN", skin.getSkinId()); | ||
} catch (Exception nsue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
velocityRootPath = Config.getStringProperty("VELOCITY_ROOT", "/WEB-INF/velocity"); | ||
if (velocityRootPath.startsWith("/WEB-INF")) { | ||
Logger.debug(VelocityUtil.class, "Velocity ROOT Path not found, defaulting it to '/WEB-INF/velocity'"); | ||
String startPath = velocityRootPath.substring(0, 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Host host; | ||
host = WebAPILocator.getHostWebAPI().getCurrentHost(request); | ||
context.put("host", host); | ||
} catch (Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (velocityRootPath.startsWith("/WEB-INF")) { | ||
Logger.debug(VelocityUtil.class, "Velocity ROOT Path not found, defaulting it to '/WEB-INF/velocity'"); | ||
String startPath = velocityRootPath.substring(0, 8); | ||
String endPath = velocityRootPath.substring(9, velocityRootPath.length()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
// to check user has permission to publish this page | ||
boolean permission = APILocator.getPermissionAPI().doesUserHavePermission(htmlPage, PERMISSION_PUBLISH, backendUser); | ||
context.put("permission", new Boolean(permission)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
String adminRoleKey = ""; | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Visitor visitor = (Visitor) request.getSession().getAttribute(WebKeys.VISITOR); | ||
context.put("visitor", visitor); | ||
|
||
} catch (Exception nsue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try { | ||
Role adminRole = APILocator.getRoleAPI().loadRoleByKey(Config.getStringProperty("CMS_ADMINISTRATOR_ROLE", "CMS Administrator")); | ||
adminRoleKey = adminRole.getRoleKey(); | ||
} catch (Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
public String parseVelocity(String velocityCode, Context ctx){ | ||
VelocityEngine ve = VelocityUtil.getEngine(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This replaced the nasty code we have everywhere
with
etc....