Skip to content

Bug #14663 #897

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

Merged
merged 1 commit into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -478,6 +478,14 @@ public boolean isSuppressionOnlyForAdmin() {
return StringUtil.getBooleanValue(getComponentParameterValue("suppressionOnlyForAdmin"));
}

public boolean isSuppressionAllowed(String profile) {
SilverpeasRole role = SilverpeasRole.fromString(profile);
boolean modifPrivilege = role == SilverpeasRole.ADMIN || role == SilverpeasRole.PUBLISHER ||
role == SilverpeasRole.SUPERVISOR;
return (!isSuppressionOnlyForAdmin() && modifPrivilege)
|| (isSuppressionOnlyForAdmin() && role == SilverpeasRole.ADMIN);
}

public boolean isContentEnabled() {
String parameterValue = getComponentParameterValue("tabContent");
if (!StringUtil.isDefined(parameterValue)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,22 @@ private String getOperations(String id, KmeliaSessionController kmeliaSC) {
return JSONCodec.encodeObject(operations -> {

if (KmeliaHelper.isNonVisiblePubsFolder(id)) {
operations.put(OP_DELETE_PUBLICATIONS, true);
String profile = kmeliaSC.getUserTopicProfile(id);
if (kmeliaSC.isSuppressionAllowed(profile)) {
operations.put(OP_DELETE_PUBLICATIONS, true);
}
operations.put(OP_EXPORT_PUBLICATIONS, true);
} else {
// getting profile
String profile = kmeliaSC.getUserTopicProfile(id);

// getting operations of topic according to profile and current
boolean isAdmin = SilverpeasRole.ADMIN.isInRole(profile);
boolean isPublisher = SilverpeasRole.PUBLISHER.isInRole(profile);
boolean isWriter = SilverpeasRole.WRITER.isInRole(profile);
boolean isUser = SilverpeasRole.USER.isInRole(profile);
Role role = new Role(profile);
boolean isRoot = NodePK.ROOT_NODE_ID.equals(id);
boolean isBasket = NodePK.BIN_NODE_ID.equals(id);
Role role = new Role().setAdmin(isAdmin).setPublisher(isPublisher).setWriter(isWriter)
.setUser(isUser);

if (isBasket) {
addBasketOperations(operations, role);
addBasketOperations(kmeliaSC, operations, role);
} else if (StringUtil.isDefined(profile)) {
NodeDetail node = kmeliaSC.getNodeHeader(id);
UserDetail user = kmeliaSC.getUserDetail();
Expand All @@ -130,7 +128,8 @@ private void addPublicationOperations(final KmeliaSessionController kmeliaSC,
!isRoot || (kmeliaSC.getNbPublicationsOnRoot() == 0 || !kmeliaSC.isTreeStructure());
boolean addPublicationAllowed = !role.isUser() && publicationsInTopic;
boolean operationsOnSelectionAllowed =
(role.isAdmin() || role.isPublisher()) && publicationsInTopic;
(role.isAdmin() || role.isPublisher()) && publicationsInTopic
&& kmeliaSC.isSuppressionAllowed(role.toString());
boolean somePublicationsExist = ofNullable(kmeliaSC.getSessionPublicationsList())
.filter(not(Collection::isEmpty))
.isPresent();
Expand Down Expand Up @@ -161,6 +160,11 @@ private void addPublicationOperations(final KmeliaSessionController kmeliaSC,
operations.put("topicSubscriptions", notRootNotAnonymousNotGuest);
operations.put("favorites", notRootNotAnonymousNotGuest);

addPublicationSelectionOperation(kmeliaSC, operations, operationsOnSelectionAllowed);
}

private static void addPublicationSelectionOperation(KmeliaSessionController kmeliaSC,
JSONCodec.JSONObject operations, boolean operationsOnSelectionAllowed) {
if (kmeliaSC.isAllPublicationsListSelected()) {
operations.put("unselectAllPublications", operationsOnSelectionAllowed);
} else {
Expand Down Expand Up @@ -216,56 +220,47 @@ private void addGeneralOperations(final KmeliaSessionController kmeliaSC,
operations.put("responsibles", !user.isAnonymous());
}

private void addBasketOperations(final JSONCodec.JSONObject operations, final Role role) {
private void addBasketOperations(final KmeliaSessionController kmeliaSC,
final JSONCodec.JSONObject operations, final Role role) {
boolean binOperationsAllowed = role.isAdmin() || role.isPublisher() || role.isWriter();
operations.put("emptyTrash", binOperationsAllowed);
boolean suppressionAllowed = kmeliaSC.isSuppressionAllowed(role.toString());
operations.put("emptyTrash", binOperationsAllowed && suppressionAllowed);
operations.put(OP_EXPORT_PUBLICATIONS, binOperationsAllowed);
operations.put("copyPublications", binOperationsAllowed);
operations.put("cutPublications", binOperationsAllowed);
operations.put(OP_DELETE_PUBLICATIONS, binOperationsAllowed);
operations.put(OP_DELETE_PUBLICATIONS, binOperationsAllowed && suppressionAllowed);
}

private static class Role {

private boolean admin;
private boolean publisher;
private boolean writer;
private boolean user;
private final SilverpeasRole silverRole;

public boolean isAdmin() {
return admin;
public Role(final String profile) {
this.silverRole = SilverpeasRole.fromString(profile);
}

public Role setAdmin(final boolean admin) {
this.admin = admin;
return this;
public boolean isAdmin() {
return silverRole == SilverpeasRole.ADMIN;
}

public boolean isPublisher() {
return publisher;
return this.silverRole == SilverpeasRole.PUBLISHER;
}

public Role setPublisher(final boolean publisher) {
this.publisher = publisher;
return this;
}

public boolean isWriter() {
return writer;
}

public Role setWriter(final boolean writer) {
this.writer = writer;
return this;
return this.silverRole == SilverpeasRole.WRITER;
}

public boolean isUser() {
return user;
return this.silverRole == SilverpeasRole.USER;
}

public Role setUser(final boolean user) {
this.user = user;
return this;
@Override
public String toString() {
return silverRole.getName();
}
}


}
4 changes: 3 additions & 1 deletion kmelia/kmelia-war/src/main/webapp/kmelia/jsp/basket.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ $(document).ready(function() {

//Display operations
OperationPane operationPane = window.getOperationPane();
operationPane.addOperation("useless", resources.getString("EmptyBasket"), "javascript:onClick=emptyTrash()");
if (kmeliaScc.isSuppressionAllowed(kmeliaScc.getProfile())) {
operationPane.addOperation("useless", resources.getString("EmptyBasket"), "javascript:onClick=emptyTrash()");
}

//Instanciation du cadre avec le view generator
Frame frame = gef.getFrame();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
if (profile.equals("admin") || profile.equals("publisher") || profile.equals("supervisor") || (ownerDetail != null && kmeliaScc.getUserDetail().getId().equals(ownerDetail.getId()) && profile.equals("writer"))) {
isOwner = true;

if (!kmeliaScc.isSuppressionOnlyForAdmin() || (profile.equals("admin") && kmeliaScc.isSuppressionOnlyForAdmin())) {
if (kmeliaScc.isSuppressionAllowed(profile)) {
// suppressionAllowed = true car si c'est un redacteur, c'est le proprietaire de la publication
suppressionAllowed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@
operationPane.addOperation("useless", resources.getString("kmelia.operation.copyPublications"), "javascript:onclick=copyPublications()");
operationPane.addOperation("useless", resources.getString("kmelia.operation.cutPublications"), "javascript:onclick=cutPublications()");
operationPane.addOperation(resources.getIcon("kmelia.paste"), resources.getString("GML.paste"), "javascript:onClick=pasteFromOperations()");
operationPane.addOperation("useless", resources.getString("kmelia.operation.deletePublications"), "javascript:onclick=deletePublications()");
if (kmeliaScc.isSuppressionAllowed(profile)) {
operationPane.addOperation("useless", resources.getString("kmelia.operation.deletePublications"), "javascript:onclick=deletePublications()");
}
operationPane.addLine();
}

Expand Down
Loading