User Permission
Overview
One of the most concerned issues is access control for ZSS. We think most enterprises have its own authorization rule. Hence, you can use 3 categories of API mentioned in previous chapters to help you build your own user permission mechanism. We will demonstrate the usage of API with a simple application. In this application, you can login with 3 different roles: OWNER, EDITOR, VIEWER. Their permissions are described in the image below:
If you login as an owner, you will have full control of the file. But if you login as an editor, you will find all sheet related operations are disabled.
When you login as a viewer, the only thing you can do is viewing. Because there is no UI for edit, and all sheets are protected from editing.
This application relies on those API we mentioned in previous chapters to control the access for each role. Let's recap them here:
Hide User Interface
Working with Spreadsheet/Control Components
Example:
spreadsheet.setShowToolbar(false);
Disable Functions
Working with Spreadsheet/Advanced/Disable Functions
Example:
spreadsheet.disableUserAction(AuxAction.COPY_SHEET, true);
Protect a Sheet
Working with Spreadsheet/Handling Data Model/Protection
Example:
Ranges.range(spreadsheet.getSelectedSheet()).protectSheet("password",
true, true, false, false, false, false, false,
false, false, false, false, false, false, false, false);
You can download the example source code to know the complete implementation.
All source code listed in this book is at Github.