add-on with LIMITED auth cannot open sidebar

坚强是说给别人听的谎言 提交于 2021-02-06 12:47:42

问题


I have a Google docs add-on which is programmed to open the sidebar as soon as the document is open. Of course this requires the add-on to be installed and enabled in the document.

I see that, since a week, the sidebar auto open feature, which is very useful in our use case, no longer works.

In StackDriver logs I see this report :

onOpen():  {authMode=LIMITED, source=Document, user=} 
publi-2.0.72-2017-11-27-18-57               [this is the publication version tag]
2017-11-27T18:02:50.126Z : show menu 
2017-11-27T18:02:50.180Z : show sidebar 
Error showing sidebar  Exception: You do not have permission to call showSidebar 
2017-11-27T18:02:50.283Z : end onOpen 

So clearly, the add-on is in LIMITED mode and showSidebar() should succeed, according to the addon authorization lifecyle (just look at the column LIMITED in the table).

--> I suspect a bug or a new security limitation was introduced recently.

For the record here is a code snippet :

/**
 * Basic setup. At the beginning:
 * 1. Add a "Add-ons" menu item.
 * 2. Display the doxMaster sidebar.
 */
function onOpen(e) {
    console.log("onOpen(): ",e)
    console.log(addonversion);
    doServerLog("show menu");
    showMenu();
    doServerLog("show sidebar");
    showSidebar();
    doServerLog("end onOpen");
}

/**
 * Creates the Add-ons menu at the google drive panel.
 */
function showMenu() {
    DocumentApp.getUi().createAddonMenu()
        .addItem(translate("sidebarMenu"), showSidebar.name)
        .addItem(translate("joinFollowingParagraph"), insertJoinFollowingParaSymbol.name)
        .addItem(translate("importDocument"), importDocument.name)
        .addItem(translate("about"), about.name)
        .addToUi();

}

/**
 * Creates a doxMaster Add-on Sidebar.
 */
function showSidebar() {
    try {
        var htmlTemplate = HtmlService.createTemplateFromFile('sidebar');
        var html = htmlTemplate.evaluate().setTitle(translate("appTitle"));
        DocumentApp.getUi().showSidebar(html);
    }
    catch (e) {
        console.log("Error showing sidebar ", e); // Add-on has not been enabled in this document
    }
}

回答1:


Yesterday we've noticed exactly the same problem as you Yves. However for us it occurs in a Google Sheets addon.

I've created an issue at Google: https://issuetracker.google.com/issues/69824548

Please star and comment so it gets picked up soon!




回答2:


I retested, and I see that :

  • on installing the Add-On, mode is set to FULL
  • then opening a document mode is set to None
  • on opening the add-on then, closing the document then reopens, mode is LIMITED.

That is consistent with the expected lifecycle, except that :

  • createTemplate fails under LIMITED mode
  • in LIMITED mode the event has {user=} with no value :

08:22:36.457 onOpen(): {authMode=LIMITED, source=Document, user=}

I think the user permissions are somewhat lost.




回答3:


From https://developers.google.com/gsuite/add-ons/concepts/editor-auth-lifecycle

Note: Add-ons can't open sidebars or dialogs while executing in AuthMode.LIMITED. You can use menu items to open sidebars and dialogs since these run in AuthMode.FULL.

From Error "You do not have permission to call showSidebar" in onOpen and onEdit (an issue from the Google Apps Script issue tracker)

Status: Won't Fix (Intended Behavior) Sorry for the delayed reply here. After many conversations with the engineering team it was decided that we cannot support opening UI elements (sidebars, dialogs) in onOpen and onEdit. The authorization lifecycle documentation has been updated to make it clear that you can only add menu items in those modes:

https://developers.google.com/gsuite/add-ons/concepts/addon-authorization#authorization_modes

We understand this impacts the possible user experiences you can provide and we apologize for the suddenness of the change.



来源:https://stackoverflow.com/questions/47517334/add-on-with-limited-auth-cannot-open-sidebar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!