Skip to content
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

Merged
merged 49 commits into from
Dec 27, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
78ec583
#13164 untested work
wezell Dec 4, 2017
7f8352a
#13164 removes multitreefactory from hibernate, includes treefactory
wezell Dec 5, 2017
e662daa
#13164 removes tree from inode and category hibernate
wezell Dec 5, 2017
d28d16c
#13164 removing old code
wezell Dec 5, 2017
f5bdcff
core#13192 edit mode parsing
wezell Dec 8, 2017
df54dc4
#13192 edit mode parsing
wezell Dec 8, 2017
04e14bb
#13192 contenttool
wezell Dec 8, 2017
6fc9946
#13194 some untested fixes
wezell Dec 8, 2017
d43b9f6
#13194 use map.getOrDefault methods
wezell Dec 8, 2017
68dc4bb
#13194 loadObjectResults
wezell Dec 8, 2017
1e4e5d5
#13194 jenkins feedback fixes
wezell Dec 8, 2017
da94307
#13194 fixes the red
wezell Dec 8, 2017
99a4771
Merge branch 'issue-13194-ConvertToPOJOUtil' into issue-13192-edit-mo…
wezell Dec 8, 2017
4ae51f5
#13192 Container+Content Resource
wezell Dec 8, 2017
aaedc07
#13192 adding widget support
wezell Dec 8, 2017
34e29db
#13192 adding widget support
wezell Dec 8, 2017
fcd43b4
#13192 container pulling
wezell Dec 11, 2017
1b85a90
#13192 edit mode cleanup
wezell Dec 11, 2017
8daeedb
Add lang variables and update edit contentlet save and cancel functio…
fmontes Dec 13, 2017
52aec59
#13192 multitree updates
wezell Dec 13, 2017
c9454d6
#13192 multitree updates
wezell Dec 13, 2017
faec379
Merge branch 'issue-13192-edit-mode-cleanup' of github.com:dotCMS/cor…
wezell Dec 13, 2017
6275d01
#13192 removing templatecontainers import
wezell Dec 13, 2017
71ddeb9
#13192 removing templatecontainers from hibernate
wezell Dec 13, 2017
3305052
#13192 allow multitree to be imported
wezell Dec 13, 2017
5691eae
#13192 fixes import
wezell Dec 13, 2017
bbedf37
#13192 copying velocity work to new folder
wezell Dec 15, 2017
ebfd602
Update ContentSelector dojo widget to make it work with ng
fmontes Dec 16, 2017
8fb2443
#13192 kinda running
wezell Dec 16, 2017
6e1d7ff
#13192 look ma, no red
wezell Dec 16, 2017
fe2d0a1
Fix ContentSelector select event
fmontes Dec 18, 2017
7f66ae5
Fix edit contentlet requires fields
fmontes Dec 18, 2017
57bb803
#13192 live mode working
wezell Dec 18, 2017
9f1c259
#13192 slow and steady
wezell Dec 19, 2017
65bc6d3
Merge branch 'issue-13192-edit-mode-cleanup' of github.com:dotCMS/cor…
wezell Dec 19, 2017
5a85e50
#13192 no red! ready to ship
wezell Dec 20, 2017
e8dac76
#13192 live mode
wezell Dec 20, 2017
8a3e9a5
#13192 live mode working
wezell Dec 20, 2017
4c03852
#13192 preview mode working exclaimation point
wezell Dec 20, 2017
bbe89a5
#13192 readding the integration tests
wezell Dec 20, 2017
b71662f
#13192 missing the multitree transformer
wezell Dec 21, 2017
c577cf1
#13192 ContainerResourceWorking
wezell Dec 21, 2017
f306c3f
#13192 merged
wezell Dec 26, 2017
a389484
Merge remote-tracking branch 'remotes/origin/master' into issue-13192…
jgambarios Dec 26, 2017
7edc8d8
Merge remote-tracking branch 'remotes/origin/master' into issue-13192…
jgambarios Dec 26, 2017
9f112aa
#13192 CloseDB aspect fixed
wezell Dec 27, 2017
cf5a3b5
Merge branch 'issue-13192-edit-mode-cleanup' of github.com:dotCMS/cor…
wezell Dec 27, 2017
41246f7
#13192 unable to save pages
wezell Dec 27, 2017
231fba4
#13192 white space cleanup
wezell Dec 27, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.dotcms.repackage.org.apache.struts.action.ActionMessage;
import com.dotcms.repackage.org.apache.struts.action.ActionMessages;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageMode;
import com.dotmarketing.util.WebKeys;

import javax.servlet.http.HttpServletRequest;
Expand All @@ -27,9 +28,7 @@ public Result intercept(final HttpServletRequest request,
Result result = Result.NEXT;

if (null != session) {
final boolean isAdminMode = (session.getAttribute
(com.dotmarketing.util.WebKeys.ADMIN_MODE_SESSION) != null);

final boolean isAdminMode = PageMode.get(request).isAdmin;

// if we are not logged in and you are not admin mode. go to login page
if (session.getAttribute(WebKeys.CMS_USER) == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.dotmarketing.portlets.contentlet.business.ContentletAPI;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageMode;

import com.liferay.portal.model.User;

import javax.servlet.http.HttpServletRequest;
Expand All @@ -38,13 +40,7 @@ public Response search(@Context HttpServletRequest request, @Context HttpServlet
User user = initData.getUser();
ResourceResponse responseResource = new ResourceResponse(initData.getParamsMap());

boolean live = true;
boolean ADMIN_MODE = (session.getAttribute(com.dotmarketing.util.WebKeys.ADMIN_MODE_SESSION) != null);
boolean PREVIEW_MODE = ((session.getAttribute(com.dotmarketing.util.WebKeys.PREVIEW_MODE_SESSION) != null) && ADMIN_MODE);
boolean EDIT_MODE = ((session.getAttribute(com.dotmarketing.util.WebKeys.EDIT_MODE_SESSION) != null) && ADMIN_MODE);
if (EDIT_MODE || PREVIEW_MODE) {
live = false;
}
PageMode mode = PageMode.get(request);

JSONObject esQuery;
try {
Expand All @@ -55,7 +51,7 @@ public Response search(@Context HttpServletRequest request, @Context HttpServlet
}

try {
ESSearchResults esresult = esapi.esSearch(esQuery.toString(), live, user, live);
ESSearchResults esresult = esapi.esSearch(esQuery.toString(), mode.showLive, user, mode.showLive);

JSONObject json = new JSONObject();
JSONArray jsonCons = new JSONArray();
Expand Down Expand Up @@ -117,21 +113,15 @@ public Response searchRaw(@Context HttpServletRequest request) {

HttpSession session = request.getSession();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Remove this useless assignment to local variable "session". rule
MINOR Remove this unused "session" local variable. rule


boolean live = true;
boolean ADMIN_MODE = (session.getAttribute(com.dotmarketing.util.WebKeys.ADMIN_MODE_SESSION) != null);
boolean PREVIEW_MODE = ((session.getAttribute(com.dotmarketing.util.WebKeys.PREVIEW_MODE_SESSION) != null) && ADMIN_MODE);
boolean EDIT_MODE = ((session.getAttribute(com.dotmarketing.util.WebKeys.EDIT_MODE_SESSION) != null) && ADMIN_MODE);
if (EDIT_MODE || PREVIEW_MODE) {
live = false;
}
PageMode mode = PageMode.get(request);

ResourceResponse responseResource = new ResourceResponse(initData.getParamsMap());

User user = initData.getUser();
try {
String esQuery = IOUtils.toString(request.getInputStream());

return responseResource.response(esapi.esSearchRaw(esQuery, live, user, live).toString());
return responseResource.response(esapi.esSearchRaw(esQuery, mode.showLive, user, mode.showLive).toString());

} catch (Exception e) {
Logger.error(this.getClass(), "Error processing :" + e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.portlets.contentlet.business.HostAPIImpl;
import com.dotmarketing.util.PageMode;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.WebKeys;
import com.liferay.portal.PortalException;
Expand Down Expand Up @@ -56,21 +57,14 @@ public Host getCurrentHost(HttpServletRequest request) throws DotDataException,
UserWebAPI userWebAPI = WebAPILocator.getUserWebAPI();
User systemUser = userWebAPI.getSystemUser();
boolean respectFrontendRoles = !userWebAPI.isLoggedToBackend(request);
boolean adminMode = false;
boolean previewMode = false;
boolean editMode = false;

if(session != null) {
adminMode = (session.getAttribute(com.dotmarketing.util.WebKeys.ADMIN_MODE_SESSION) != null);
previewMode = (session.getAttribute(com.dotmarketing.util.WebKeys.PREVIEW_MODE_SESSION) != null && adminMode);
editMode = (session.getAttribute(com.dotmarketing.util.WebKeys.EDIT_MODE_SESSION) != null && adminMode);
}

PageMode mode = PageMode.get(request);

String pageHostId = request.getParameter("host_id");
if(pageHostId != null && (editMode || previewMode)) {
host = find(pageHostId, systemUser, respectFrontendRoles);
if(pageHostId != null && !mode.showLive) {
host = find(pageHostId, systemUser, respectFrontendRoles);
} else {
if(session != null && adminMode && session.getAttribute(WebKeys.CURRENT_HOST) != null) {
if(session != null && mode.isAdmin && session.getAttribute(WebKeys.CURRENT_HOST) != null) {
host = (Host) session.getAttribute(WebKeys.CURRENT_HOST);
} else if(request.getAttribute(WebKeys.CURRENT_HOST) != null) {
host = (Host) request.getAttribute(WebKeys.CURRENT_HOST);
Expand All @@ -83,7 +77,7 @@ public Host getCurrentHost(HttpServletRequest request) throws DotDataException,
}

request.setAttribute(WebKeys.CURRENT_HOST, host);
if(session != null && adminMode) {
if(session != null && mode.isAdmin) {
session.setAttribute(WebKeys.CURRENT_HOST, host);
}
return host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.dotmarketing.portlets.languagesmanager.business.LanguageAPI;
import com.dotmarketing.portlets.languagesmanager.model.Language;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageMode;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.WebKeys;
import com.liferay.portal.struts.MultiMessageResources;
Expand Down Expand Up @@ -134,7 +135,8 @@ public Language getLanguage(HttpServletRequest httpRequest) {
//only set in session if we are not in a timemachine
if(sessionOpt.getAttribute("tm_lang")==null){
sessionOpt.setAttribute(WebKeys.HTMLPAGE_LANGUAGE, String.valueOf(future.getId()));
boolean ADMIN_MODE = (sessionOpt.getAttribute(WebKeys.ADMIN_MODE_SESSION) != null);
boolean ADMIN_MODE = PageMode.get(httpRequest).isAdmin;

if (ADMIN_MODE == false || httpRequest.getParameter("leftMenu") == null) {
sessionOpt.setAttribute(WebKeys.Globals_FRONTEND_LOCALE_KEY, locale);
httpRequest.setAttribute(WebKeys.Globals_FRONTEND_LOCALE_KEY, locale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.dotmarketing.tag.model.Tag;
import com.dotmarketing.util.Config;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageMode;
import com.dotmarketing.util.RegEX;
import com.dotmarketing.util.RegExMatch;
import com.dotmarketing.util.TagUtil;
Expand Down Expand Up @@ -142,12 +143,8 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
return;
}
if (RegEX.contains(url, mastRegEx)) {
boolean ADMIN_MODE = (optSession != null
&& optSession.getAttribute(com.dotmarketing.util.WebKeys.ADMIN_MODE_SESSION)
!= null);
boolean EDIT_MODE = ((optSession != null
&& optSession.getAttribute(com.dotmarketing.util.WebKeys.EDIT_MODE_SESSION)
!= null) && ADMIN_MODE);
boolean ADMIN_MODE = PageMode.get(request) .isAdmin;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'. rule

boolean EDIT_MODE = PageMode.get(request) == PageMode.EDIT;

Structure structure = null;

Expand Down
29 changes: 8 additions & 21 deletions dotCMS/src/main/java/com/dotmarketing/filters/CMSFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import com.dotmarketing.util.Config;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.NumberOfTimeVisitedCounter;
import com.dotmarketing.util.PageRequestModeUtil;
import com.dotmarketing.util.PageMode;

import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.WebKeys;
import java.io.IOException;
Expand All @@ -28,7 +29,7 @@
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.LogFactory;

public class CMSFilter implements Filter {
Expand Down Expand Up @@ -223,37 +224,23 @@ public void destroy() {
}

private void countSiteVisit(HttpServletRequest request, HttpServletResponse response) {

HttpSession session = request.getSession(false);
boolean PAGE_MODE = true;

if (session != null) {
PAGE_MODE = PageRequestModeUtil.isPageMode(session);
}

if (PAGE_MODE) {
PageMode mode = PageMode.get(request);
if(mode == PageMode.ANON) {
NumberOfTimeVisitedCounter.maybeCount(request, response);

}
}

private void countPageVisit(HttpServletRequest request) {

HttpSession session = request.getSession(false);
boolean PAGE_MODE = true;

if (session != null) {
PAGE_MODE = PageRequestModeUtil.isPageMode(session);
}

if (PAGE_MODE) {
PageMode mode = PageMode.get(request);
if(mode == PageMode.ANON) {
Optional<Visitor> visitor = visitorAPI.getVisitor(request);

if (visitor.isPresent()) {
visitor.get().addPagesViewed(request.getRequestURI());
}

}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.dotmarketing.business.web.HostWebAPI;
import com.dotmarketing.business.web.WebAPILocator;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageMode;

public class ThreadNameFilter implements Filter {
FastDateFormat df = FastDateFormat.getInstance("MM-dd-yyyy hh:mm:ss z");
Expand Down Expand Up @@ -59,8 +60,7 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
long languageId = WebAPILocator.getLanguageWebAPI().getLanguage(request).getId();

String queryString = request.getQueryString();
boolean adminMode = (request.getSession(false) != null && request.getSession().getAttribute(
com.dotmarketing.util.WebKeys.ADMIN_MODE_SESSION) != null);
boolean adminMode = PageMode.get(request) .isAdmin;
String referer = request.getHeader("Referer");
StringWriter sw = new StringWriter();
sw.append("url:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.Role;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageMode;

import com.liferay.portal.model.User;
import com.liferay.portal.struts.Action;
import com.liferay.portal.struts.ActionException;
Expand Down Expand Up @@ -84,11 +86,7 @@ public void run(HttpServletRequest request, HttpServletResponse response)
Logger.warn(this, "ERROR: "+e.getMessage());
}

//Enabling pages edit mode
HttpSession session = request.getSession();
session.setAttribute(com.dotmarketing.util.WebKeys.EDIT_MODE_SESSION, "true");
session.setAttribute(com.dotmarketing.util.WebKeys.PREVIEW_MODE_SESSION, null);
session.setAttribute(com.dotmarketing.util.WebKeys.ADMIN_MODE_SESSION, "true");
PageMode.setPageMode(request, PageMode.EDIT);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
import com.dotmarketing.util.DateUtil;
import com.dotmarketing.util.InodeUtils;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageRequestModeUtil;
import com.dotmarketing.util.PageMode;

import com.dotmarketing.util.PaginatedArrayList;
import com.dotmarketing.util.RegEX;
import com.dotmarketing.util.RegExMatch;
Expand Down Expand Up @@ -1426,8 +1427,8 @@ public Map<String,Object> saveContent(List<String> formData, boolean isAutoSave,
iCanLock=false;
contentLocked = false;
}
PageRequestModeUtil.setBackEndModeInSession(req, contentLocked, iCanLock);
PageMode.setPageMode(req, contentLocked, iCanLock);

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.dotmarketing.util.CookieUtil;
import com.dotmarketing.util.InodeUtils;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageMode;
import com.dotmarketing.util.RegEX;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.VelocityUtil;
Expand Down Expand Up @@ -711,10 +712,8 @@ public String getHTML(String uri, Host host, boolean liveMode, String contentId,


if (!liveMode) {
requestProxy.setAttribute(WebKeys.PREVIEW_MODE_SESSION, "true");
requestProxy.getSession().setAttribute(WebKeys.PREVIEW_MODE_SESSION, "true");
requestProxy.setAttribute(WebKeys.ADMIN_MODE_SESSION, "true");
requestProxy.getSession().setAttribute(WebKeys.ADMIN_MODE_SESSION, "true");
requestProxy.setAttribute(WebKeys.PAGE_MODE_SESSION, PageMode.PREVIEW);
requestProxy.setAttribute(WebKeys.PAGE_MODE_SESSION, PageMode.PREVIEW);
}
boolean signedIn = false;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dotmarketing.portlets.htmlpages.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


import com.dotcms.repackage.javax.portlet.ActionRequest;
import com.dotcms.repackage.javax.portlet.ActionResponse;
Expand All @@ -20,7 +20,8 @@
import com.dotmarketing.util.ActivityLogger;
import com.dotmarketing.util.HostUtil;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageRequestModeUtil;
import com.dotmarketing.util.PageMode;

import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.WebKeys;
import com.liferay.portal.language.LanguageUtil;
Expand Down Expand Up @@ -87,7 +88,8 @@ public void processAction(ActionMapping mapping, ActionForm form, PortletConfig
HttpServletRequest hreq = reqImpl.getHttpServletRequest();

// gets the session object for the messages
PageRequestModeUtil.setBackEndModeInSession(hreq, contentLocked, iCanLock);
PageMode.setPageMode(hreq, contentLocked, iCanLock);


IHTMLPage htmlPage = _previewHTMLPages(req, user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws Servl
try {
User user = userWebAPI.getLoggedInUser(req);
boolean respectFrontendRoles = !userWebAPI.isLoggedToBackend(req);

PageMode mode = PageMode.get(req);
//If session is in Admin Mode (Edit Mode) we should respect front end roles also.
if(session != null && session.getAttribute(com.dotmarketing.util.WebKeys.ADMIN_MODE_SESSION) != null){
if(mode.isAdmin){
respectFrontendRoles = true;
}

Expand All @@ -204,23 +204,10 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws Servl
assetIdentifier = content.getIdentifier();
} else {
boolean live=userWebAPI.isLoggedToFrontend(req);
boolean PREVIEW_MODE = false;
boolean EDIT_MODE = false;

if(session != null) {
PREVIEW_MODE = ((session.getAttribute(com.dotmarketing.util.WebKeys.PREVIEW_MODE_SESSION) != null));
try {
EDIT_MODE = (((session.getAttribute(com.dotmarketing.util.WebKeys.EDIT_MODE_SESSION) != null)));
} catch (Exception e) {
Logger.error(this, "Error: Unable to determine if there's a logged user.", e);
}
}

//GIT-4506
if(WebAPILocator.getUserWebAPI().isLoggedToBackend(req)){
if(!EDIT_MODE && !PREVIEW_MODE)// LIVE_MODE
live = true;
else
live = false;
live = mode.showLive;
}

if (req.getSession(false) != null && req.getSession().getAttribute("tm_date")!=null) {
Expand Down Expand Up @@ -381,16 +368,10 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws Servl

} else {

boolean _adminMode = false;
try {
_adminMode = (session!=null && session.getAttribute(com.dotmarketing.util.WebKeys.ADMIN_MODE_SESSION) != null);
}catch(Exception e){
Logger.warn(this, "An unexpected problem happened when trying to retrieve the backend session");
Logger.debug(this, "Something happened!", e);
}


// Set the expiration time
if (!_adminMode) {
if (!mode.isAdmin) {

int _daysCache = 365;
GregorianCalendar expiration = new GregorianCalendar();
Expand Down
Loading