From 0ce4fa37cb4d47924da0cd3a6dfc56b83b9bd616 Mon Sep 17 00:00:00 2001 From: T8y8 Date: Fri, 14 Oct 2016 14:07:14 -0700 Subject: [PATCH 1/3] Fix for issie #60. Make Sign Out a no-op when you are already signed out --- tableauserverclient/server/endpoint/auth_endpoint.py | 3 +++ tableauserverclient/server/endpoint/sites_endpoint.py | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tableauserverclient/server/endpoint/auth_endpoint.py b/tableauserverclient/server/endpoint/auth_endpoint.py index e685effbe..e66c0ec7f 100644 --- a/tableauserverclient/server/endpoint/auth_endpoint.py +++ b/tableauserverclient/server/endpoint/auth_endpoint.py @@ -41,6 +41,9 @@ def sign_in(self, auth_req): def sign_out(self): url = "{0}/{1}".format(self.baseurl, 'signout') + # If there are no auth tokens you're already signed out. No-op + if not self.parent_srv._auth_token: + return self.post_request(url, '') self.parent_srv._clear_auth() logger.info('Signed out') diff --git a/tableauserverclient/server/endpoint/sites_endpoint.py b/tableauserverclient/server/endpoint/sites_endpoint.py index 704fb9de9..957d224e5 100644 --- a/tableauserverclient/server/endpoint/sites_endpoint.py +++ b/tableauserverclient/server/endpoint/sites_endpoint.py @@ -59,7 +59,12 @@ def delete(self, site_id): raise ValueError(error) url = "{0}/{1}".format(self.baseurl, site_id) self.delete_request(url) - logger.info('Deleted single site (ID: {0})'.format(site_id)) + # Deleting the site also signs you out on the Server. + # Here we check that you're deleting the site you are signed in to + # (Which is true now but may not always be) and then clear auth tokens + if site_id == self.parent_srv._site_id: + self.parent_srv._clear_auth() + logger.info('Deleted single site (ID: {0}) and signed out'.format(site_id)) # Create new site def create(self, site_item): From c8d1116009fd5de8e44609bedb6d913f76f11c8f Mon Sep 17 00:00:00 2001 From: T8y8 Date: Fri, 14 Oct 2016 16:58:31 -0700 Subject: [PATCH 2/3] Responding to CR feedback. Make a method for exposing is_signed_in and fix a bug in test setup --- tableauserverclient/server/endpoint/auth_endpoint.py | 2 +- tableauserverclient/server/endpoint/sites_endpoint.py | 7 +++---- tableauserverclient/server/server.py | 3 +++ test/test_site.py | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tableauserverclient/server/endpoint/auth_endpoint.py b/tableauserverclient/server/endpoint/auth_endpoint.py index e66c0ec7f..9e316d042 100644 --- a/tableauserverclient/server/endpoint/auth_endpoint.py +++ b/tableauserverclient/server/endpoint/auth_endpoint.py @@ -42,7 +42,7 @@ def sign_in(self, auth_req): def sign_out(self): url = "{0}/{1}".format(self.baseurl, 'signout') # If there are no auth tokens you're already signed out. No-op - if not self.parent_srv._auth_token: + if not self.parent_srv.is_signed_in(): return self.post_request(url, '') self.parent_srv._clear_auth() diff --git a/tableauserverclient/server/endpoint/sites_endpoint.py b/tableauserverclient/server/endpoint/sites_endpoint.py index 957d224e5..be5161b58 100644 --- a/tableauserverclient/server/endpoint/sites_endpoint.py +++ b/tableauserverclient/server/endpoint/sites_endpoint.py @@ -59,10 +59,9 @@ def delete(self, site_id): raise ValueError(error) url = "{0}/{1}".format(self.baseurl, site_id) self.delete_request(url) - # Deleting the site also signs you out on the Server. - # Here we check that you're deleting the site you are signed in to - # (Which is true now but may not always be) and then clear auth tokens - if site_id == self.parent_srv._site_id: + # If we deleted the site we are logged into + # then we are automatically logged out + if site_id == self.parent_srv.site_id: self.parent_srv._clear_auth() logger.info('Deleted single site (ID: {0}) and signed out'.format(site_id)) diff --git a/tableauserverclient/server/server.py b/tableauserverclient/server/server.py index 24d56e1fe..8c28c1825 100644 --- a/tableauserverclient/server/server.py +++ b/tableauserverclient/server/server.py @@ -81,3 +81,6 @@ def http_options(self): @property def session(self): return self._session + + def is_signed_in(self): + return self._auth_token is not None diff --git a/test/test_site.py b/test/test_site.py index 3076e4ce3..311f9524f 100644 --- a/test/test_site.py +++ b/test/test_site.py @@ -17,7 +17,7 @@ def setUp(self): # Fake signin self.server._auth_token = 'j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM' - + self.server._site_id = '0626857c-1def-4503-a7d8-7907c3ff9d9f' self.baseurl = self.server.sites.baseurl def test_get(self): From c186fd877f398a97c8237df5d0db357e132c1686 Mon Sep 17 00:00:00 2001 From: T8y8 Date: Sat, 15 Oct 2016 11:55:38 -0700 Subject: [PATCH 3/3] Adding another log statement --- tableauserverclient/server/endpoint/sites_endpoint.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tableauserverclient/server/endpoint/sites_endpoint.py b/tableauserverclient/server/endpoint/sites_endpoint.py index be5161b58..51736ffc7 100644 --- a/tableauserverclient/server/endpoint/sites_endpoint.py +++ b/tableauserverclient/server/endpoint/sites_endpoint.py @@ -62,6 +62,7 @@ def delete(self, site_id): # If we deleted the site we are logged into # then we are automatically logged out if site_id == self.parent_srv.site_id: + logger.info('Deleting current site and clearing auth tokens') self.parent_srv._clear_auth() logger.info('Deleted single site (ID: {0}) and signed out'.format(site_id))