Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dotCMS/core into issue-13469-impr…
Browse files Browse the repository at this point in the history
…ovements-for-lang-content-wf-task
  • Loading branch information
Jonathan authored and Jonathan committed Feb 15, 2018
2 parents d2a2d43 + 01dffbc commit ad4eea3
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.dotcms.rest.annotation.NoCache;
import com.dotcms.rest.exception.ForbiddenException;
import com.dotcms.rest.exception.mapper.ExceptionMapperUtil;
import com.dotmarketing.beans.Identifier;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.util.SecurityLogger;
Expand Down Expand Up @@ -113,6 +114,14 @@ public final Response authentication(@Context final HttpServletRequest request,
final Map<String, Object> userMap = user.toMap();

userMap.put("loggedInDate", new Date());

Identifier editModeId = (Identifier) request.getSession().getAttribute(WebKeys.LOGIN_TO_EDIT_MODE);

if (editModeId != null) {
userMap.put("editModeUrl", editModeId.getURI());
request.getSession().removeAttribute(WebKeys.LOGIN_TO_EDIT_MODE);
}

res = Response.ok(new ResponseEntityView(userMap)).build(); // 200
request.getSession().setAttribute(Globals.LOCALE_KEY, locale);
} else {
Expand Down
44 changes: 34 additions & 10 deletions dotCMS/src/main/java/com/dotcms/rest/api/v1/page/PageResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
import com.dotmarketing.beans.Host;
import com.dotmarketing.beans.MultiTree;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.PermissionAPI;
import com.dotmarketing.business.PermissionLevel;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.factories.MultiTreeFactory;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.contentlet.model.ContentletVersionInfo;
import com.dotmarketing.portlets.htmlpageasset.business.HTMLPageAssetAPI;
import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset;
import com.dotmarketing.portlets.htmlpageasset.model.IHTMLPage;
import com.dotmarketing.portlets.templates.business.TemplateAPI;
import com.dotmarketing.portlets.templates.model.Template;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageMode;
Expand Down Expand Up @@ -68,19 +71,24 @@ public class PageResource {

private final PageResourceHelper pageResourceHelper;
private final WebResource webResource;
private final TemplateAPI templateAPI;
private final PermissionAPI permissionAPI;

/**
* Creates an instance of this REST end-point.
*/
public PageResource() {
this(PageResourceHelper.getInstance(), new WebResource());
this(PageResourceHelper.getInstance(), new WebResource(), APILocator.getTemplateAPI(),
APILocator.getPermissionAPI());
}

@VisibleForTesting
protected PageResource(final PageResourceHelper pageResourceHelper, final WebResource
webResource) {
protected PageResource(final PageResourceHelper pageResourceHelper, final WebResource webResource,
TemplateAPI templateAPI, PermissionAPI permissionAPI) {
this.pageResourceHelper = pageResourceHelper;
this.webResource = webResource;
this.templateAPI = templateAPI;
this.permissionAPI = permissionAPI;
}

/**
Expand Down Expand Up @@ -226,28 +234,44 @@ public Response renderHTMLOnly(@Context final HttpServletRequest request,
try {


final HTMLPageAsset page = (UUIDUtil.isUUID(uri)) ? (HTMLPageAsset) APILocator.getHTMLPageAssetAPI().findPage(uri, user, mode.respectAnonPerms) : this.pageResourceHelper.getPage(request, user, uri, mode);

final HTMLPageAsset page = (UUIDUtil.isUUID(uri)) ?
(HTMLPageAsset) APILocator.getHTMLPageAssetAPI().findPage(uri, user, mode.respectAnonPerms) :
this.pageResourceHelper.getPage(request, user, uri, mode);

final Template template = this.templateAPI.findWorkingTemplate(page.getTemplateId(), user, false);

final ContentletVersionInfo info = APILocator.getVersionableAPI().getContentletVersionInfo(page.getIdentifier(), page.getLanguageId());
final Builder<String, Object> pageMapBuilder = ImmutableMap.builder();
final boolean canLock = APILocator.getContentletAPI().canLock(page, user);
final String lockedBy= (info.getLockedBy()!=null) ? info.getLockedBy() : null;
final String lockedUserName = (info.getLockedBy()!=null) ? APILocator.getUserAPI().loadUserById(info.getLockedBy()).getFullName() : null;


Host host = APILocator.getHostAPI().find(page.getHost(), user, mode.respectAnonPerms);
final Host host = APILocator.getHostAPI().find(page.getHost(), user, mode.respectAnonPerms);

request.setAttribute(WebKeys.CURRENT_HOST, host);
request.getSession().setAttribute(WebKeys.CURRENT_HOST, host);
final ObjectWriter objectWriter = JsonMapper.mapper.writer().withDefaultPrettyPrinter();
final String html = this.pageResourceHelper.getPageRendered(page, request, response, user, mode);

final boolean editPermission = this.permissionAPI.doesUserHavePermission(page, PermissionLevel.EDIT.getType(), user);

pageMapBuilder.put("render",html )
.put("canLock", canLock)
.put("workingInode", info.getWorkingInode())
.put("shortyWorking", APILocator.getShortyAPI().shortify(info.getWorkingInode()));
pageMapBuilder.putAll(page.getMap());


final Map<String, Object> pageMap = new HashMap(page.getMap());
final String templateIdentifier = (String) pageMap.get(HTMLPageAssetAPI.TEMPLATE_FIELD);
pageMap.remove(HTMLPageAssetAPI.TEMPLATE_FIELD);

pageMapBuilder.putAll(pageMap);

final ImmutableMap<Object, Object> templateMap = ImmutableMap.builder().put("drawed", template.isDrawed())
.put("canEdit", editPermission)
.put("id", templateIdentifier)
.build();

pageMapBuilder.put("template", templateMap);

if(lockedBy!=null) {
pageMapBuilder.put("lockedOn", info.getLockedOn())
.put("lockedBy", lockedBy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ private PageView getPageMetadata(final HttpServletRequest request, final HttpSer
final Template template = mode.showLive ? (Template) this.versionableAPI.findLiveVersion(page.getTemplateId(), user, mode.respectAnonPerms) :
(Template) this.versionableAPI.findWorkingVersion(page.getTemplateId(), user, mode.respectAnonPerms);

final TemplateLayout layout = DotTemplateTool.themeLayout(template.getInode());
TemplateLayout layout = null;

if (template.isDrawed()) {
layout = DotTemplateTool.themeLayout(template.getInode());
}

final Map<String, ContainerView> mappedContainers = this.getMappedContainers(template, user);

Expand Down Expand Up @@ -381,7 +385,8 @@ private Template getTemplate(IHTMLPage page, User user, PageForm form) throws Do
saveTemplate.setTitle(form.getTitle());
saveTemplate.setTheme((form.getThemeId()==null) ? oldTemplate.getTheme() : form.getThemeId());
saveTemplate.setDrawedBody(form.getLayout());

saveTemplate.setDrawed(true);

return saveTemplate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ public interface CategoryAPI {
* Determines if a givenParent is parent/grandParent/... and so on of a givenSon, recursively
*/
public boolean isParent(Category givenChild, Category givenParent, User user);

/**
* Determines if a givenParent is parent/grandParent/... and so on of a givenSon, recursively
*/
public boolean isParent(Category givenChild, Category givenParent, User user, boolean respectFrontendRoles);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,12 +644,16 @@ private PaginatedCategories getCategoriesSubList(int start, int count, List<Cate
}

public boolean isParent(Category givenChild, Category givenParent, User user) {
return isParent(givenChild,givenParent,user,false);
}

public boolean isParent(Category givenChild, Category givenParent, User user, boolean respectFrontendRoles) {


List<Category> parents;

try {
parents = getParents(givenChild, user, false);
parents = getParents(givenChild, user, respectFrontendRoles);

if(parents==null || parents.isEmpty()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static Map<String, Object> getContentPrintableMap(User user, Contentlet c
final List<Category> childCategories = new ArrayList<>();
for (Category category : cats) {

if (APILocator.getCategoryAPI().isParent(category, parentCategory, user)) {
if (APILocator.getCategoryAPI().isParent(category, parentCategory, user,true)) {

childCategories.add(category);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ private String deleteSpecialCharacter(String fileName) throws IOException {
fileName = fileName.replace("<", "");
fileName = fileName.replace(">", "");
fileName = fileName.replace("|", "");
fileName = fileName.replace("+", " ");
if (!UtilMethods.isSet(fileName)) {
throw new IOException(
"Please specify a name without special characters \\/:*?\"<>|");
Expand Down
18 changes: 10 additions & 8 deletions dotCMS/src/main/java/com/liferay/portal/action/LayoutAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,19 @@ public ActionForward execute(
// }else{
_processActionRequest(req, res);

ActionResponseImpl actionResponse =
(ActionResponseImpl)req.getAttribute(
WebKeys.JAVAX_PORTLET_RESPONSE);
if (!Boolean.parseBoolean(req.getParameter("isNg"))) {
ActionResponseImpl actionResponse =
(ActionResponseImpl) req.getAttribute(
WebKeys.JAVAX_PORTLET_RESPONSE);

String redirectLocation =
actionResponse.getRedirectLocation();
String redirectLocation =
actionResponse.getRedirectLocation();

if (Validator.isNotNull(redirectLocation)) {
res.sendRedirect(SecurityUtils.stripReferer(req, redirectLocation));
if (Validator.isNotNull(redirectLocation)) {
res.sendRedirect(SecurityUtils.stripReferer(req, redirectLocation));

return null;
return null;
}
}

String windowState = req.getParameter("p_p_state");
Expand Down
2 changes: 2 additions & 0 deletions dotCMS/src/main/java/com/liferay/portal/util/WebKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,6 @@ public class WebKeys {
public static final String POPUP = "popup";
public static final String AJAX_PORTLET = "ajax_portlet";
public static final String HIDE_SUBNAV = "hide_subnav";

public static final String LOGIN_TO_EDIT_MODE = "LOGIN_TO_EDIT_MODE";
}
8 changes: 4 additions & 4 deletions dotCMS/src/main/webapp/WEB-INF/messages/Language.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4649,6 +4649,8 @@ system.locale.language.inputs.language.options.zu=Zulu
## Content Types
contenttypes.content.fileasset=File
contenttypes.content.content=Content
contenttypes.content.edit.contenttype=Edit {0}
contenttypes.content.create.contenttype=Create {0}
contenttypes.content.contenttype=content type
contenttypes.content.form=Form
contenttypes.content.persona=Persona
Expand Down Expand Up @@ -4726,7 +4728,6 @@ contenttypes.tab.relationship.header=Relationship
contenttypes.tab.publisher.push.history.header=Push History
contenttypes.fieldname.structure.name=Content Type Name
contenttypes.fieldname.entries=Entries
contenttypes.form.name.error.required=Name is required

contenttypes.relationship.select.current.contentType.error=Must select {0} as parent o child Content Type

Expand Down Expand Up @@ -4881,6 +4882,7 @@ editpage.toolbar.primary.action=Save
editpage.toolbar.secondary.action=Cancel
editpage.toolbar.nav.content=Content
editpage.toolbar.nav.layout=Layout
editpage.toolbar.nav.code=Code
editpage.toolbar.edit.page=Edit
editpage.toolbar.preview.page=Preview
editpage.toolbar.live.page=Live
Expand Down Expand Up @@ -4922,6 +4924,4 @@ dot.common.message.locking=Locking...
dot.common.message.locked=Locked
dot.common.message.unlocking=Unlocking...
dot.common.message.unlocked=Unlocked

# Common Validation Messages
common.validation.name.error.required=Name is required
dot.common.message.field.required={0} is required
8 changes: 6 additions & 2 deletions dotCMS/src/main/webapp/html/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ function stripCarriageReturn(s) {
return s.replace(/\r|\n|\r\n/g, " ");
}

function submitForm(form, action, singleSubmit) {
function submitForm(form, action, singleSubmit, callback) {
if (submitFormCount == 0) {
if (singleSubmit == null || singleSubmit) {
submitFormCount++;
Expand All @@ -727,7 +727,11 @@ function submitForm(form, action, singleSubmit) {
form.action = action;
}

form.submit();
form.submit();

if (callback) {
callback();
}
}
else {
if (this.submitFormAlert != null) {
Expand Down
2 changes: 0 additions & 2 deletions dotCMS/src/main/webapp/html/ng-contentlet-selector.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
contentTypes = APILocator.getContainerAPI().getContentTypesInContainer(container);
}
contentTypes = new ArrayList<>(contentTypes);
contentTypes.addAll(APILocator.getContentTypeAPI(user).findByType(BaseContentType.WIDGET));
Layout contentLayout = APILocator.getLayoutAPI().findLayoutByName("Content");
String containerStructures = "[";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@
if((data["referer"] != null && data["referer"] != '' && !data["contentletLocked"]) || data["htmlPageReferer"] != null ) {
if(data["isHtmlPage"]){
self.location = data["htmlPageReferer"];
window.top.location = '/dotAdmin/#/edit-page/content?url=' + data["htmlPageReferer"];
} else if(data["sourceReferer"]){
self.location = data["referer"] + "&content_inode=" + data["contentletInode"]+"&referer=" + escape(data["sourceReferer"]);
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,17 @@
dojo.require('dotcms.dojo.data.ContainerReadStore');
var referer = '<%=referer%>';
var isNg = '<%=request.getParameter("ng") %>' === 'true';
function submitfm(form,subcmd) {
var customEvent = document.createEvent("CustomEvent");
customEvent.initCustomEvent("ng-event", false, false, {
name: "advanced-template-saving",
data: {}
});
document.dispatchEvent(customEvent);
window.onbeforeunload=true;
if(dijit.byId("toggleEditor").checked){
document.getElementById("bodyField").value=editor.getValue();
Expand All @@ -107,8 +116,26 @@
}
form.cmd.value = '<%=Constants.ADD%>';
form.subcmd.value = subcmd;
form.action = '<portlet:actionURL><portlet:param name="struts_action" value="/ext/templates/edit_template" /></portlet:actionURL>';
submitForm(form);
form.action = '<portlet:actionURL><portlet:param name="struts_action" value="/ext/templates/edit_template" /></portlet:actionURL>';
if (isNg) {
var data = new URLSearchParams(new FormData(form)).toString();
var req = new XMLHttpRequest();
req.open("POST", form.action, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
customEvent.initCustomEvent("ng-event", false, false, {
name: "advanced-template-saved",
data: {}
});
document.dispatchEvent(customEvent);
}
};
req.send(data);
} else {
submitForm(form);
}
}
var copyAsset = false;
Expand Down Expand Up @@ -254,7 +281,6 @@
</script>

<script language="JavaScript" src="/html/js/cms_ui_utils.js"></script>

<liferay:box top="/html/common/box_top.jsp" bottom="/html/common/box_bottom.jsp">
<liferay:param name="box_title" value="<%= LanguageUtil.get(pageContext, \"edit-template\") %>" />
Expand All @@ -265,7 +291,7 @@
<input name="subcmd" type="hidden" value="">
<input name="userId" type="hidden" value="<%= user.getUserId() %>">
<input name="admin_l_list" type="hidden" value="">
<input name="isNg" type="hidden" value='<%=request.getParameter("ng") %>'>
<div class="portlet-main" style="height:100vh;border:0px solid red;">
<!-- START TabContainer-->
Expand Down Expand Up @@ -457,9 +483,11 @@
</a>
<% } %>
<a onClick="cancelEdit()" >
<%= UtilMethods.escapeSingleQuotes(LanguageUtil.get(pageContext, "cancel")) %>
</a>
<% if (request.getParameter("ng") == null) { %>
<a onClick="cancelEdit()" >
<%= UtilMethods.escapeSingleQuotes(LanguageUtil.get(pageContext, "cancel")) %>
</a>
<% } %>
</div>
</div>
</div>
Expand Down

0 comments on commit ad4eea3

Please sign in to comment.