Skip to content

Commit

Permalink
EEA / Streamlining publication and groups - issue metadata unpublicat…
Browse files Browse the repository at this point in the history
…ion event when removing ALL group privileges from privileges dialog
  • Loading branch information
josegar74 committed Feb 29, 2024
1 parent acb5203 commit d43bc82
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.fao.geonet.events.history.RecordGroupOwnerChangeEvent;
import org.fao.geonet.events.history.RecordOwnerChangeEvent;
import org.fao.geonet.events.history.RecordPrivilegesChangeEvent;
import org.fao.geonet.events.md.MetadataUnpublished;
import org.fao.geonet.kernel.AccessManager;
import org.fao.geonet.kernel.DataManager;
import org.fao.geonet.kernel.datamanager.*;
Expand All @@ -63,6 +64,8 @@
import org.fao.geonet.util.WorkflowUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -91,7 +94,7 @@
@PreAuthorize("hasAuthority('Editor')")
@Controller("recordSharing")
@ReadWriteController
public class MetadataSharingApi {
public class MetadataSharingApi implements ApplicationEventPublisherAware {
private static final String DEFAULT_PUBLICATION_TYPE_NAME = "default";

@Autowired
Expand Down Expand Up @@ -157,6 +160,13 @@ public class MetadataSharingApi {
@Autowired
private IPublicationConfig publicationConfig;

private ApplicationEventPublisher eventPublisher;

@Override
public void setApplicationEventPublisher(
ApplicationEventPublisher applicationEventPublisher) {
this.eventPublisher = applicationEventPublisher;
}
public static Vector<OperationAllowedId> retrievePrivileges(ServiceContext context, String id, Integer userId, Integer groupId) {

OperationAllowedRepository opAllowRepo = context.getBean(OperationAllowedRepository.class);
Expand Down Expand Up @@ -549,6 +559,12 @@ private void setOperations(
}
}

if (sharing.isClear() && !metadataUtils.isMetadataPublished(metadata.getId())) {
// Throw the metadata unpublish event, as when removing privileges, are not part of the parameters,
// not processed in setOperation / unsetOperation that triggers the metadata publish/unpublish events
eventPublisher.publishEvent(new MetadataUnpublished(metadata));
}

if (notifyByMail) {
java.util.Optional<GroupPrivilege> allGroupPrivsBefore =
sharingBefore.getPrivileges().stream().filter(p -> p.getGroup() == ReservedGroup.all.getId()).findFirst();
Expand Down

0 comments on commit d43bc82

Please sign in to comment.