private void canShare(SharedResource sharedResource, String bucket, ResourceDescriptor resource, Set<String> resharedResourceUrls) {
        if (bucket.equals(resource.getBucketName())) {
            return;
        }
        while (resource != null) {
            if (resharedResourceUrls.contains(resource.getUrl())) {
                if (sharedResource.getPermissions().contains(ResourceAccessType.WRITE)) {
                    throw new IllegalArgumentException("Re-shared resource %s is not allowed to be shared with the permission WRITE"
                            .formatted(sharedResource.getUrl()));
                }
                return;
            }
            resource = resource.getParent();
        }
        throw new IllegalArgumentException("Resource %s is not allowed to be shared by the user".formatted(sharedResource.getUrl()));
    }
Initialize share request by creating invitation object

@param request  - request body
@return invitation link
server/src/main/java/com/epam/aidial/core/server/service/ShareService.java