Skip to content

Commit

Permalink
fixing bug #11421 : attachments of publication public version are not…
Browse files Browse the repository at this point in the history
… in 'read-only' mode
  • Loading branch information
NicolasEYSSERIC committed Mar 17, 2020
1 parent 6f5cf7f commit 19e5018
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Expand Up @@ -246,7 +246,8 @@
showMenuNotif="${showMenuNotif}"
useWebDAV="${webdavEditingEnable}"
useXMLForm="${useXMLForm}"
fromAlias="${fromAlias}" />
fromAlias="${fromAlias}"
userRole="${highestUserRole}"/>
<span class="lineMain ${forbiddenDownloadClass}">
<img id='edit_<c:out value="${currentAttachment.oldSilverpeasId}"/>' src='<c:url value="/util/icons/arrow/menuAttachment.gif" />' class="moreActions"/>
<c:if test="${showIcon}">
Expand Down
Expand Up @@ -24,6 +24,7 @@
package org.silverpeas.core.web.attachment.tag;

import org.apache.commons.lang3.StringEscapeUtils;
import org.silverpeas.core.admin.user.model.SilverpeasRole;
import org.silverpeas.core.admin.user.model.User;
import org.silverpeas.core.admin.user.model.UserDetail;
import org.silverpeas.core.contribution.attachment.model.SimpleDocument;
Expand Down Expand Up @@ -53,6 +54,7 @@ public class SimpleDocumentContextualMenu extends TagSupport {
private boolean useWebDAV;
private boolean showMenuNotif;
private boolean fromAlias;
private SilverpeasRole userRole;

private static final String TEMPLATE = "oMenu%s.getItem(%s).cfg.setProperty(\"disabled\", %s);";

Expand Down Expand Up @@ -80,6 +82,8 @@ public void setFromAlias(final boolean fromAlias) {
this.fromAlias = fromAlias;
}

public void setUserRole(final SilverpeasRole userRole) { this.userRole = userRole; }

@Override
public int doStartTag() throws JspException {
try {
Expand All @@ -89,7 +93,7 @@ public int doStartTag() throws JspException {
LocalizationBundle messages = ResourceLocator.getLocalizationBundle(
"org.silverpeas.util.attachment.multilang.attachment", favoriteLanguage);
UserDetail user = mainSessionController.getCurrentUserDetail();
if (!fromAlias && attachment.canBeModifiedBy(user)) {
if (!fromAlias && canBeModified(user)) {
pageContext.getOut().print(
prepareActions(attachment, useXMLForm, useWebDAV, user,
favoriteLanguage, messages, showMenuNotif));
Expand All @@ -108,6 +112,11 @@ public int doEndTag() throws JspException {
return EVAL_PAGE;
}

boolean canBeModified(UserDetail user) {
return (userRole != null && userRole.isGreaterThanOrEquals(SilverpeasRole.writer)) &&
attachment.canBeModifiedBy(user);
}

boolean isAdmin(User user) {
return user.isAccessAdmin();
}
Expand Down
9 changes: 8 additions & 1 deletion core-web/src/main/resources/META-INF/contextMenu.tld
Expand Up @@ -76,5 +76,12 @@
<rtexprvalue>true</rtexprvalue>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description>To indicate the current role.</description>
<name>userRole</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>org.silverpeas.core.admin.user.model.SilverpeasRole</type>
</attribute>
</tag>
</taglib>
</taglib>

0 comments on commit 19e5018

Please sign in to comment.