From 7c6e4548627949ed8f102b12491782c573e73e10 Mon Sep 17 00:00:00 2001 From: MayTekayaa <100131287+MayTekayaa@users.noreply.github.com> Date: Mon, 19 Jan 2026 11:03:10 +0100 Subject: [PATCH] fix: Add placeholder page when the user accesses another user's personal drive - EXO-82012 (#302) Before this change, a user creates a document in his personal drive, then attaches it to an article in a space. Another user who is a member of the same space goes to the location of the first user's document, which is restricted because it is located in his personal drive. This change corrects this behavior and displays a placeholder page to the second user to indicate that he does not have access to this drive. --- .../org/exoplatform/onlyoffice/Config.java | 37 ++++++++++++++++++- .../OnlyofficeEditorServiceImpl.java | 28 ++++++++++++++ webapp/src/main/webapp/js/onlyoffice.js | 4 ++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/services/src/main/java/org/exoplatform/onlyoffice/Config.java b/services/src/main/java/org/exoplatform/onlyoffice/Config.java index ee0d47390..0d9ce4bdd 100644 --- a/services/src/main/java/org/exoplatform/onlyoffice/Config.java +++ b/services/src/main/java/org/exoplatform/onlyoffice/Config.java @@ -143,9 +143,9 @@ public static class Builder { // Editor.User protected String userId, name; + protected boolean canAccessDocumentLocation; - - protected boolean allowEdition = true; + protected boolean allowEdition = true; /** * Instantiates a new builder. @@ -432,6 +432,17 @@ public Builder lastModified(String lastModified) { return this; } + /** + * Sets can access document path or not. + * + * @param canAccess the access document path + * @return the builder + */ + public Builder canAccessDocumentLocation(boolean canAccess) { + this.canAccessDocumentLocation = canAccess; + return this; + } + /** * Download url. * @@ -485,6 +496,7 @@ public Config build() { Document document = new Document(key, fileType, title, url, info, permissions); Editor.User user = new Editor.User(userId, name); Editor editor = new Editor(callbackUrl, lang, mode, user); + editor.setCanAccessDocumentLocation(this.canAccessDocumentLocation); EditorPage editorPage = new EditorPage(comment, renameAllowed, displayPath, lastModifier, lastModified,drive); Config config = new Config(documentserverUrl, platformRestUrl, @@ -921,6 +933,8 @@ public void setLastSaved(long lastSaved) { /** The mode. */ protected String mode; + protected boolean canAccessDocumentLocation; + /** * Instantiates a new editor. * @@ -937,6 +951,25 @@ protected Editor(String callbackUrl, String lang, String mode, User user) { this.user = user; } + /** + * Sets if can access to document path. + * + * @param canAccess the can access variable + */ + public void setCanAccessDocumentLocation(boolean canAccess) { + this.canAccessDocumentLocation = canAccess; + } + + + /** + * Is canAccessDocumentLocation. + * + * @return the isCanAccessDocumentLocation + */ + public Boolean isCanAccessDocumentLocation() { + return canAccessDocumentLocation; + } + /** * Gets the callback url. * diff --git a/services/src/main/java/org/exoplatform/onlyoffice/OnlyofficeEditorServiceImpl.java b/services/src/main/java/org/exoplatform/onlyoffice/OnlyofficeEditorServiceImpl.java index 4f781f884..89b211d5e 100644 --- a/services/src/main/java/org/exoplatform/onlyoffice/OnlyofficeEditorServiceImpl.java +++ b/services/src/main/java/org/exoplatform/onlyoffice/OnlyofficeEditorServiceImpl.java @@ -705,6 +705,7 @@ public Config createEditor(String schema, String ecmsPageLink = explorerLink(path); builder.explorerUri(explorerUri(schema, host, port, ecmsPageLink)); builder.secret(documentserverSecret); + builder.canAccessDocumentLocation(canAccessDocumentLocation(node, userId)); config = builder.build(); @@ -728,6 +729,7 @@ public Config createEditor(String schema, config.getEditorPage().setComment(nodeComment(node)); config.getEditorPage().setLastModifier(getLastModifier(node)); config.getEditorPage().setLastModified(getLastModified(node)); + config.getEditorConfig().setCanAccessDocumentLocation(canAccessDocumentLocation(node, userId)); cachedEditorConfigStorage.saveConfig(config.getDocument().getKey(), config,false); cachedEditorConfigStorage.saveConfig(config.getDocId(),config,false); @@ -819,6 +821,7 @@ public Config createViewer(String schema, } else { builder.setAllowEdition(false); } + builder.canAccessDocumentLocation(canAccessDocumentLocation(node, userId)); Config config = builder.build(); // Create users' config map and add first user @@ -1206,6 +1209,31 @@ public List getVersions(String workspace, String docId, int itemParPage return getPages(versions, itemParPage, pageNum); } + private String extractSpacePrettyName(String path) { + if (path == null) { + return null; + } + String[] parts = path.split("/"); + + if (parts.length > 3 && "Groups".equals(parts[1]) && "spaces".equals(parts[2])) { + return parts[3]; + } + return null; + } + private boolean canAccessDocumentLocation(Node node, String userId) throws RepositoryException { + String path = node.getPath(); + String[] permissions = new String[] { PermissionType.READ }; + if (path.startsWith(usersPath)) { + return PermissionUtil.hasPermissions(node, userId, permissions); + } + if (path.startsWith(groupsPath)) { + String spaceName = extractSpacePrettyName(path); + Space space = spaceService.getSpaceByPrettyName(spaceName); + return space != null && (PermissionUtil.hasPermissions(node, userId, permissions) || spaceService.isMember(space, userId)); + } + return false; +} + private List getPages(List c, Integer pageSize, int nb) { if (c == null || c.isEmpty()) return Collections.emptyList(); diff --git a/webapp/src/main/webapp/js/onlyoffice.js b/webapp/src/main/webapp/js/onlyoffice.js index 979131d96..71eaad3a9 100644 --- a/webapp/src/main/webapp/js/onlyoffice.js +++ b/webapp/src/main/webapp/js/onlyoffice.js @@ -577,6 +577,10 @@ * Create back button url. */ var getBackUrl = function(config) { + if (config.editorConfig && !config.editorConfig.canAccessDocumentLocation) { + const url = new URL(window.location.origin + eXo.env.portal.context + "/" + eXo.env.portal.portalName + "/restricted-drive"); + return url.toString(); + } if(!config.backTo){ return config.explorerUrl; }