Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app publish and unpublish resets view of app #45

Open
MonoMoggy opened this issue Mar 12, 2019 · 1 comment
Open

app publish and unpublish resets view of app #45

MonoMoggy opened this issue Mar 12, 2019 · 1 comment

Comments

@MonoMoggy
Copy link

If we run app_publish(unpublishRunningApps=True) it will work as expected, but if a user has previously set access permissions to "Anyone, including anonymous users", it will be reset to the default value.

@MonoMoggy
Copy link
Author

To fix this, it seems that you can use an undocumented endpoint /v4/modelProduct and do something like this:

from domino import Domino
import sys
import requests
 
class MyDomino(Domino):
    def get_app_settings(self):
        url = self._routes.host + "/v4/modelProducts"
        r = requests.get(url, auth=('', self._api_key))
        settings = [x for x in r.json() if x['projectUrl'] == '/u/' + self._routes._owner_username + '/' + self._routes._project_name][0]
        return settings
    def set_app_settings(self, settings=None, visibility="PUBLIC"):
        """
        Parameters
        ----------
        visibility : str
            One of "GRANT_BASED", "GRANT_BASED_STRICT", "AUTHENTICATED", "PUBLIC"
        """
        if settings is None:
            settings = self.get_app_settings()
        assert visibility.upper() in ["GRANT_BASED","GRANT_BASED_STRICT","AUTHENTICATED","PUBLIC"]
        settings['permissionsData']['visibility'] = visibility.upper()
        url = self._routes.host + "/v4/modelProducts"
        r = requests.post(url, auth=('', self._api_key), json=settings)
        return r
 
project = "my_user/test_publish_app"
    
if __name__ == "__main__":
    domino = MyDomino(project)
    if len(sys.argv) == 1:
        domino.app_publish()
    elif sys.argv[1] == "publish":
        domino.app_publish()
        if len(sys.argv) == 3:
            domino.set_app_settings(visibility=sys.argv[2])
    elif sys.argv[1] == "unpublish":
        domino.app_unpublish()
    else:
        import warnings
        warnings.warn("Not valid argument found: {}\nNothing will be done".format(sys.argv[1:]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant