Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions services/src/main/java/org/exoplatform/onlyoffice/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -921,6 +933,8 @@ public void setLastSaved(long lastSaved) {
/** The mode. */
protected String mode;

protected boolean canAccessDocumentLocation;

/**
* Instantiates a new editor.
*
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1206,6 +1209,31 @@ public List<Version> 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 <T> List<T> getPages(List<T> c, Integer pageSize, int nb) {
if (c == null || c.isEmpty())
return Collections.emptyList();
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/main/webapp/js/onlyoffice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading