Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/maven/fixes/9.0' into maven/rele…
Browse files Browse the repository at this point in the history
…ase/9.0
  • Loading branch information
metaventis-build committed Sep 3, 2024
2 parents eddcd23 + 3733053 commit e67e4d6
Show file tree
Hide file tree
Showing 27 changed files with 293 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

import org.alfresco.service.cmr.repository.NodeRef;

import java.util.List;

public interface EduSharingCustomPermissionService {
public EsAccessStatus hasPermission(NodeRef nodeRef);
/**
* if you want to filter which orgs should be used for the fuzzy, "local" search, you can provide a custom Service
* */
default List<String> getLocalOrganizations(List<String> allOrganizations) {
return allOrganizations;
}

/*default EsAccessStatus hasPermission(NodeRef nodeRef) {
return null;
}*/

/*
enum EsAccessStatus {
// access is granted
Expand All @@ -15,4 +27,8 @@ enum EsAccessStatus {
// should not be allowed to grant access afterwards
DENIED_ENFORCE
}
*/



}
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,15 @@ public void updateNode(String nodeId, Map props, List<String> propertiesToRemove
serviceRegistry.getTransactionService().getRetryingTransactionHelper().doInTransaction(() -> {
policyBehaviourFilter.disableBehaviour(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId));
NodeServiceFactory.getLocalService().updateNodeNative(nodeId,
(HashMap<String, ?>) propertiesToRemove.stream().collect(
Collectors.toMap((o) -> o, (o) -> null)
propertiesToRemove.stream().collect(
HashMap::new, (m, v) -> m.put(v, null), HashMap::putAll
)
);
policyBehaviourFilter.enableBehaviour(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId));
return null;
});
}catch(Throwable t) {
getLogger().warn("failed to remove props from node "+nodeId);
getLogger().warn("failed to remove props from node "+nodeId+": " + t.getMessage());
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
import org.edu_sharing.repository.server.MCAlfrescoAPIClient;
import org.edu_sharing.repository.server.tools.VCardConverter;
import org.edu_sharing.repository.server.tools.cache.RepositoryCache;
import org.edu_sharing.service.InsufficientPermissionException;
import org.edu_sharing.service.authentication.ScopeUserHomeService;
import org.edu_sharing.service.authentication.ScopeUserHomeServiceFactory;
import org.edu_sharing.service.feedback.FeedbackServiceFactory;
import org.edu_sharing.service.nodeservice.NodeServiceFactory;
import org.edu_sharing.service.nodeservice.NodeServiceHelper;
import org.edu_sharing.service.nodeservice.RecurseMode;
import org.edu_sharing.service.permission.PermissionServiceFactory;
import org.edu_sharing.service.permission.PermissionServiceHelper;
import org.edu_sharing.service.rating.RatingServiceFactory;
import org.edu_sharing.service.stream.StreamServiceFactory;
import org.edu_sharing.service.tracking.TrackingServiceFactory;
Expand Down Expand Up @@ -269,31 +272,31 @@ public List<NodeRef> getAllNodeRefs(String username, String type, String scope){
}

private void handleStatistics(NodeRef personNodeRef, String deletedUsername, PersonDeleteOptions options) {
String username = (String)nodeService.getProperty(personNodeRef,
QName.createQName(CCConstants.CM_PROP_PERSON_USERNAME));
try {
if(options.statistics.delete) {
TrackingServiceFactory.getTrackingService().deleteUserData(username);
logger.info("removed tracking/statistics data");
}else{
TrackingServiceFactory.getTrackingService().reassignUserData(username,deletedUsername);
logger.info("removed tracking/statistics data");
}
}catch(Throwable t){
throw new RuntimeException(t);
String username = (String)nodeService.getProperty(personNodeRef,
QName.createQName(CCConstants.CM_PROP_PERSON_USERNAME));
try {
if(options.statistics.delete) {
TrackingServiceFactory.getTrackingService().deleteUserData(username);
logger.info("removed tracking/statistics data");
}else{
TrackingServiceFactory.getTrackingService().reassignUserData(username,deletedUsername);
logger.info("removed tracking/statistics data");
}
}catch(Throwable t){
throw new RuntimeException(t);
}
}

/**
* Deletes all nodes from the given person + type in the repository
*/
private List<NodeRef> deleteAllOfType(NodeRef personNodeRef,String type,String scope) {
String username = (String)nodeService.getProperty(personNodeRef,
QName.createQName(CCConstants.CM_PROP_PERSON_USERNAME));
List<NodeRef> refs = getAllNodeRefs(username,type, scope);
logger.info("Deleting all files of type "+type);
deleteAllRefs(refs);
return refs;
String username = (String)nodeService.getProperty(personNodeRef,
QName.createQName(CCConstants.CM_PROP_PERSON_USERNAME));
List<NodeRef> refs = getAllNodeRefs(username,type, scope);
logger.info("Deleting all files of type "+type);
deleteAllRefs(refs);
return refs;
}

/**
Expand Down Expand Up @@ -394,8 +397,59 @@ else if(options.collections.privateCollections.equals(PersonDeleteOptions.Delete
collectionsIos.forEach((ref)->setOwner(ref,userName,options.receiver, options));
}
return counts;
} else {
List<NodeRef> collectionsIosPublic = filterPublic(collectionsIos);
collectionsIos.removeAll(collectionsIosPublic);

List<NodeRef> collectionsMapsPublic = filterPublic(collectionsMaps);
collectionsMaps.removeAll(collectionsMapsPublic);

// remove private/shared collections + ios
if(options.collections.privateCollections.equals(PersonDeleteOptions.DeleteMode.delete)) {
// the maps may be not enough if the user contributed to foreign collections
deleteAllRefs(collectionsIos);
deleteAllRefs(collectionsMaps);
}
else if(options.collections.privateCollections.equals(PersonDeleteOptions.DeleteMode.assign)) {
setOwnerAndPermissions(collectionsMaps, userName, options);
//setOwnerAndPermissions(collectionsIos, userName, options);
// io references should not support additional permissions (always inherit)
collectionsIos.forEach((ref)->setOwner(ref,userName,options.receiver, options));
}

// remove public collections + ios
if(options.collections.publicCollections.equals(PersonDeleteOptions.DeleteMode.delete)) {
// the maps may be not enough if the user contributed to foreign collections
deleteAllRefs(collectionsIosPublic);
deleteAllRefs(collectionsMapsPublic);
}
else if(options.collections.publicCollections.equals(PersonDeleteOptions.DeleteMode.assign)) {
setOwnerAndPermissions(collectionsMapsPublic, userName, options);
//setOwnerAndPermissions(collectionsIos, userName, options);
// io references should not support additional permissions (always inherit)
collectionsIosPublic.forEach((ref)->setOwner(ref,userName,options.receiver, options));
}
return counts;
}
throw new IllegalArgumentException("Currently collection deletion does only support the same modes for private and public");
}

/**
* return only elements were GROUP_EVERYONE has Permission.Read
*/
private List<NodeRef> filterPublic(List<NodeRef> refs) {
return refs.stream().filter(ref -> {
try {
return Arrays.stream(PermissionServiceFactory.getLocalService().getPermissions(ref.getId()).getAces()).anyMatch(
ace -> ace.getAuthorityType().equals(CCConstants.PERM_AUTHORITY_TYPE_EVERYONE) &&
ace.getAuthority().equals(CCConstants.AUTHORITY_GROUP_EVERYONE) && (
ace.getPermission().equals(CCConstants.PERMISSION_READ) || ace.getPermission().equals(CCConstants.PERMISSION_CONSUMER
)
)
);
} catch (Exception e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
}

/**
Expand Down Expand Up @@ -453,9 +507,9 @@ public List<PersonDeleteResult.Element> convertToElements(Collection<NodeRef>...
List<PersonDeleteResult.Element> result=new ArrayList<>();
for (Collection<NodeRef> ref : refs) {
result.addAll(ref.stream().map((r)->
new PersonDeleteResult.Element(r.getId(),
(String) nodeService.getProperty(r, QName.createQName(CCConstants.CM_NAME)),
nodeService.getType(r).toString())
new PersonDeleteResult.Element(r.getId(),
(String) nodeService.getProperty(r, QName.createQName(CCConstants.CM_NAME)),
nodeService.getType(r).toString())
).collect(Collectors.toList()));
}
return result;
Expand Down Expand Up @@ -704,8 +758,8 @@ private NodeRef getDeletedFolderForOrg(PersonDeleteOptions options, String scope
if(orgRef == null) {
if(scope!=null) {
orgRef = authorityService.getAuthorityNodeRef(
ScopeUserHomeServiceFactory.getScopeUserHomeService().getOrCreateScopedEduGroup(orgName, scope).getGroupId()
);
ScopeUserHomeServiceFactory.getScopeUserHomeService().getOrCreateScopedEduGroup(orgName, scope).getGroupId()
);
}
if(orgRef == null) {
throw new IllegalArgumentException("Given org " + orgName + " (" + scope + ") could not be found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,9 @@ public void updateNodeNative(StoreRef store, String nodeId, Map<String, ?> _prop
logger.warn("Error while calling interceptor " + i.getClass().getName() + ": " + e.toString());
}
}
Map<QName, Serializable> propsStore = propsFinal.entrySet().stream().collect(
Map<QName, Serializable> propsStore = propsFinal.entrySet().stream().
filter(e -> e.getValue() != null).
collect(
HashMap::new,
(m,entry)-> m.put(QName.createQName(entry.getKey()), (Serializable) entry.getValue()),
HashMap::putAll
Expand Down
Loading

0 comments on commit e67e4d6

Please sign in to comment.