Skip to content

Commit 12c84a7

Browse files
committed
Report of the fix of the bug #14663
1 parent d82a619 commit 12c84a7

File tree

7 files changed

+61
-66
lines changed

7 files changed

+61
-66
lines changed

kmelia/kmelia-library/src/main/java/org/silverpeas/components/kmelia/KmeliaPublicationHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static boolean isRemovable(String instanceId, String currentUserId, Strin
5252
if (hasWritePrivilege(currentUserId, profile, ownerDetail)) {
5353
boolean removeOnlyForAdmin = StringUtil.getBooleanValue(
5454
getParameterValue(instanceId, InstanceParameters.suppressionOnlyForAdmin));
55-
return !removeOnlyForAdmin || "admin".equals(profile);
55+
return !removeOnlyForAdmin || SilverpeasRole.ADMIN.getName().equals(profile);
5656
}
5757
return false;
5858
}

kmelia/kmelia-war/src/main/java/org/silverpeas/components/kmelia/control/KmeliaSessionController.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,14 @@ public boolean isSuppressionOnlyForAdmin() {
478478
return StringUtil.getBooleanValue(getComponentParameterValue("suppressionOnlyForAdmin"));
479479
}
480480

481+
public boolean isSuppressionAllowed(String profile) {
482+
SilverpeasRole role = SilverpeasRole.fromString(profile);
483+
boolean modifPrivilege = role == SilverpeasRole.ADMIN || role == SilverpeasRole.PUBLISHER ||
484+
role == SilverpeasRole.SUPERVISOR;
485+
return (!isSuppressionOnlyForAdmin() && modifPrivilege)
486+
|| (isSuppressionOnlyForAdmin() && role == SilverpeasRole.ADMIN);
487+
}
488+
481489
public boolean isContentEnabled() {
482490
String parameterValue = getComponentParameterValue("tabContent");
483491
if (!StringUtil.isDefined(parameterValue)) {

kmelia/kmelia-war/src/main/java/org/silverpeas/components/kmelia/servlets/JSONServlet.java

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,18 @@ public void doPost(HttpServletRequest req, HttpServletResponse res) {
8686
private String getOperations(String id, KmeliaSessionController kmeliaSC) {
8787
return JSONCodec.encodeObject(operations -> {
8888

89+
String profile = kmeliaSC.getUserTopicProfile(id);
8990
if (KmeliaHelper.isNonVisiblePubsFolder(id)) {
90-
operations.put(OP_DELETE_PUBLICATIONS, true);
91+
operations.put(OP_DELETE_PUBLICATIONS, kmeliaSC.isSuppressionAllowed(profile));
9192
operations.put(OP_EXPORT_PUBLICATIONS, true);
9293
} else {
9394
// getting profile
94-
String profile = kmeliaSC.getUserTopicProfile(id);
9595
NodeDetail folder = kmeliaSC.getNodeHeader(id);
96-
97-
// getting operations of topic according to profile and current
98-
boolean isAdmin = SilverpeasRole.ADMIN.isInRole(profile);
99-
boolean isPublisher = SilverpeasRole.PUBLISHER.isInRole(profile);
100-
boolean isWriter = SilverpeasRole.WRITER.isInRole(profile);
101-
boolean isUser = SilverpeasRole.USER.isInRole(profile);
96+
Role role = new Role(profile);
10297
boolean isRoot = NodePK.ROOT_NODE_ID.equals(id);
10398
boolean isInBasket = folder.getFullPath().contains("/" + NodePK.BIN_NODE_ID + "/");
104-
Role role = new Role().setAdmin(isAdmin).setPublisher(isPublisher).setWriter(isWriter)
105-
.setUser(isUser);
106-
10799
if (isInBasket) {
108-
addBasketOperations(operations, role, folder);
100+
addBasketOperations(kmeliaSC, operations, role, folder);
109101
} else if (StringUtil.isDefined(profile)) {
110102
UserDetail user = kmeliaSC.getUserDetail();
111103
// general operations
@@ -130,7 +122,8 @@ private void addPublicationOperations(final KmeliaSessionController kmeliaSC,
130122
!isRoot || (kmeliaSC.getNbPublicationsOnRoot() == 0 || !kmeliaSC.isTreeStructure());
131123
boolean addPublicationAllowed = !role.isUser() && publicationsInTopic;
132124
boolean operationsOnSelectionAllowed =
133-
(role.isAdmin() || role.isPublisher()) && publicationsInTopic;
125+
(role.isAdmin() || role.isPublisher()) && publicationsInTopic &&
126+
kmeliaSC.isSuppressionAllowed(role.toString());
134127
boolean somePublicationsExist = ofNullable(kmeliaSC.getSessionPublicationsList())
135128
.filter(not(Collection::isEmpty))
136129
.isPresent();
@@ -161,6 +154,10 @@ private void addPublicationOperations(final KmeliaSessionController kmeliaSC,
161154
operations.put("topicSubscriptions", notRootNotAnonymousNotGuest);
162155
operations.put("favorites", notRootNotAnonymousNotGuest);
163156

157+
addPublicationSelectionOperation(kmeliaSC, operations, operationsOnSelectionAllowed);
158+
}
159+
160+
private static void addPublicationSelectionOperation(KmeliaSessionController kmeliaSC, JSONCodec.JSONObject operations, boolean operationsOnSelectionAllowed) {
164161
if (kmeliaSC.isAllPublicationsListSelected()) {
165162
operations.put("unselectAllPublications", operationsOnSelectionAllowed);
166163
} else {
@@ -216,15 +213,17 @@ private void addGeneralOperations(final KmeliaSessionController kmeliaSC,
216213
operations.put("responsibles", !user.isAnonymous());
217214
}
218215

219-
private void addBasketOperations(final JSONCodec.JSONObject operations, final Role role,
216+
private void addBasketOperations(final KmeliaSessionController kmeliaSc,
217+
final JSONCodec.JSONObject operations, final Role role,
220218
NodeDetail node) {
221219
boolean binOperationsAllowed = role.isAdmin() || role.isPublisher() || role.isWriter();
222220
boolean isAdmin = role.isAdmin();
223-
operations.put("emptyTrash", binOperationsAllowed);
221+
boolean suppressionAllowed = kmeliaSc.isSuppressionAllowed(role.toString());
222+
operations.put("emptyTrash", binOperationsAllowed && suppressionAllowed);
224223
operations.put(OP_EXPORT_PUBLICATIONS, binOperationsAllowed);
225224
operations.put("copyPublications", binOperationsAllowed);
226225
operations.put("cutPublications", binOperationsAllowed);
227-
operations.put(OP_DELETE_PUBLICATIONS, binOperationsAllowed);
226+
operations.put(OP_DELETE_PUBLICATIONS, binOperationsAllowed && suppressionAllowed);
228227
if (!node.isBin()) {
229228
operations.put("deleteTopic", isAdmin);
230229
operations.put("copyTopic", isAdmin);
@@ -234,45 +233,32 @@ private void addBasketOperations(final JSONCodec.JSONObject operations, final Ro
234233

235234
private static class Role {
236235

237-
private boolean admin;
238-
private boolean publisher;
239-
private boolean writer;
240-
private boolean user;
236+
private final SilverpeasRole silverRole;
241237

242-
public boolean isAdmin() {
243-
return admin;
238+
public Role(final String profile) {
239+
this.silverRole = SilverpeasRole.fromString(profile);
244240
}
245241

246-
public Role setAdmin(final boolean admin) {
247-
this.admin = admin;
248-
return this;
242+
public boolean isAdmin() {
243+
return silverRole == SilverpeasRole.ADMIN;
249244
}
250245

251246
public boolean isPublisher() {
252-
return publisher;
247+
return this.silverRole == SilverpeasRole.PUBLISHER;
253248
}
254249

255-
public Role setPublisher(final boolean publisher) {
256-
this.publisher = publisher;
257-
return this;
258-
}
259250

260251
public boolean isWriter() {
261-
return writer;
262-
}
263-
264-
public Role setWriter(final boolean writer) {
265-
this.writer = writer;
266-
return this;
252+
return this.silverRole == SilverpeasRole.WRITER;
267253
}
268254

269255
public boolean isUser() {
270-
return user;
256+
return this.silverRole == SilverpeasRole.USER;
271257
}
272258

273-
public Role setUser(final boolean user) {
274-
this.user = user;
275-
return this;
259+
@Override
260+
public String toString() {
261+
return silverRole.getName();
276262
}
277263
}
278264
}

kmelia/kmelia-war/src/main/webapp/kmelia/jsp/basket.jsp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ $(document).ready(function() {
9797
9898
//Display operations
9999
OperationPane operationPane = window.getOperationPane();
100-
operationPane.addOperation("useless", resources.getString("EmptyBasket"), "javascript:onClick=emptyTrash()");
101-
100+
if (kmeliaScc.isSuppressionAllowed(kmeliaScc.getProfile())) {
101+
operationPane.addOperation("useless", resources.getString("EmptyBasket"), "javascript:onClick=emptyTrash()");
102+
}
102103
out.println(window.printBefore());
103104
%>
104105
<view:frame>

kmelia/kmelia-war/src/main/webapp/kmelia/jsp/publicationManager.jsp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<%@ page import="java.util.Date" %>
4242
<%@ page import="java.util.StringTokenizer" %>
4343
<%@ page import="org.silverpeas.core.contribution.model.Thumbnail" %>
44+
<%@ page import="org.silverpeas.components.kmelia.KmeliaPublicationHelper" %>
4445

4546
<c:set var="userLanguage" value="${requestScope.resources.language}"/>
4647
<fmt:setLocale value="${userLanguage}"/>
@@ -138,19 +139,11 @@
138139
action = "UpdateView";
139140
isOwner = true;
140141
} else {
141-
if (profile.equals("admin") || profile.equals("publisher") || profile.equals("supervisor") || (ownerDetail != null && kmeliaScc.getUserDetail().getId().equals(ownerDetail.getId()) && profile.equals("writer"))) {
142-
isOwner = true;
143-
144-
if (!kmeliaScc.isSuppressionOnlyForAdmin() || (profile.equals("admin") && kmeliaScc.isSuppressionOnlyForAdmin())) {
145-
// suppressionAllowed = true car si c'est un redacteur, c'est le proprietaire de la publication
146-
suppressionAllowed = true;
147-
}
148-
} else if (!profile.equals("user") && kmeliaScc.isCoWritingEnable()) {
149-
// si publication en co-redaction, considerer qu'elle appartient aux co-redacteur au meme titre qu'au proprietaire
150-
// mais suppressionAllowed = false pour que le co-redacteur ne puisse pas supprimer la publication
151-
isOwner = true;
152-
suppressionAllowed = false;
153-
}
142+
isOwner = (ownerDetail != null &&
143+
kmeliaScc.getUserDetail().getId().equals(ownerDetail.getId()))
144+
|| (!profile.equals("user") && kmeliaScc.isCoWritingEnable());
145+
suppressionAllowed = KmeliaPublicationHelper.isRemovable(kmeliaScc.getComponentId(),
146+
kmeliaScc.getUserId(), profile, ownerDetail);
154147
155148
//modification pour acceder a l'onglet voir aussi
156149
kmeliaScc.setSessionOwner(isOwner);

kmelia/kmelia-war/src/main/webapp/kmelia/jsp/simpleListOfPublications.jsp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@
189189
operationPane.addOperation("useless", resources.getString("kmelia.operation.copyPublications"), "javascript:onclick=copyPublications()");
190190
operationPane.addOperation("useless", resources.getString("kmelia.operation.cutPublications"), "javascript:onclick=cutPublications()");
191191
operationPane.addOperation(resources.getIcon("kmelia.paste"), resources.getString("GML.paste"), "javascript:onClick=pasteFromOperations()");
192-
operationPane.addOperation("useless", resources.getString("kmelia.operation.deletePublications"), "javascript:onclick=deletePublications()");
192+
if (kmeliaScc.isSuppressionAllowed(profile)) {
193+
operationPane.addOperation("useless", resources.getString("kmelia.operation.deletePublications"), "javascript:onclick=deletePublications()");
194+
}
193195
operationPane.addLine();
194196
}
195197

kmelia/kmelia-war/src/main/webapp/kmelia/jsp/treeview.jsp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@
4848

4949
<fmt:message key="GML.ForbiddenAccessContent" var="labelForbiddenAccess"/>
5050

51-
<c:set var="folderId" value="${request.CurrentFolderId}"/>
51+
<c:set var="folderId" value="${requestScope.CurrentFolderId}"/>
5252
<c:if test="${silfn:isNotDefined(folderId)}">
5353
<c:set var="folderId" value="0"/>
5454
</c:if>
5555

5656
<%
57-
String profile = (String) request.getAttribute("Profile");
58-
String translation = (String) request.getAttribute("Language");
57+
String profile = (String) request.getAttribute("Profile");
58+
String translation = (String) request.getAttribute("Language");
5959
boolean displayNBPublis = (Boolean) request.getAttribute("DisplayNBPublis");
6060
Boolean rightsOnTopics = (Boolean) request.getAttribute("RightsOnTopicsEnabled");
6161
SearchContext searchContext = (SearchContext) request.getAttribute("SearchContext");
62-
int currentPageIndex = (Integer) request.getAttribute("PageIndex");
62+
int currentPageIndex = (Integer) request.getAttribute("PageIndex");
6363
6464
String pubIdToHighlight = (String) request.getAttribute("PubIdToHighlight"); //used when we have found publication from search (only toolbox)
6565
@@ -69,6 +69,7 @@
6969
7070
boolean userCanManageRoot = "admin".equalsIgnoreCase(profile);
7171
boolean userCanManageTopics = rightsOnTopics || "admin".equalsIgnoreCase(profile) || kmeliaScc.isTopicManagementDelegated();
72+
boolean userCanEmptyTrash = kmeliaScc.isSuppressionAllowed(profile);
7273
%>
7374
<view:sp-page>
7475
<view:sp-head-part withCheckFormScript="true">
@@ -88,6 +89,11 @@
8889
<script type="text/javascript">
8990
let isSearchTopicEnabled = ${displaySearch};
9091
92+
function canEmptyTrash(nodeType) {
93+
const isUserCanEmptyTrash = <%= userCanEmptyTrash %>;
94+
return nodeType === "bin" && isUserCanEmptyTrash;
95+
}
96+
9197
function topicGoTo(id) {
9298
closeWindows();
9399
displayTopicContent(id);
@@ -145,7 +151,7 @@
145151
return <%=KmeliaPublicationHelper.isPublicationsOnRootAllowed(componentId)%>;
146152
}
147153
148-
const icons = new Object();
154+
const icons = {};
149155
icons["permalink"] = "<%=resources.getIcon("kmelia.link")%>";
150156
icons["operation.addTopic"] = "<%=resources.getIcon("kmelia.operation.addTopic")%>";
151157
icons["operation.addPubli"] = "<%=resources.getIcon("kmelia.operation.addPubli")%>";
@@ -154,7 +160,7 @@
154160
icons["operation.subscribe"] = "<%=resources.getIcon("kmelia.operation.subscribe")%>";
155161
icons["operation.favorites"] = "<%=resources.getIcon("kmelia.operation.favorites")%>";
156162
157-
const params = new Object();
163+
const params = {};
158164
params["rightsOnTopic"] = <%=rightsOnTopics.booleanValue()%>;
159165
params["i18n"] = <%=I18NHelper.isI18nContentActivated%>;
160166
params["nbPublisDisplayed"] = <%=displayNBPublis%>;
@@ -479,16 +485,15 @@
479485
}
480486
if (isSpecialFolder(nodeType)) {
481487
return false;
482-
} else if (nodeType === "bin") {
483-
const binItems = {
488+
} else if (canEmptyTrash(nodeType)) {
489+
return {
484490
emptyItem: {
485491
label: "<%=resources.getString("EmptyBasket")%>",
486492
action: function () {
487493
emptyTrash();
488494
}
489495
}
490496
};
491-
return binItems;
492497
}
493498
494499
// The default set of all items

0 commit comments

Comments
 (0)