Script - Correct security in personal nodes
The script changes the security recursively for all the childs for the nodes okm:personal, okm:trash and okm:mail removing all previous security an assigning all grants to the owner of the folder ( the folder name identifies the user ).
import com.openkm.api.OKMAuth;
import com.openkm.api.OKMFolder;
import com.openkm.bean.Folder;
import java.util.*;
import com.openkm.util.PathUtils;
import com.openkm.bean.Permission;
public void changeSecurity(String path){
for(Folder fld : OKMFolder.getInstance().getChildren(null, path)) {
String userId = PathUtils.getName(fld.getPath());
Map revokeRoles = OKMAuth.getInstance().getGrantedRoles(null, fld.getPath());
Map revokeUsers = OKMAuth.getInstance().getGrantedUsers(null, fld.getPath());
Map grantUsers = new HashMap();
grantUsers.put(userId, Permission.ALL_GRANTS);
revokeUsers.remove(userId);
OKMAuth.getInstance().changeSecurity(null, fld.getPath(), grantUsers, revokeUsers, new HashMap(), revokeRoles, true);
print("Done " + path + "<br />");
}
}
changeSecurity("/okm:personal");
changeSecurity("/okm:trash");
changeSecurity("/okm:mail");