none
dynamically Restrict Edit on Word documents using Javascript API Office Addin RRS feed

  • Question

  • I have a requirement to develop a solution to enable the administrator to set edit permissions on Ms Word based on the user logged on.

    The solution will be hosted by SharePoint 2013 using Office Co authoring. The document must be edited by many users at the same time and each user must only edit the section the admins have configured the user to edit.

    Does anyone have any idea how to allow the administrator to set the permissions? Then dynamically disable/enable controls based on template name and user logon on MS Word 2016 using JavaScript API for Word.

    The client does not want to use the option available out of the box to restrict edit using passwords because it is easy to crack the password.

    http://www.c-sharpcorner.com/UploadFile/8ea152/set-and-remove-editing-restrictions-in-word-2013-documents/

    I have looked at the link below but my problem is to disable/enable the controls dynamically without hard cording the controls or users.

    https://xomino.com/2017/03/29/office-add-ins-javascript-control-over-the-content-control-lock-in-a-word-document/

    • Edited by tapsb Monday, June 26, 2017 8:44 AM
    Monday, June 26, 2017 7:55 AM

All replies

  • Hi tapsb,

    I try to search for the solution of your requirement.

    but currently, Office JS Api provide the limited features and functionality.

    so currently it is not possible to check dynamically for the user to enable and disable the content control in document.

    you had mentioned that the document will be stored on sharepoint and many users will try to update it simultaneously.

    so currently there is no way to check which user is editing and which content control is get edited by that user.

    Reference:

    Word JavaScript API reference

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 27, 2017 3:03 AM
    Moderator
  • Hi Deepak 

    Thanks you for you reply.

    Is there any other way to set permissions on MS word documents programmatically?

    Or any third party tool that can be used?

    Tuesday, June 27, 2017 8:03 AM
  • Hi tapsb,

    you had asked,"Is there any other way to set permissions on MS word documents programmatically?"

    if you can able to use VBA to solve your issue then you can try to check Permission Object.

    Use the  Permission object to restrict permissions to the active document and to return or set specific permissions settings.

    The  Permission object gives access to a collection of UserPermission objects. Use the UserPermission object to associate specific sets of rights with individual users. While some permissions granted through the user interface (such as msoPermissionPrint ) apply to all users, you can use the UserPermission object to assign them on a per-user basis with per-user expiration dates.

    Example:

    Dim irmPermission As Office.Permission 
     Dim strIRMInfo As String 
     Set irmPermission = ActiveWorkbook.Permission 
     If irmPermission.Enabled Then 
     strIRMInfo = "Permissions are restricted on this document." & vbCrLf 
     strIRMInfo = strIRMInfo & " View in trusted browser: " & _ 
     irmPermission.EnableTrustedBrowser & vbCrLf & _ 
     " Document author: " & irmPermission.DocumentAuthor & vbCrLf & _ 
     " Users with permissions: " & irmPermission.Count & vbCrLf & _ 
     " Cache licenses: " & irmPermission.StoreLicenses & vbCrLf & _ 
     " Request permission URL: " & irmPermission.RequestPermissionURL & vbCrLf 
     If irmPermission.PermissionFromPolicy Then 
     strIRMInfo = strIRMInfo & " Permissions applied from policy:" & vbCrLf & _ 
     " Policy name: " & irmPermission.PolicyName & vbCrLf & _ 
     " Policy description: " & irmPermission.PolicyDescription 
     Else 
     strIRMInfo = strIRMInfo & " Default permissions applied." & vbCrLf & _ 
     " Default policy name: " & irmPermission.PolicyName & vbCrLf & _ 
     " Default policy description: " & irmPermission.PolicyDescription 
     End If 
     Else 
     strIRMInfo = "Permissions are NOT restricted on this document." 
     End If 
     MsgBox strIRMInfo, vbInformation + vbOKOnly, "IRM Information" 
     Set irmPermission = Nothing
    

    Reference:

    Permission Object (Office)

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 28, 2017 7:07 AM
    Moderator
  • Hi tapsb,

    I am afraid there is no built-in function to achieve your requirement.

    For a workaround, I would suggest you enable single sign-on for Word AddIn, after user sign on, you could loop through the content control to dynamically set the cannotEdit property.

    To avoid hard cording, I think you could create a database to indicate who has the permission to edit the paragraph, and then check the permission after user sign on.

    Here are references for sso and content control property.

    # Enable single sign-on for Office Add-ins (preview)

    https://github.com/OfficeDev/office-js-docs/blob/master/docs/develop/sso-in-office-add-ins.md

    # ContentControl Object (JavaScript API for Word)

    https://dev.office.com/reference/add-ins/word/contentcontrol

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 30, 2017 6:08 AM
  • Thanks I will try this
    Thursday, July 6, 2017 9:57 AM
  • Thanks Deepak due to security issues with VBA i have decided to use Office JavaScript API solution
    Thursday, July 6, 2017 9:59 AM
  • Hi  tapsb,

    Have you a solution to this question? I also need to deal this, so I need your help, please!

    thank you!


    • Edited by jerry_199 Saturday, September 23, 2017 8:31 AM
    Saturday, September 23, 2017 8:30 AM
  • Hi jerry_199,

    you can see that this is an old thread.

    if you still have a issue then I suggest you to create a new thread with detailed information.

    if you create a new thread then there is a much more chances to got the reply from community members.

    so there will be more possibility to get the solution for your issue.

    Thanks for your understanding.

    Regards

    Deepak 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 9, 2017 6:35 AM
    Moderator