Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Adding More Sharing Permissions to ONLYOFFICE Doc Editors

DZone 's Guide to

Adding More Sharing Permissions to ONLYOFFICE Doc Editors

ONLYOFFICE's suite of permissions not enough? Let's see how to add more.

· Open Source Zone ·
Free Resource

ONLYOFFICE is an open source office suite that contains docx, xlsx, pptx editors for integration with other apps. Previously, we wrote some articles on how to integrate the editors with document management systems in PHP, Node.js, Python, etc. In this article, we will show you how to add more sharing permissions to DMS + editors combos.

That means more flexible access rights management: apart from basic reading and editing rights, you will be able to bring about commenting, reviewing, filling form rights, and also restrict downloading files.

As an example, we will use integration with ownCloud, open-source sync and share solution.

Basic Integration Info

To start, let’s install the editors (ONLYOFFICE Document Server). The easiest way to do so is to use Docker:

docker run -itd -p 8080:80 onlyoffice/documentserver


You can also install the editors from the repository or by compiling the source code.

Now let’s see how they can be connected to ownCloud.

The integration is with the ONLYOFFICE-ownCloud integration app that serves as a bridge between the file storage and the editors (Document Server). It is written in PHP, and you can check its source code on GitHub.

The app allows for connecting ONLYOFFICE Document Server and ownCloud to:

  • View and edit documents, spreadsheets and presentations stored in ownCloud.
  • Co-edit documents, spreadsheets, and presentations in real time.

In one of our previous articles, we wrote how to create an app for integration with another DMS in PHP. Use it to learn how to add buttons for document viewing and editing.

Now let’s focus on sharing files and access permissions.

Sharing files in ownCloud

The default Files sharing app in ownCloud’s core is responsible for granting access to files. When it’s enabled, users can provide access to files to other users. By default, they can share files for viewing and editing.

Since version 10.2 of ownCloud Server, with the ONLYOFFICE-ownCloud integration app, the new options will appear for office docs:

Image title

If the box "Can edit" is unchecked, you can choose between several access rights.

  • Download. You can restrict downloading docs by unwanted users.
  • Review (for docx). Users with such access can suggest changes in Track Changes mode without modifying the initial document.
  • Filling forms (for docx). Users with this permission can insert and change data in the fields chosen by the document author.
  • Comment. Users can’t change the initial document, but they can leave comments.
  • Modify filter(for xlsx). It allows users with full access to configure the filters so that the changes will be displayed for every co-author.

Note that ticking the boxes affects other boxe,s as some permissions are mutually exclusive. When you choose filling forms, it deactivates commenting. Choosing reviewing rights deactivates filling forms and commenting. All the dependencies are documented here.

Now let’s see how all this was implemented in the ownCloud-ONLYOFFICE connector so that you can use it in your own app.

How to Add New Permissions

To make this possible, your DMS must allow registering new sharing attributes.

The new method registerShareAttribute was added to ownCloud’s sharing app in version 10.2. So, we added the following code to our integration app to register the download rights attribute:

OCA.Onlyoffice.Share = {
    attach: function (model) {
        model.registerShareAttribute({
            "scope": "permissions",
            "key": "download",
            "default": true,
            "label": "download",
            "incompatiblePermissions": [OC.PERMISSION_UPDATE]
        });
    }
};

OC.Plugins.register("OC.Share.ShareItemModel", OCA.Onlyoffice.Share);


Note that it should be specified that this access type will be displayed only if no rights for editing are granted.

Other attributes are registered similarly. When you are adding “comment”, as below, it is necessary to indicate incompatibility with “review” and “form filling”:

model.registerShareAttribute({
    "scope": "ONLYOFFICE",
    "key": "comment",
    "default": false,
    "label": "comment",
    "incompatiblePermissions": [OC.PERMISSION_UPDATE],
    "incompatibleAttributes": [
        {
            "scope": "ONLYOFFICE",
            "key": "review",
            "enabled": true
        },
        {
            "scope": "ONLYOFFICE",
            "key": "fillForms",
            "enabled": true
        }
    ]
});


User-selected settings are automatically saved by the ownCloud system. The user who has been granted access will have the values of these permissions available.

On the server side, you can access these attributes via this PHP code:

$fileStorage = $file->getStorage();
if ($fileStorage->instanceOfStorage("\OCA\Files_Sharing\SharedStorage")) {
    $attributes = $fileStorage->getShare()->getAttributes();
    $permissionsReviewOnly = $attributes->getAttribute("ONLYOFFICE", "review");
}


Boolean values of the attributes are transferred to the initialization configuration of the ONLYOFFICE editors into the rights section.

Basically, that’s all you need to know, especially if you have experience in web services development. I hope this will help enhance the functionality of your app!

Topics:
open source ,dms ,onlyoffice ,permissions ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}